贡献者: addis
因为 gcc 的版本是 11.2,但 kernel 编译 gcc 版本是 11.3,而这非常困难,参考子节 1 。
首先到 Nvidia 官网下载 Linux 驱动。安装以后提示需要先禁止 nouveau 驱动才可以安装。安装包可以自动写入一个 /etc/modprobe.d/nvidia-installer-disable-nouveau.conf
文件来试图禁止。
# generated by nvidia-installer
blacklist nouveau
options nouveau modeset=0
注意写入该文件后,如果显卡安装失败,那么重启以后就可能导致屏幕没有任何反应。但只要想办法把该文件删掉再次重启即可(例如用一个启动 U 盘)。
另外 Nvidia 驱动安装包的日志会写进 /var/log/nvidia-installer.log
。
安装包会提示这个
An alternate method of installing the NVIDIA driver was detected.
(This is usually a package provided by your distributor.) A
driver installed via that method may integrate better with your
system than a driver installed by nvidia-installer.
Please review the message provided by the maintainer of this alternate
installation method and decide how to proceed:
Continue installation Abort installation
ERROR: An error occurred while performing the step: "Building kernel modules". See /var/log/nvidia-installer.log for details.
失败原因: apt 在 trigger 的时候无法 load kernel,最可能是因为 kernel 编译器和当前编译器不一样。
sudo add-apt-repository ppa:graphics-drivers/ppa
/var/log/nvidia-installer.log
:
-> Kernel module compilation complete.
ERROR: Unable to load the kernel module 'nvidia.ko'. This happens most frequently when this kernel module was built against the wrong or improperly configured kernel sources, with a version of gcc that differs from the one used to build the target kernel, or if another driver, such as nouveau, is present and prevents the NVIDIA kernel module from obtaining ownership of the NVIDIA device(s), or no NVIDIA device installed in this system is supported by this NVIDIA Linux graphics driver release.
参考这个,推荐用 ubuntu-drivers tool。
sudo apt update
sudo ubuntu-drivers list
nvidia-driver-470-server, (kernel modules provided by nvidia-dkms-470-server)
nvidia-driver-390, (kernel modules provided by nvidia-dkms-390)
nvidia-driver-470, (kernel modules provided by nvidia-dkms-470)
nvidia-driver-510-server, (kernel modules provided by nvidia-dkms-510-server)
nvidia-driver-450-server, (kernel modules provided by nvidia-dkms-450-server)
nvidia-driver-418-server, (kernel modules provided by nvidia-dkms-418-server)
nvidia-driver-510, (kernel modules provided by nvidia-dkms-510)
sudo ubuntu-drivers install [--gpgpu]
sudo ubuntu-drivers install nvidia:510
,就会开始安装。