手動編譯安裝 nvidia 驅動 (Debian /Ubuntu ) [論壇 - Ubuntu 非官方發行版討論]


正在瀏覽:   1 名遊客


 到底部   前一個主題   下一個主題  [無發表權] 請登錄或者註冊



手動編譯安裝 nvidia 驅動 (Debian /Ubuntu )
會員二級
註冊日期:
2017/3/23 10:15
所屬群組:
已註冊使用者
等級: 5
HP : 0 / 108
MP : 14 / 497
EXP: 35
離線
Ubuntu 發行版 nvidia 驅動實際只有一個版本,Debain 套件庫的 nvidia 驅動分得很散,如果選擇舊版跨套件庫安裝,很容易出現依賴問題。如果套件庫的版本不是你需要的,而是需要特定版本。如果要安裝舊版,APT套件管理器時常會碰到依賴問題而不能安裝,那就需要自己手動編譯,可以自由靈活選擇想要的版本安裝。

內容源自 openSUSE nVidia 驅動安裝腳本修改:

############################################
### NVIDIA Driver 64-bit Library
############################################
# Depends:
sudo apt-get install dkms gcc make patch linux-headers-amd64

NV_NAME=NVIDIA-Linux-x86_64
NV_VER='390.42'

wget -c http://us.download.nvidia.com/XFree86/Linux-x86_64/$NV_VER/"$NV_NAME"-"$NV_VER".run

sh "$NV_NAME"-"$NV_VER".run --check

sh "$NV_NAME"-"$NV_VER".run -x

sudo /sbin/rmmod nvidia >/dev/null 2>&1

## Remove all 64-bit library
sudo rm -f /usr/lib/xorg/modules/drivers/nvidia_drv.so
sudo rm -f /usr/lib/nvidia/xorg/modules/extensions/libglx.so.$NV_VER
sudo rm -f /usr/lib/x86_64-linux-gnu/nvidia/libGL.so.$NV_VER
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.$NV_VER
sudo rm -f /usr/lib/x86_64-linux-gnu/vdpau/libvdpau_nvidia.so.$NV_VER
sudo rm -f /usr/lib/x86_64-linux-gnu/vdpau/libvdpau_nvidia.so.1
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvidia-tls.so.$NV_VER
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvidia-cfg.so.$NV_VER
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvidia-cfg.so.1
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.$NV_VER
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvidia-ml.so
sudo rm -f /usr/lib/x86_64-linux-gnu/libcuda.so.$NV_VER
sudo rm -f /usr/lib/x86_64-linux-gnu/libcuda.so
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvcuvid.so.$NV_VER
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvidia-ptxjitcompiler.so.$NV_VER
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvidia-ptxjitcompiler.so.1
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvidia-fatbinaryloader.so.$NV_VER
sudo rm -f /usr/bin/nvidia-xconfig
sudo rm -f /usr/share/man/man1/nvidia-xconfig.1.gz
sudo rm -f /usr/lib/nvidia/libnvidia-gtk3.so.$NV_VER
sudo rm -f /usr/bin/nvidia-settings
sudo rm -f /usr/share/man/man1/nvidia-settings.1.gz
sudo rm -f /usr/share/applications/nvidia-settings.desktop
sudo rm -f /usr/share/pixmaps/nvidia-settings.png
sudo rm -f /usr/share/nvidia/nvidia-application-profiles-"$NV_VER"-key-documentation
sudo rm -f /usr/bin/nvidia-bug-report.sh
sudo rm -f /usr/bin/nvidia-smi
sudo rm -f /usr/share/man/man1/nvidia-smi.1.gz
sudo rm -f /etc/OpenCL/vendors/nvidia.icd
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvidia-compiler.so.$NV_VER
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvidia-opencl.so.$NV_VER
sudo rm -f /usr/lib/x86_64-linux-gnu/libnvidia-opencl.so
sudo rm -f /usr/lib/x86_64-linux-gnu/nvidia/libOpenCL.so.1.0.0
sudo rm -f /usr/lib/x86_64-linux-gnu/nvidia/libOpenCL.so
sudo rm -f /usr/share/licenses/nvidia/LICENSE
sudo rm -f /usr/share/licenses/nvidia-utils
sudo rm -f /usr/share/doc/nvidia/README
sudo rm -f /usr/share/doc/nvidia/NVIDIA_Changelog
sudo rm -f /usr/lib/nvidia/xorg/modules/libwfb.so
sudo rm -f /usr/lib/nvidia/xorg/modules/extensions/libglx.so
sudo rm -f /usr/lib/x86_64-linux-gnu/nvidia/libGL.so.1

# Install library
cd "$NV_NAME"-"$NV_VER"

