Linux 安裝 NVidia 驅動程式
環境
- OS: Debian 11
- GPU: Nvidia 410
- 建議開機: boot
執行步驟
- 檢查 GPU 型號
lspci -nn | egrep -i "3d|display|vga"
00:02.0 VGA compatible controller [0300]: Intel Corporation HD Graphics 630 [8086:591b] (rev 04)
01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GP106M [GeForce GTX 1060 Mobile] [10de:1c20] (rev a1)
- 安裝 linux-headers 及必要套件
- Debian
sudo apt -y install linux-headers-$(uname -r) build-essential libglvnd-dev pkg-config gcc g++ make
- 移除不必要套件
- 下載最新 Nvidia driver
到以下網址下載最新的驅動程式
https://www.nvidia.com/zh-tw/geforce/drivers/
wget https://tw.download.nvidia.com/XFree86/Linux-x86_64/470.256.02/NVIDIA-Linux-x86_64-470.256.02.run
- 關閉
sudo tee /etc/modprobe.d/blacklist-nouveau.conf<<EOF
blacklist nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off
EOF
sudo update-initramfs -u
sudo systemctl set-default multi-user.target
sudo reboot
lsmod | grep nouveau
- 更新
# 使用 別人包好的
sudo apt install nvidia-driver firmware-misc-nonfree
# 使用 NVidia 官方驅動程式
sudo bash ./NVIDIA-Linux-x86_64-470.256.02.run
- 啟動圖型介面
sudo systemctl set-default graphical.target
- 檢查指令
nvidia-smi
lspci | grep -i nvidia
CUDA 安裝
wget https://developer.download.nvidia.com/compute/cuda/repos/debian12/x86_64/cuda-keyring_1.1-1_all.deb
sudo apt install ./cuda-keyring_1.1-1_all.deb
sudo add-apt-repository contrib
sudo add-apt-repository non-free
sudo apt update
sudo apt install cuda-toolkit-12-4
sudo apt install -y cuda-drivers
~/.bashrc
或/etc/profile.d/nvidia.sh
export PATH=/usr/local/cuda-12/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-12/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
nvcc --version
pollochang@pollo-ai:~$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Mar_28_02:18:24_PDT_2024
Cuda compilation tools, release 12.4, V12.4.131
Build cuda_12.4.r12.4/compiler.34097967_0
完全移除
sudo apt purge "*nvidia*"
錯誤處理
ERROR: Unable to find the kernel source tree for the currently running kernel. Please make sure you have installed the kernel source files for your kernel and that they are properly configured; on RedHat Linux systems, for example, be sure you have the 'kernel-source' or 'kernel-devel' RPM installed. If you know the correct kernel source files are installed, you may specify the kernel source path with the '--kernel-source-path' command line option.
NVidia
參考資料
- How to Install Nvidia Drivers on Debian
- 在 Debian 中安裝 nvidia 驅動程式
- 如何在Debian系統安裝Nvidia驅動、CUDA、cuDNN
- How to Install NVIDIA CUDA and cuDNN on Debian 12 Bookworm
dkms firmware-nvidia-gsp glx-alternative-mesa glx-alternative-nvidia glx-diversions libcuda1 libegl-nvidia0 libgl1-nvidia-glvnd-glx libgles-nvidia1 libgles-nvidia2 libglx-nvidia0 libnvcuvid1 libnvidia-allocator1 libnvidia-cfg1 libnvidia-egl-gbm1 libnvidia-egl-wayland1 libnvidia-eglcore libnvidia-encode1 libnvidia-glcore libnvidia-glvkspirv libnvidia-ml1 libnvidia-pkcs11-openssl3 libnvidia-ptxjitcompiler1 libnvidia-rtcore linux-headers-amd64 nvidia-alternative nvidia-driver nvidia-driver-bin nvidia-driver-libs nvidia-egl-common nvidia-egl-icd nvidia-installer-cleanup nvidia-kernel-common nvidia-kernel-dkms nvidia-kernel-support nvidia-legacy-check nvidia-modprobe nvidia-persistenced nvidia-settings nvidia-support nvidia-suspend-common nvidia-vdpau-driver nvidia-vulkan-common nvidia-vulkan-icd update-glx xserver-xorg-video-nvidia