ubuntu16.04——NVIDIA驱动安装(亲测好使!+避坑)

1、查看显卡型号

$ lshw -c video

  结果显示:

  

  可以看到你的显卡信息,比如我的就是 product: GF108GL[Quadro 600] 

  或

$ lspci | grep VGA
01:00.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)

2、下载驱动程序:

  http://www.nvidia.cn/Download/index.aspx

  下载完之后是一个名称为 NVIDIA-Linux-x86_64-xxx.xx.run 的文件。可以用chmod +x 增加执行许可权执行。

  

 

  为了再次确认一遍,你还可以使用这个命令查看你可以使用的驱动:

$ ubuntu-drivers devices

  结果显示:

  如果结果显示和搜索到的驱动版本一样,推荐也是390.67,那我们可以安心安装390.67版本。但是结果显示的并没有390.67,为了避免出错,建议选择结果显示中的版本号,如361。

  

 

  接着需要先安装一些 NVIDIA 显卡依赖的软件,在终端依次执行如下命令:

$ sudo dpkg --add-architecture i386
$ sudo apt update
$ sudo apt install build-essential libc6:i386

3、删除原有驱动:(可选)

$ sudo apt-get remove --purge nvidia*

4、禁用nouveau驱动:

  这一步必须,不禁用nvidia驱动安不上。

  编辑/etc/modprobe.d/blacklist-nouveau.conf 档案,新增以下内容

blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off

  然后储存。

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"

  关闭nouveau:

$ echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf

  然后重启:

$ sudo update-initramfs -u

$ sudo reboot

  验证是否禁用nouveau:

lsmod | grep nouveau

  没有信息返回说明已禁用(如图)

  

 

5、获取Kernel source(非常重要):

$ sudo apt-get install linux-source

$ apt-get install linux-headers-x.x.x-genneric

$ sudo apt-get install linux-headers-$(uname -r)

6、先按Ctrl + Alt + F1到控制台,关闭当前图形环境

$ sudo service lightdm stop

7、安装Nvidia驱动:

chmod +x NVIDIA-Linux-x86_64-xxx.xx.run
sudo ./NVIDIA-Linux-x86_64-xxx.xx.run
sudo ./NVIDIA-Linux-x86_64-396.18.run -no-x-check -no-nouveau-check -no-opengl-files

  //只有禁用opengl这样安装才不会出现循环登陆的问题

    -no-x-check:安装驱动时关闭X服务

    -no-nouveau-check:安装驱动时禁用nouveau

    -no-opengl-files:只安装驱动文件,不安装OpenGL文件

8、安装过程中的选项:

  The distribution-provided pre-install script failed! Are you sure you want to continue? 选择 yes 继续。

  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?  选择 No 继续。

  问题没记住,选项是:install without signing

  问题大概是:Nvidia's 32-bit compatibility libraries? 选择 No 继续。

  Would you like to run the nvidia-xconfigutility to automatically update your x configuration so that the NVIDIA x driver will be used when you restart x? Any pre-existing x confile will be backed up.  选择 Yes程中会有一些问题,自己回答选择Yes或者No。

  这些选项如果选择错误可能会导致安装失败,没关系,只要前面不出错,多尝试几次就好。

  如果出现安装错误

An NVIDIA kernel module ‘nvidia-drm’ appears to already be loaded in your kernel…

 

  那么就输入这一行代码

sudo systemctl isolate multi-user.target

sudo modprobe -r nvidia-drm

9、打开图形界面:

sudo service lightdm start

  然后挂在Nvidia驱动

$ modprobe nvidia

10、检查驱动是否安装成功

  说明驱动安装成功 

  下面也可以测试

sudo lshw -c video|grep configuration

configuration: driver=nvidia latency=0

11、参考链接

https://www.itread01.com/content/1546829642.html

https://blog.csdn.net/yaohuan2017/article/details/108670724

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

https://blog.csdn.net/qiancaobaicheng/article/details/95096354

12、注意!!!

  如果出现问题:

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 a driver such as
   rivafb/nvidiafb is present and prevents the NVIDIA kernel module from
   obtaining ownership of the NVIDIA graphics device(s), or NVIDIA GPU
   installed in this system is not supported by this NVIDIA Linux graphics
   driver release.

  可能是没有禁用安全引导项

posted @ 2021-01-21 21:49  涅风  阅读(5179)  评论(0编辑  收藏  举报