# X driver
sudo install -D -m755  nvidia_drv.so /usr/lib/xorg/modules/drivers/nvidia_drv.so

# GLX extension module for X
sudo install -D -m755 "libglx.so.$NV_VER" /usr/lib/nvidia/xorg/modules/extensions/libglx.so.$NV_VER

# OpenGL library
sudo install -D -m755 "libGL.so.$NV_VER" /usr/lib/x86_64-linux-gnu/nvidia/libGL.so.$NV_VER

# OpenGL core library
sudo install -D -m755 "libnvidia-glcore.so.$NV_VER" /usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.$NV_VER

# VDPAU 
sudo install -D -m755 "libvdpau_nvidia.so.$NV_VER" /usr/lib/x86_64-linux-gnu/vdpau/libvdpau_nvidia.so.$NV_VER
sudo ln -sf libvdpau_nvidia.so.$NV_VER /usr/lib/x86_64-linux-gnu/vdpau/libvdpau_nvidia.so.1

# nvidia-tls library
sudo install -D -m755 "tls/libnvidia-tls.so.$NV_VER" /usr/lib/x86_64-linux-gnu/libnvidia-tls.so.$NV_VER
sudo install -D -m755 "libnvidia-cfg.so.$NV_VER" /usr/lib/x86_64-linux-gnu/libnvidia-cfg.so.$NV_VER
sudo ln -sf libnvidia-cfg.so.$NV_VER /usr/lib/x86_64-linux-gnu/libnvidia-cfg.so.1
sudo install -D -m755 "libnvidia-ml.so.$NV_VER" /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.$NV_VER
sudo ln -sf libnvidia-ml.so.$NV_VER /usr/lib/x86_64-linux-gnu/libnvidia-ml.so

# CUDA
sudo install -D -m755 "libcuda.so.$NV_VER" /usr/lib/x86_64-linux-gnu/libcuda.so.$NV_VER
sudo ln -sf libcuda.so.$NV_VER /usr/lib/x86_64-linux-gnu/libcuda.so
sudo install -D -m755 "libnvcuvid.so.$NV_VER" /usr/lib/x86_64-linux-gnu/libnvcuvid.so.$NV_VER
sudo ln -sf libnvcuvid.so.$NV_VER /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
sudo install -D -m755 "libnvidia-ptxjitcompiler.so.$NV_VER" /usr/lib/x86_64-linux-gnu/libnvidia-ptxjitcompiler.so.$NV_VER
sudo ln -sf libnvidia-ptxjitcompiler.so.$NV_VER /usr/lib/x86_64-linux-gnu/libnvidia-ptxjitcompiler.so.1

# NVIDIA FAT binary loader library
sudo install -D -m755 "libnvidia-fatbinaryloader.so.$NV_VER" /usr/lib/x86_64-linux-gnu/libnvidia-fatbinaryloader.so.$NV_VER

# nvidia-xconfig
sudo install -D -m755 nvidia-xconfig /usr/bin/nvidia-xconfig
sudo install -D -m644 nvidia-xconfig.1.gz /usr/share/man/man1/nvidia-xconfig.1.gz

# nvidia-settings
sudo install -D -m755 "libnvidia-gtk3.so.$NV_VER" /usr/lib/nvidia/libnvidia-gtk3.so.$NV_VER
sudo install -D -m755 nvidia-settings /usr/bin/nvidia-settings
sudo install -D -m644 nvidia-settings.1.gz /usr/share/man/man1/nvidia-settings.1.gz
sudo install -D -m644 nvidia-settings.desktop /usr/share/applications/nvidia-settings.desktop
sudo install -D -m644 nvidia-settings.png /usr/share/pixmaps/nvidia-settings.png
sudo install -D -m644 "nvidia-application-profiles-"$NV_VER"-key-documentation" /usr/share/nvidia/nvidia-application-profiles-"$NV_VER"-key-documentation
sudo sed -e 's:__UTILS_PATH__:/usr/bin:' -e 's:__PIXMAP_PATH__:/usr/share/pixmaps:' -i "/usr/share/applications/nvidia-settings.desktop"

# nvidia-bug-report
sudo install -D -m755 nvidia-bug-report.sh /usr/bin/nvidia-bug-report.sh

# nvidia-smi
sudo install -D -m755 nvidia-smi /usr/bin/nvidia-smi
sudo install -D -m644 nvidia-smi.1.gz /usr/share/man/man1/nvidia-smi.1.gz

