一、官网下载驱动
官网链接https://developer.nvidia.com/rdp/cudnn-download
从官网下载.sh文件,保存在/home/你的用户名
/下,以便之后使用。
二、禁用nouveau显卡
sudo vim /etc/modprobe.d/blacklist.conf
如果没有安装vim(备选)
sudo apt-get update
sudo apt-get install vim
在blacklist.conf末尾加入
blacklist nouveau
options nouveau modeset=0
更新系统,并重启
sudo update-initramfs -u
sudo reboot
验证nouveau是否禁用
lsmod | grep nouveau
# 没任何信息说明nouveau已禁用
三、安装驱动
按ctr+alt+f? 进入ttf 命令行模式, (?是几自己试,如果都没有反应使用下面代码进入)
# 关闭用户图形界面
sudo systemctl set-default multi-user.target
sudo reboot
sudo service lightdm stop # 这个也是关闭图形界面, 可能不用执行了。
卸载原有驱动
sudo apt-get remove nvidia-* (这个卸载不会影响到cuda和cudnn的,放心使用)
运行驱动文件
sudo chmod a+x NVIDIA-Linux-x86_64-460.58.run # 文件名看自己的
sudo ./NVIDIA-Linux-x86_64-460.58.run -no-x-check -no-nouveau-check -no-opengl-files
# -no-x-check 安装驱动时关闭X服务
# -no-nouveau-check 安装驱动时禁用nouveau
# -no-opengl-files 只安装驱动文件, 不安装opengl文件
安装中的选项
the distribution-provided pre-install script failed! Are you sure want to continue ? Yes
would you like to register the kernel module sources with DKMS? this will allow DKMS to automatically ... No
nvidia's 32-bit compatibility libraries? No
would you like to run the nvidia-xconfigutility to automatical update your x configuration so that... Yes
安装过程可能会告知缺c,缺make,自行百度or谷歌,apt-get install 对应文件,再重新run 驱动程序即可。
四、检验驱动是否安装成功
挂载驱动
modprobe nvidia
检验驱动是否安装成功
nvidia-smi
开启图形界面(如果之前使用了命令行关闭了图形界面)
sudo systemctl set-default graphical.target
sudo reboot
五、关闭内核更新(可选)
为什么要关闭内核更新?
因为如果不关闭,可能重启电脑,内核更新,导致驱动被挂掉。(可能重新挂载下也可以?尝试过的麻烦说一下)
关闭内核更新:
- 查看系统使用的内核
uname -a # 查看系统正在使用的内核
"""结果为:
Linux 用户名-B40MH 5.4.0-67-generic ...
注意: 5.4.0-67-generic为版本号
"""
- 将系统使用的内核设置为禁止自动更新
sudo apt-mark hold linux-image-5.4.0-67-generic # 注意版本号
sudo apt-mark hold linux-modules-extra-5.4.0-67-generic
六、参考
参考自https://blog.youkuaiyun.com/haijun7013/article/details/105454293