Ubuntu 16.04 安装nvidia驱动

小咪咪 2023-06-20 10:58 23阅读 0赞

环境

笔记本:技嘉

操作系统:ubuntu 16.04LTS 显卡:nvidia Geforce`GTX 1070

安装步骤

(安装方式——手动**run文件安装**)

1.搜索驱动程序下载

在NVIDIA驱动官网选择参数搜索后,下载,本次下载驱动为NVIDIA-Linux-x86_64-440.36.run

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjczMTI0MQ_size_16_color_FFFFFF_t_70

2.卸载旧驱动

卸载可能存在的旧版本 nvidia 驱动(对没有安装过 nvidia 驱动的主机,这步可以省略,但推荐执行,无害),如果你安装失败了也需要执行这一步

  1. sudo apt-get remove --purge nvidia*
  2. #若安装失败也是这样卸载以及
  3. ./NVIDIA-Linux-x86_64-390.48.run --uninstall #确保卸载干净。

3.安装可能需要的依赖

  1. #其实很多你的环境已经安装了,所以一般并没有多少时间。
  2. sudo apt-get update
  3. sudo apt-get install dkms build-essential linux-headers-generic
  4. sudo apt-get install gcc-multilib xorg-dev
  5. sudo apt-get install freeglut3-dev libx11-dev libxmu-dev install libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev

4.禁用noueau驱动

  1. sudo vi /etc/modprobe.d/blacklist-nouveau.conf
  2. #在文件 blacklist-nouveau.conf 中加入如下内容:
  3. blacklist nouveau
  4. blacklist lbm-nouveau
  5. options nouveau modeset=0
  6. alias nouveau off
  7. alias lbm-nouveau off
  8. #保存 :wq
  9. #禁用nouveau 内核模块
  10. echo options nouveau modeset=0 | sudo tee -a /etc/modprobe.d/nouveau-kms.conf
  11. sudo update-initramfs -u
  12. reboot #重启
  13. lsmod |grep nouveau #无显示则成功 当然驱动没了你的桌面分辨率会比较大。

5.进入blos关闭secure boot

一定要关闭,否则无法安装成功

技嘉笔记本重启“F2”进入,[security]->[Delete All Secure Boot Variables],选择[Yes],[Secure Boot]将从[Active]变为[Not Active],”F10”保存并退出

6.进入tty关闭图形界面

按 CTRL + ALT + F1 键进入,登录

  1. sudo service lightdm stop
  2. #为了重建视频输出,必须先将其暂停

7. 运行.run文件选择合适选项

  1. cd 下载目录
  2. chmod a+x NVIDIA-Linux-x86_64-440.36.run #添加权限
  3. sudo ./NVIDIA-Linux-x86_64-440.36.run --dkms --no-opengl-files

–no-opengl-files:表示只安装驱动文件,不安装OpenGL文件。这个参数不可省略,否则会导致登陆界面死循环,英语一般称为”login loop”或者”stuck in login”。
当然脸红的情况下并不会。
必选参数解释:因为NVIDIA的驱动默认会安装OpenGL,而Ubuntu的内核本身也有OpenGL、且与GUI显示息息相关,一旦NVIDIA的驱动覆写了OpenGL,在GUI需要动态链接OpenGL库的时候就引起问题。
–no-x-check:表示安装驱动时不检查X服务,非必需,我们已经禁用图形界面。
–no-nouveau-check:表示安装驱动时不检查nouveau,非必需,我们已经禁用驱动。
-Z, –disable-nouveau:禁用nouveau。此参数非必需,因为之前已经手动禁用了nouveau。
-A:查看更多高级选项。
-dkms(默认开启)在 kernel 自行更新时将驱动程序安装至模块中,从而阻止驱动程序重新安装。在 kernel 更新期间,dkms 触发驱动程序重编译至新的 kernel 模块堆栈。
8.安装过程中的问题

1.If you plan to no longer use the NVIDIA deriver, you should make sure that no X screens are configured to use the NVIDIA X driver X driver in your X configuration file. If you used nvidia-xconfig to configure X, it may have created a backup of your original configuration. Would you like to run ‘nvidia-xconfig —restore-original-backup’ to attempt restoration of the original X configuration file?

选择 no 继续

2.Would you like to run the nvidia-xconfig utility to automatically updata your X onfiguration file so that the NVIDIA X driver will be used when you restart X? Any pre-existing X configuration file will be backed up.

选择 no 继续

3.Would you like to register the kernel module souces with DKMS? This will allow DKMS to automatically build a new module, if you install a different kernel later?
选择 no 继续

4.问题大概是:Nvidia’s 32-bit compatibility libraries?

选择 no 继续

5.Kernel module compilation complete.The target kernel has CONFIG_MODULE_SIG set. which means that is supports

cryptographic signature on kernel modules. On some system, the kernel may refuse

to load modules without a valid signature from a trusted key. This system also has

UEFI Secure Boot enabled; many distrubtions enforce module signature verification

on UEFI systems when Secure Boot is enabled(2). Would you like sign the NVIDIA kernel

module? (Answer: Install without signing)

Kernel module load error: Required key not avaliable

ERROR: The kernel module failed to load, because it was not signed by a key

  1. that is trusted by the kernel. Please try installing the driver again.
  2. and sign the kernel when prompted to do so.

ERROR: Unable to load the kernel module ‘nvidia.ko’. This happens most

  1. frequently when this kernel module was built against the wrong or
  2. improperly configured kernel sources, with a version of gcc that
  3. differs from the one used to build the target kernel(1), or if a driver
  4. such as rivafb, nvidiafb. or nouveau is present and prevents the
  5. NVIDIA kernel module from obtaining ownership of the NVIDIA
  6. graphics device(s), or no NVIDIA GPU installed in this system is
  7. supported by this NVIDIA Linux graphics driver release.

以上错误简要描述了 NVIDIA 由于由于Ubuntu 16.04 的内核编译默认设置了 CONFIG_MODULE_SIG 为真, 然后Secure Boot打开所带来的问题, 更详细的描述见参考链接[2][3]. 大意是在支持UEFI的设备上打开Secure Boot 后,Ubuntu 16.04对于添加到内核的模块更加保守, 需要持有签名才能添加到模块中, 而显卡驱动由于要添加到内核中, 所以需要签名. 在安装过程中我们也会看到NVIDIA显卡会提示是否生成签名. 如果生成成功则没有问题,如果失败则,进入BIOS关闭Secure Boot

9.安装完成后验证

  1. nvidia-smi #若列出GPU的信息列表,表示驱动安装成功

若失败则跳回2卸载后重新开始

【参考】

最全面解析 Ubuntu 16.04 安装nvidia驱动 以及各种错误

ubuntu 上NVIDIA驱动和CUDA9.0 的坑之一二

安装驱动时的问题

发表评论

表情:
评论列表 (有 0 条评论,23人围观)

还没有评论,来说两句吧...

相关阅读