# OpenCL
sudo install -D -m644  nvidia.icd "/etc/OpenCL/vendors/nvidia.icd"
sudo install -D -m755 "libnvidia-compiler.so.$NV_VER" "/usr/lib/x86_64-linux-gnu/libnvidia-compiler.so.$NV_VER"
sudo install -D -m755 "libnvidia-opencl.so.$NV_VER" "/usr/lib/x86_64-linux-gnu/libnvidia-opencl.so.$NV_VER"
sudo ln -sf libnvidia-opencl.so.$NV_VER /usr/lib/x86_64-linux-gnu/libnvidia-opencl.so
sudo install -D -m755 "libOpenCL.so.1.0.0" "/usr/lib/x86_64-linux-gnu/nvidia/libOpenCL.so.1.0.0"

# Links to OpenCL
sudo ln -sf "/usr/lib/x86_64-linux-gnu/nvidia/libOpenCL.so.1.0.0" "/usr/lib/x86_64-linux-gnu/nvidia/libOpenCL.so"

# Documentation
sudo install -D -m644 LICENSE /usr/share/licenses/nvidia/LICENSE
sudo install -D -m644 README.txt /usr/share/doc/nvidia/README
sudo install -D -m644 NVIDIA_Changelog /usr/share/doc/nvidia/NVIDIA_Changelog

# Link to libwfb.so
sudo ln -sf /usr/lib/xorg/modules/libwfb.so /usr/lib/nvidia/xorg/modules/libwfb.so

# Link to libglx.so otherwise X dont find them
sudo ln -sf /usr/lib/nvidia/xorg/modules/extensions/libglx.so.$NV_VER /usr/lib/nvidia/xorg/modules/extensions/libglx.so

# Link to libGL
sudo ln -sf /usr/lib/x86_64-linux-gnu/nvidia/libGL.so.$NV_VER /usr/lib/x86_64-linux-gnu/nvidia/libGL.so.1


############################################
### Install dkms sources
############################################
# Remove dkms sources
sudo rm -rf /usr/src/nvidia-$NV_VER

sudo cp -R kernel /usr/src/nvidia-"$NV_VER"
sudo cp LICENSE /usr/src/nvidia-"$NV_VER"/
sudo cp README.txt /usr/src/nvidia-"$NV_VER"/

# Copy patches to dkms
# mkdir -p /usr/src/nvidia-"$NV_VER"/patches
# cp /usr/share/doc/packages/nvidia-bumblebee/*.patch /usr/src/nvidia-"$NV_VER"/patches/

# Patch makefile for x86_64 systems
# %ifarch x86_64
# sed '34 c\ARCH = x86_64' Makefile > mk1
# mv mk1 Makefile
# %endif

cat > dkms.conf << EOF
PACKAGE_NAME="nvidia"
PACKAGE_VERSION=$NV_VER
BUILT_MODULE_NAME[0]=nvidia
DEST_MODULE_LOCATION[0]="/updates/"
MAKE[0]="unset ARCH; IGNORE_CC_MISMATCH=1 env NV_VERBOSE=1 make \${parallel_jobs+-j\$parallel_jobs} modules KERNEL_UNAME=\${kernelver}"
CLEAN="make KERNEL_UNAME=\${kernelver} clean"
AUTOINSTALL=yes
BUILT_MODULE_NAME[1]="nvidia-modeset"
DEST_MODULE_LOCATION[1]="/updates/"
BUILT_MODULE_NAME[2]="nvidia-drm"
DEST_MODULE_LOCATION[2]="/updates/"
BUILT_MODULE_NAME[3]="nvidia-uvm"
DEST_MODULE_LOCATION[3]="/updates/"
EOF

sudo rm -f /usr/src/nvidia-"$NV_VER"/dkms.conf
sudo mv dkms.conf /usr/src/nvidia-"$NV_VER"/

# Install Kernel Modules
sudo /usr/sbin/dkms remove -m nvidia -v "$NV_VER" --all

sudo /usr/sbin/dkms build -m nvidia -v $NV_VER -k $(uname -r)
sudo /usr/sbin/dkms install -m nvidia -v $NV_VER -k $(uname -r)


############################################
### NVIDIA Driver 32-bit Library
############################################
Depends:
sudo dpkg --add-architecture i386
sudo apt-get install libglx-mesa0:i386

