ubuntu NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driver is installled

ubuntu20.04重启后输入nvidia-smi发现报错:
NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
出现上述错误应该是ubuntu重启时更新了内核导致内核版本和驱动版本不匹配导致的。
参考文章方法:

sudo apt-add-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install dkms

# 查看显卡驱动版本
ls /usr/src

可以看到一个文件夹以显卡驱动版本号命名,若没有,则显卡驱动没装上,需要重新装显卡驱动
在这里插入图片描述
然后执行命令安装上面对应的驱动版本

sudo dkms install -m nvidia -v 545.29.06

执行上述命令报错:
ERROR: Cannot create report: [Errno 17] File exists: ‘/var/crash/nvidia-kernel-source-5.15.0.107-server.0.crash’
Error! Bad return status for module build on kernel: 5.15.0.107-generic (x86_64)
Consult /var/lib/dkms/nvidia/545.29.06/build/make.log for more information.

进入到log文件中查看发现,出错原因是在/usr/src/linux-headers-5.15.0-107-generic/下:
include/generated/autoconf.h or include/config/auto.conf 不存在。
我查找对应的文件后发现上述的两个文件是存在的。
接着我按照log中提示的方式在/usr/src/linux-headers-5.15.0-107-generic/下重新编译内核:

make oldconfig
make prepare

执行上述命令时也报了很多错误,比如一些依赖包没有安装,在执行make prepare时报了如下错误:
make prepare No rule to make target ‘arch/x86/entry/syscalls/syscall_32.tbl’
查找之后无果。
注:如果在上述报错中,log文件中的错误是:You are building kernel with non-retpoline compiler, please update your compiler。
原因是kernel版本与gcc不匹配,查看你的gcc版本是不是过低。

最后解决方法
因为ubuntu重启后更新了内核,故在上述方法行不通后,我就考虑将当前更新的内核版本降级,查看当前内核版本

uname -a

发现我当前内核是5.15.0-107。
查看系统现存的内核版本

grep menuentry /boot/grub/grub.cfg

在这里插入图片描述
发现系统中还存在另一个内核版本是5.15.0-105(我猜想这个应该是我重启之前的版本)。复制上述信息中想要降级的内核menuentry之后的单引号内的字符串,比如:

Ubuntu, with Linux 5.15.0-105-generic

我这里需要把内核版本降级到5.15.0-105。参考文章

# 查看grub版本,我这里grub版本是2.04
grub-install --version

# 修改grub中的内容
# 将第一个GRUB_DEFAULT=0修改为:GRUB_DEFAULT="Ubuntu, with Linux 5.15.0-105-generic"
sudo gedit /etc/default/grub

# 修改后更新grub
sudo update-grub

更新中如果看到警告信息:
警告: Please don’t useold title ‘Ubuntu,Linux 5.15.0-105-generic’for GRUB_DEFAULT,
use’Advanced options for Ubuntu>Ubuntu,Linux 5.15.0-105-generic’
(forversionsbefore2.00) or’gnulinux-advanced-b7d0a478-c427-4233-a9b3-f677703eab10>gnulinux-5.15.0-105-generic-advanced-b7d0a478-c427-4233-a9b3-f677703eab10’ (for2.00or later)

根据之前看到的grub版本,如果大于等于2.00,则将第三个单引号内的字符串复制粘贴.否则把第二个单引号内的字符串复制粘贴
例如我的grub版本大于2.00,则再次将之前的

GRUB_DEFAULT="Ubuntu, with Linux 5.15.0-105-generic"

修改为:

GRUB_DEFAULT='gnulinux-advanced-b7d0a478-c427-4233-a9b3-f677703eab10>gnulinux-5.15.0-105-generic-advanced-b7d0a478-c427-4233-a9b3-f677703eab10'

再次更新grub:

sudo update-grub

更新完成后再次执行最开始的命令:

sudo apt-add-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install dkms
sudo dkms install -m nvidia -v 545.29.06

输出如下信息:

Module nvidia/545.29.06 already installed on kernel 5.15.0-105-generic (x86_64).

说明成功了,接着重启电脑即可:

reboot

重启后重新输入:

nvidia-smi

发现可以正常显示了。

参考
https://blog.csdn.net/qq_41263444/article/details/119888947
https://blog.csdn.net/AQiya/article/details/128918727

  • 14
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值