天天看点

NVIDIA无法连接:NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driver

前言

在使用Ubuntu服务器的时候,有时会碰到GPU无法使用的情况,即当输入指令‘nvidia-smi’显示NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver

情况有二:

第一种:显卡驱动型号自动改变

NVIDIA无法连接:NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driver

有时候显卡驱动自动切换到开源的显卡驱动“Nouveau”上,导致NVIDIA显卡驱动失效,把驱动调回第一个驱动即可解决问题。(这里没想通这里的驱动为啥会自动切换,也许跟内核自动更新有关)

第二种:内核更新导致原显卡驱动不可用

这里许多博主说用安装DKMS的方式解决,但是对我无效。遂采用降低内核版本并禁用内核更新的方式解决。

修改系统引导文件:sudo gedit /etc/default/grub

更改内容如下:

GRUB_TIMEOUT=10

GRUB_CMDLINE_LINUX_DEFAULT=“text”

# grub_timeout_style=hidden(以#号注释该语句)

更新使生效:sudo update-grub

重启后系统引导多了一个选择界面,分别是:

*ubuntu

*ubuntu的高级选项

选择最老的内核版本并启动,此时输入nvidia-smi正常

但是为了以绝后患,接下来关闭自动更新和自动升级内核:

NVIDIA无法连接:NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driver

在terminal输入 uname -a查看当前内核版本,博主的是5.11.0-40-generic

输入指令

sudo apt-mark hold linux-headers-5.11.0-40-generic

sudo apt-mark hold linux-image-5.11.0-40-generic

sudo apt-mark hold linux-modules-5.11.0-40-generic

sudo apt-mark hold linux-modules-extra-5.11.0-40-generic

sudo apt-mark hold linux-modules-nvidia-470-5.11.0-40-generic

查看启动项grep menuentry /boot/grub/grub.cfg

并编辑启动项

sudo gedit /etc/default/grub

设置默认启动项,更改GRUB_DEFAULT=0为 GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu,Linux 5.11.0-40-generic"

(如果是中文则为**“Ubuntu 高级选项>Ubuntu,Linux 5.11.0-40-generic”**)

继续阅读