# Remove all 32-bit library
sudo rm -f /usr/lib/i386-linux-gnu/nvidia/libGL.so.$NV_VER
sudo rm -f /usr/lib/i386-linux-gnu/nvidia/libGL.so
sudo rm -f /usr/lib/i386-linux-gnu/nvidia/libGL.so.1
sudo rm -f /usr/lib/i386-linux-gnu/libnvidia-glcore.so.$NV_VER
sudo rm -f /usr/lib/i386-linux-gnu/vdpau/libvdpau_nvidia.so.$NV_VER
sudo rm -f /usr/lib/i386-linux-gnu/vdpau/libvdpau_nvidia.so.1
sudo rm -f /usr/lib/i386-linux-gnu/libcuda.so.$NV_VER
sudo rm -f /usr/lib/i386-linux-gnu/libnvcuvid.so.$NV_VER
sudo rm -f /usr/lib/i386-linux-gnu/libnvidia-ptxjitcompiler.so.$NV_VER
sudo rm -f /usr/lib/i386-linux-gnu/libnvidia-fatbinaryloader.so.$NV_VER
sudo rm -f /usr/lib/i386-linux-gnu/libnvidia-tls.so.$NV_VER
sudo rm -f /usr/lib/i386-linux-gnu/libnvidia-compiler.so.$NV_VER
sudo rm -f /usr/lib/i386-linux-gnu/libnvidia-opencl.so.$NV_VER
sudo rm -f /usr/lib/i386-linux-gnu/libnvidia-ml.so.$NV_VER
sudo rm -f /usr/lib/i386-linux-gnu/nvidia/libOpenCL.so.1.0.0
sudo rm -f /usr/lib/i386-linux-gnu/nvidia/libOpenCL.so

sudo /sbin/ldconfig

# Install library
# OpenGL library
sudo install -D -m755 32/libGL.so.$NV_VER /usr/lib/i386-linux-gnu/nvidia/libGL.so.$NV_VER

# OpenGL Links
sudo ln -sf /usr/lib/i386-linux-gnu/nvidia/libGL.so.$NV_VER /usr/lib/i386-linux-gnu/nvidia/libGL.so
sudo ln -sf /usr/lib/i386-linux-gnu/nvidia/libGL.so.$NV_VER /usr/lib/i386-linux-gnu/nvidia/libGL.so.1

# OpenGL core library
sudo install -D -m755 32/libnvidia-glcore.so.$NV_VER /usr/lib/i386-linux-gnu/libnvidia-glcore.so.$NV_VER

# VDPAU
sudo install -D -m755 32/libvdpau_nvidia.so.$NV_VER /usr/lib/i386-linux-gnu/vdpau/libvdpau_nvidia.so.$NV_VER
# sudo ln -sf libvdpau_nvidia.so.$NV_VER /usr/lib/i386-linux-gnu/vdpau/libvdpau_nvidia.so.1

# CUDA
sudo install -D -m755 32/libcuda.so.$NV_VER /usr/lib/i386-linux-gnu/libcuda.so.$NV_VER
sudo install -D -m755 32/libnvcuvid.so.$NV_VER /usr/lib/i386-linux-gnu/libnvcuvid.so.$NV_VER
sudo install -D -m755 32/libnvidia-ptxjitcompiler.so.$NV_VER /usr/lib/i386-linux-gnu/libnvidia-ptxjitcompiler.so.$NV_VER

# NVIDIA FAT binary loader library
sudo install -D -m755 32/libnvidia-fatbinaryloader.so.$NV_VER /usr/lib/i386-linux-gnu/libnvidia-fatbinaryloader.so.$NV_VER

# nvidia-tls library
sudo install -D -m755 32/tls/libnvidia-tls.so.$NV_VER /usr/lib/i386-linux-gnu/libnvidia-tls.so.$NV_VER

# OpenCL
sudo install -D -m755 32/libnvidia-compiler.so.$NV_VER /usr/lib/i386-linux-gnu/libnvidia-compiler.so.$NV_VER
sudo install -D -m755 32/libnvidia-opencl.so.$NV_VER /usr/lib/i386-linux-gnu/libnvidia-opencl.so.$NV_VER
sudo install -D -m755 32/libnvidia-ml.so.$NV_VER /usr/lib/i386-linux-gnu/libnvidia-ml.so.$NV_VER
sudo install -D -m755 32/libOpenCL.so.1.0.0 /usr/lib/i386-linux-gnu/nvidia/libOpenCL.so.1.0.0

# Links
sudo ln -sf /usr/lib/i386-linux-gnu/nvidia/libOpenCL.so.1.0.0 /usr/lib/i386-linux-gnu/nvidia/libOpenCL.so

sudo /sbin/ldconfig

sudo sh -c 'echo "blacklist nouveau" > /etc/modprobe.d/50-blacklist.conf'

sudo update-initramfs -u

# clean
cd ..
sudo rm -rf "$NV_NAME"-"$NV_VER".run
sudo rm -rf "$NV_NAME"-"$NV_VER"



PCI-E 的 nVidia 顯示卡 安裝後執行 sudo nvidia-xconfig
NVIDIA Optimus 略過 進行下一步...

3/20 14:44:07
應用擴展 工具箱


 [無發表權] 請登錄或者註冊


可以查看帖子.
不可發帖.
不可回覆.
不可編輯自己的帖子.
不可刪除自己的帖子.
不可發起投票調查.
不可在投票調查中投票.
不可上傳附件.
不可不經審核直接發帖.