因近日有项目需要在Linux环境下,因此在主机上安装Ubuntu系统。但新安装的Ubuntu系统没有NVIDIA驱动,系统使用了CPU上的集显。没有NVIDIA驱动不仅无法让机器发挥显卡性能,甚至会影响显示器显示比例。因此开始了安装NVIDIA驱动的漫漫路。
网上有许多种安装方式,但是本人经验,推荐使用run文件手动安装。具体步骤如下:
首先在NVIDIA官网上下载对应的驱动
点击search后,下载对应的版本即可。
无论之前是否安装过NVIDIA驱动,都推荐执行这一步骤:
$ sudo apt-get remove --purge nvidia*
# 若安装失败也是这样卸载以及
$ sudo chmod a+x NVIDIA-Linux-x86_64-440.44.run
# 给予可执行权限
$ sudo sh NVIDIA-Linux-x86_64-440.44.run --uninstall #确保卸载干净。
Nouveau是由第三方为NVIDIA显卡开发的一个开源3D驱动,为了让用户安装完系统即可进入桌面,因此很多Linux发行版默认集成了Nouveau驱动。但是Nouveau驱动会影响安装NVIDIA官方驱动,因此在安装前要先禁用Nouveau驱动。
sudo gedit /etc/modprobe.d/blacklist.conf
在文本最后添加
blacklist nouveau
完成后,重启机器。
进入存放run文件的目录,执行以下命令:
$ sudo sh NVIDIA-Linux-x86_64-440.44.run -no-x-check -no-nouveau-check -no-opengl-files
本来安装 Nvidia驱动需要关闭 nouveau 驱动和图形界面,加上后面的参数后就不需要那么繁琐,最后一个opengl的参数十分关键,不加上去有可能安装过后重启时会出现循环登录。
安装中可能会出现以下问题:
1. There appears to already be a driver installed on your system (version:
390.42). As part of installing this driver (version: 390.42), the existing
driver will be uninstalled. Are you sure you want to continue?
Continue installation Abort installation
(选择 Coninue,如果是重装的话)
2. The distribution-provided pre-install script failed! Are you sure you want
to continue?
Continue installation Abort installation
(选择 Cotinue)
3. Would you like to register the kernel module sources with DKMS? This will
allow DKMS to automatically build a new module, if you install a different
kernel later.
Yes No
(这里选 No)
4. Install NVIDIA's 32-bit compatibility libraries?
Yes No
(这里选 No)
5. Installation of the kernel module for the NVIDIA Accelerated Graphics Driver
for Linux-x86_64 (version 390.42) is now complete.
OK
如果能出现第五条,那恭喜,您已成功安装NVIDIA驱动。重启后执行:
$ nvidia-smi
可以看到类似如下的内容:
Wed Sep 11 13:58:25 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 435.21 Driver Version: 435.21 CUDA Version: 10.1 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce 940MX Off | 00000000:03:00.0 Off | N/A |
| N/A 39C P0 N/A / N/A | 602MiB / 2004MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 2169 G /usr/lib/xorg/Xorg 249MiB |
| 0 2303 G /usr/bin/gnome-shell 109MiB |
| 0 2889 G ...uest-channel-token=14726807182689878412 186MiB |
| 0 3458 G ...-token=3D67814D6F5E1D850334BE0B40D7F34F 5MiB |
| 0 3821 G .../下载/pycharm-2019.1.1/jre64/bin/java 2MiB |
| 0 6205 G ...uest-channel-token=11960780542914565189 44MiB |
+-----------------------------------------------------------------------------+
大功告成!
Unable to load the “nvidia-drm” kernel module
ERROR: Installation has failed. Please see the file '/var/log/nvidia-installer.log' for details. You may find suggestions on fixing installation problems in the README available on the Linux driver download page at www.nvidia.com.
出现这个问题可能有两个原因:
解决方法:
执行以下命令:
sudo mokutil --disable-validation
该命令会要求设置一个 8-16位的密码,设置完成后重启。第一次重启,会有几秒钟提示按任意键进入MoK管理界面,然后按照提示输入密码,禁用Secure boot 即可。
解决方法:
执行以下命令:
$ grep nvidia /etc/modprobe.d/* /lib/modprobe.d/*
运行结果如下,可能不同机器的结果会有小出入,但可见NVIDIA的一些模块被禁用:
/etc/modprobe.d/blacklist-framebuffer.conf:blacklist nvidiafb
/lib/modprobe.d/blacklist-nvidia.conf:# This file was generated by nvidia-prime
/lib/modprobe.d/blacklist-nvidia.conf:blacklist nvidia
/lib/modprobe.d/blacklist-nvidia.conf:blacklist nvidia-drm
/lib/modprobe.d/blacklist-nvidia.conf:blacklist nvidia-modeset
/lib/modprobe.d/blacklist-nvidia.conf:alias nvidia off
/lib/modprobe.d/blacklist-nvidia.conf:alias nvidia-drm off
/lib/modprobe.d/blacklist-nvidia.conf:alias nvidia-modeset off
/lib/modprobe.d/nvidia-kms.conf:# This file was generated by nvidia-prime
/lib/modprobe.d/nvidia-kms.conf:options nvidia-drm modeset=1
因此需要将这些blacklist文件删除或者转为.bak文件(可能不同机器文件名不同,可视上一命令运行结果定)
cd /etc/modprobe.d/
sudo mv blacklist-nvidia.conf blacklist-nvidia.conf.bak
cd /lib/modprobe.d/
sudo mv blacklist-nvidia.conf blacklist-nvidia.conf.bak
解决以上,重启后,再行安装即可!