安装nvidia-driver的血泪史

安装nvidia-driver的血泪史

查看显卡硬件型号

在终端输入:

ubuntu-drivers devices

可以看到如下界面:

== /sys/devices/pci0000:00/0000:00:03.0/0000:02:00.0 ==
modalias : pci:v000010DEd00001F07sv00001458sd000037ADbc03sc00i00
vendor   : NVIDIA Corporation
manual_install: True
driver   : nvidia-driver-418-server - distro non-free
driver   : nvidia-driver-450-server - distro non-free recommended
driver   : nvidia-driver-415 - third-party free
driver   : nvidia-driver-435 - distro non-free
driver   : nvidia-driver-440-server - distro non-free
driver   : xserver-xorg-video-nouveau - distro free builtin

我的显卡对应的推荐安装的版本号是:
nvidia-driver-450-server - distro non-free recommended

方法一:自动安装合适版本

sudo ubuntu-drivers autoinstall

就可以自动安装了。

方法二:使用 dkms 自动安装

sudo apt-get install dkms 

DKMS全称是Dynamic Kernel Module Support,它可以帮我们维护内核外的这些驱动程序,在内核版本变动之后可以自动重新生成新的模块。

sudo dkms install -m nvidia -v 410.78 

410.78是安装驱动的版本

方法三:从官网下载,然后手动安装

方法三 第一步:查找合适的型号

确认自己电脑显卡的型号

lshw -numeric -C display

https://www.nvidia.com/Download/index.aspx
从官网下载合适的型号

注意每个选项,特别是操作系统那里,一定选择 Linux 64-bit

方法三 第二步:屏蔽开源驱动 nouveau

法1

(原文章说“可以不编辑blacklist.conf,NVIDIA.run驱动程序可以自己停止其他开源驱动,但是需要重启”)

sudo gedit /etc/modprobe.d/blacklist.conf

添加以下内容保存

blacklist vga16fb 
blacklist nouveau 
blacklist rivafb 
blacklist nvidiafb 
blacklist rivatv 
(这里有一行空格)

法2

Ubuntu 系统默认安装好是使用的一个开源的驱动:nouveau,我们要安装官方的驱动需要先禁用这个开源驱动,方法如下,依次执行:

sudo bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
sudo bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nvidia-nouveau.conf"

执行完上面两条指令后,我们使用如下命令看看是否成功禁用了开源驱动:cat /etc/modprobe.d/blacklist-nvidia-nouveau.conf。如果和下面一样,表示成功了。

cat /etc/modprobe.d/blacklist-nvidia-nouveau.conf
blacklist nouveau
options nouveau modeset=0

法3

sudo gedit /etc/modprobe.d/blacklist.conf

添加以下内容保存:

blacklist nouveau 

法4

sudo gedit /etc/modprobe.d/blacklist.conf #打开文本

#在打开的最后加上两行:
blacklist nouveau 
options nouveau modeset=0

方法三 第三步:把nvidia显卡驱动删光

下面几种方法好像都可以

sudo apt-get purge nvidia*
# 或者
sudo apt-get autoremove --purge nvidia*
# 或者
sudo apt-get --purge remove nvidia-*
# 或者(好像保险一点,我用其他方法把我的nvidia-docker都给删了)
sudo /usr/bin/nvidia-uninstall
# 还有一个要删除的
sudo apt-get --purge remove xserver-xorg-video-nouveau

方法三 第四步:关停图形化界面 lightdm

sudo service lightdm stop
# 或者
sudo /etc/init.d/lightdm stop
# 第一个方法对我来说没用,没有任何响应

成功关闭服务后将出现:

lightdm stop/waiting
# 或者
[ ok ] Stopping lightdm (via systemctl): lightdm.service.

然后重启

sudo reboot

然后按快捷键:CTRL+ALT+F1 进入字符界面

输入用户名和密码,登录系统

方法三 第四步:

cd Downloads #进入你从官网下载驱动的位置
sudo sh nvidia.....run #中间是文件的名字

一些问题

问题1 Ubuntu – Install Latest Nvidia Drivers – UNMET Dependencies

https://itectec.com/ubuntu/ubuntu-install-latest-nvidia-drivers-unmet-dependencies/
在使用 sudo ubuntu-drivers autoinstall
的时候发生depends错误
he following packages have unmet dependencies:
nvidia-driver-440 : Depends: libnvidia-gl-440 (= 440.82-0ubuntu0~0.18.04.1) but it is not going to be installed

The following packages have unmet dependencies:
libnvidia-ifr1-450 : Depends: libnvidia-gl-450 but it is not going to be installed
nvidia-driver-450 : Depends: libnvidia-gl-450 (= 450.80.02-0ubuntu1) but it is not going to be installed
Recommends: libnvidia-compute-450:i386 (= 450.80.02-0ubuntu1)

The following packages have unmet dependencies:
libnvidia-gl-450 : Depends: libnvidia-common-450 but it is not installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

djz@sunlab:~$ sudo dpkg --remove --force-remove-reinstreq libnvidia-common-450
dpkg: warning: ignoring request to remove libnvidia-common-450 which isn't installed

djz@sunlab:~$ sudo dpkg --remove --force-remove-reinstreq libnvidia-gl-450
dpkg: dependency problems prevent removal of libnvidia-gl-450:amd64:
nvidia-driver-450 depends on libnvidia-gl-450 (= 450.80.02-0ubuntu1).
libnvidia-ifr1-450:amd64 depends on libnvidia-gl-450.

dpkg: error processing package libnvidia-gl-450:amd64 (--remove):
dependency problems - not removing

按照depend顺序,倒着来,挨个卸载

sudo dpkg --remove --force-remove-reinstreq libnvidia-compute-450-server:amd64

问题2


报错:WARNING: Unable to find suitable destination to install 32-bit compatibility libraries
解决办法:
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install libc6:i386

whereis nvidia
nvidia: /usr/lib/nvidia /usr/share/nvidia

sudo dkms install -m nvidia -v 340

dkms status
dkms status 显示
没有执行sudo dkms install -m nvidia -v 410.78之前
bbswitch, 0.8, 4.15.0-72-generic, x86_64: installed
bbswitch, 0.8, 4.15.0-74-generic, x86_64: installed
bbswitch, 0.8, 4.4.0-171-generic, x86_64: installed
之后
bbswitch, 0.8, 4.15.0-72-generic, x86_64: installed
bbswitch, 0.8, 4.15.0-74-generic, x86_64: installed
bbswitch, 0.8, 4.4.0-171-generic, x86_64: installed
nvidia, 410.78, 4.15.0-74-generic, x86_64: installed

参考:

http://www.mamicode.com/info-detail-1434964.html

https://www.jianshu.com/p/3cedce05a481

https://zhuanlan.zhihu.com/p/59618999

你可能感兴趣的:(安装nvidia-driver的血泪史)