ubuntu18.04安装显卡驱动后,循环登录( NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA dr);

ubuntu18.04安装显卡驱动后,循环登录(或者登录后无法进入桌面, 卡在 unbuntu 的红色背景中);
(ubuntu18.04, 内核 5.4.0-90-generic, nvidia-driver)

设备环境

联想笔记本RTX2060 的显卡, 系统ubuntu18.04.05(5.4.0-42-generic), 在系统自己更新(18.04.06, 5.4.0-90-generic)后会产生一个新的默认内核.

1. 循环登录

现象:

  1. 在新的内核环境下,禁用了nouveau, 使用 ./xxx.run -no-x-check -no-nouveau-check -no-opengl-files, 依次安装,卸载过三种显卡驱动nvidia-driver- 470.86, 470.82, 495.44,

  2. 出现的问题是显卡安装后,使用 nvidia-smi 可以查看到显卡信息, 但是重启登录过后, 卡在进入桌面的那一步, 无法进入桌面, 卡在 unbuntu 的红色背景中;

  3. 或者是输入密码后,出现循环登录的情况;

解决方法, 注意,笔者这里是笔记本,双系统,ubtun+win10, 如果是单系统的台式机,请不要执行以下删除操作。

 1.  进入 advance ubuntu 中, 使用5.4.0.-42 内核进入系统,
   注意到刚刚是在5.4.0-90 上安装的nvidia-driver. 
如果没有之前的内核可以选择的话,直接进入 tty 文本界面,进行操作;
 3.  sudo  rm  /etc/X11/xorg.conf 
 4.  sudo reboot 

对于台式机,单系统 ubuntu 时,
如果误删了 xorg.conf 文件,
则重启机器时, 按住 shift 键, 进入 Advance options for Ubuntu ;

选择低版本的 ubuntu 进入, 由于刚才删除 xorg 是高版本内核中的配置文件,
所以可以进入 低版本的 kernel 中, 重新配置,
使用低版本的kernel 作为默认启动项, 具体方法见 第三节。

2. NVIDIA-SMI has failed

2.1 dkms 重新编译nvidia driver

若出现如下情况:
NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

step1:sudo apt-get install dkms

step2: sudo dkms install -m nvidia -v 4xx.79

其中step2 中的4xx.79是NVIDIA的版本号,当你不知道的时候,进入/usr/src目录中,可以看到里面有nvidia文件夹,后缀就是其版本号;

nvidia-smi

3 内核版本与 nvidia driver 不匹配

如果上面一个不行, 且出现下面情况:

3.1 出现内核版本与 nvidia -driver 驱动不匹配的 情况

sudo dkms install -m nvidia -v 535.104.05

Kernel preparation unnecessary for this kernel.  Skipping...

Building module:
cleaning build area...
'make' -j16 NV_EXCLUDE_BUILD_MODULES='' KERNEL_UNAME=5.15.0-107-generic modules...(bad exit status: 2)
ERROR (dkms apport): binary package for nvidia: 535.104.05 not found
Error! Bad return status for module build on kernel: 5.15.0-107-generic (x86_64)
Consult /var/lib/dkms/nvidia/535.104.05/build/make.log for more information.

在使用 DKMS(Dynamic Kernel Module Support) (动态内核模块支持)安装 NVIDIA 驱动程序期间遇到的错误消息表明存在一些潜在问题:

内核兼容性:该错误 bad exit status: 2 表明 NVIDIA 驱动程序版本和您当前的内核版本 5.15.0-107-generic 可能存在兼容性问题。

缺少二进制包:该消息 binary package for nvidia: 535.104.05 not found 表明您尝试安装的 NVIDIA 驱动程序的特定版本可能未正确设置或在 DKMS 树中可用。

生成错误:查阅 make.log 文件的建议对于确定生成失败的确切原因至关重要。此日志将包含有关编译过程中遇到的错误的详细信息。

3.2 查看

出现上述的3.1 中情况的原因, 是由于当前ubuntu 的 内核版本 与 nvidia 驱动不匹配造成的.

  1. 切换到 /usr/src 目录下, 看当前存在的内核版本;
:/usr/src$ ls
linux                              linux-source-5.4.0
linux-headers-5.15.0-105-generic   linux-source-5.4.0.tar.bz2
linux-headers-5.15.0-107-generic   nvidia-535.104.05
linux-hwe-5.15-headers-5.15.0-105  vboxhost-7.0.16
linux-hwe-5.15-headers-5.15.0-10

使用 uname -a 可以看到当前正在使用的内核版本:

uname -a
Linux Lenovo-Legion-Y7000P2020H 5.15.0-105-generic #115~20.04.1-Ubuntu SMP 

3.3 回退内核

在启动机器时, 通过 Adavances options for ubuntu , 可以看到 当前存在的内核版本情况,

.....
Ubuntu, with Linux 5.15.0-105-generic
.....

通常是两对, 一个是更新的+ recover mode; 另一个是之前的;

我们需要回退到之前 旧版本的内核。

sudo gedit /etc/default/grub

设置 GRUB 默认条目:
将该 GRUB_DEFAULT=0 行替换为记下的确切名称,并用引号括起来。例如

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

保存和更新 GRUB:

sudo update-grub

如果出现警告时,

sudo update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-107-generic
Found initrd image: /boot/initrd.img-5.15.0-107-generic
Found linux image: /boot/vmlinuz-5.15.0-105-generic
Found initrd image: /boot/initrd.img-5.15.0-105-generic
Warning: Please don't use old title `Ubuntu, with Linux 5.15.0-105-generic' for GRUB_DEFAULT, use `Advanced options for Ubuntu>Ubuntu, with Linux 5.15.0-105-generic' (for versions before 2.00) or `gnulinux-advanced-9b9f03eb-9d60-45cd-aae7-cb1d0ce2e6f0>gnulinux-5.15.0-105-generic-advanced-9b9f03eb-9d60-45cd-aae7-cb1d0ce2e6f0' (for 2.00 or later)
Found Windows Boot Manager on /dev/nvme1n1p1@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for UEFI Firmware Settings
done

则重新修改 grub,
注意,以下字符不同的机器会产生不同的字符串, 需要根据自己的机器进行修改。

GRUB_DEFAULT="gnulinux-advanced-9b9f03eb-9d60-45cd-aae7-cb1d0ce2e6f0>gnulinux-5.15.0-105-generic-advanced-9b9f03eb-9d60-45cd-aae7-cb1d0ce2e6f0"

使用以下命令 grep 验证菜单项:
为确保使用正确的条目,您可以列出所有 GRUB 菜单条目。使用以下命令来获取 GRUB 配置文件:

grep -A10 "menuentry '" /boot/grub/grub.cfg

同样, 需要更新grub;

sudo update-grub

3.4 阻止内核更新

为了防止将来的内核更新,您需要保存内核软件包:

sudo apt-mark hold linux-image-5.15.0-105-generic linux-headers-5.15.0-105-generic

验证保留:

dpkg --get-selections | grep linux

通过配置正确的 GRUB 菜单项并保存内核软件包,您可以确保系统以所需的内核版本启动,并防止不必要的内核更新。此设置在双启动方案中特别有用,在这些方案中,在重新启动时保持稳定的环境至关重要。

短时间内, 可以通过回退到低版本的内核版本, 但如果长期不更新kernel , 则会存在安全隐患, 所以有时间的情况下,应该更新内核。

------------------------------------- 我是分割线----------------------------------------------------------

  1. make oldconfig
cat /var/lib/dkms/nvidia/535.104.05/build/make.log

DKMS make.log for nvidia-535.104.05 for kernel 5.15.0-107-generic (x86_64)
2024年 05月 16日 星期四 09:15:23 CST
make[1]: Entering directory '/usr/src/linux-headers-5.15.0-107-generic'

  ERROR: Kernel configuration is invalid.
         include/generated/autoconf.h or include/config/auto.conf are missing.
         Run 'make oldconfig && make prepare' on kernel src to fix it.

make[1]: *** [Makefile:758: include/config/auto.conf] Error 1
make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-107-generic'
make: *** [Makefile:82: modules] Error 2

共享的 DKMS make.log 错误消息表明构建 NVIDIA 驱动程序模块所需的内核配置文件存在问题。具体来说,关于“内核配置无效”的错误和缺少 include/generated/autoconf.h 或 include/config/auto.conf 文件是关键问题。

如果内核头文件没有为模块编译做好适当的准备,通常会发生此类问题。以下是解决此问题的方法:

首先,确保您位于内核头文件所在的正确目录中。对于 Ubuntu,它通常是 /usr/src/linux-headers-$(uname -r)/ .执行以下命令:

cd /usr/src/linux-headers-$(uname -r)
sudo make oldconfig
sudo make prepare
sudo make oldconfig

LEX     scripts/kconfig/lexer.lex.c
/bin/sh: 1: flex: not found
make[1]: *** [scripts/Makefile.host:9: scripts/kconfig/lexer.lex.c] Error 127
make: *** [Makefile:630: oldconfig] Error 2
respecting_god@Lenovo-Legion-Y7000P2020H:/usr/src/linux-headers-5.15.0-107-generic$ sudo make prepare
  SYNC    include/config/auto.conf.cmd
  LEX     scripts/kconfig/lexer.lex.c
/bin/sh: 1: flex: not found
make[2]: *** [scripts/Makefile.host:9: scripts/kconfig/lexer.lex.c] Error 127
make[1]: *** [Makefile:630: syncconfig] Error 2
make: *** [Makefile:750: include/config/auto.conf.cmd] Error 2

make prepare 期间 make oldconfig 遇到的错误消息,表示系统中缺少该 flex 实用程序。 Flex 是用于生成扫描仪的工具:识别文本中词汇模式的程序。它是构建 Linux 内核和内核模块的某些部分所必需的。

sudo apt-get update
sudo apt-get install flex bison build-essential
sudo make prepare
  SYNC    include/config/auto.conf.cmd
make[1]: *** No rule to make target 'arch/x86/entry/syscalls/syscall_32.tbl', needed by 'arch/x86/include/generated/uapi/asm/unistd_32.h'.  Stop.
make: *** [arch/x86/Makefile:217: archheaders] Error 2

在此期间 sudo make prepare 遇到的错误表明与生成特定于体系结构的标头相关的 make 过程存在问题,尤其是对于 x86 体系结构。这可能是由于多种原因造成的,包括环境中的内核头文件不完整或不一致,或者缺少构建模块所需的基本文件。

错误提到缺少 syscall_32.tbl .此文件对于在 x86 系统上构建内核的某些部分至关重要,尤其是在使用 32 位支持进行编译时:

注意 ,以下多个 步骤 需要执行 sudo 权限, 并且软连接 建立时, 如果该路径下存在多个相同前缀同名文件时, 则需要明确该文件的名称 ,不可用通配符*

sudo apt-get install linux-source
cd /usr/src
sudo tar xjf linux-source-*.tar.bz2
sudo ln -s linux-source-* linux
cd linux
sudo make oldconfig
sudo  make prepare

  1. 使用默认配置
    当开始出现, 如下选项时, 笔者在这里,全使用了默认配置,没有修改
IRQ subsystem
*
Use IRQ threading by default (IRQ_FORCED_THREADING_DEFAULT) [N/y/?] (NEW) 
  1. openssl
    错误表明您的系统中缺少 OpenSSL 标头,而编译处理加密签名(如模块签名)的 Linux 内核部分需要这些标头。缺少的特定文件是 openssl/opensslv.h ,它是 OpenSSL 开发包的一部分。
HOSTCC  scripts/sign-file
scripts/sign-file.c:25:10: fatal error: openssl/opensslv.h: No such file or directory
   25 | #include <openssl/opensslv.h>
      |          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [scripts/Makefile.host:107: scripts/sign-file] Error 1
make: *** [Makefile:1163: scripts] Error 2
sudo apt-get update
sudo apt-get install libssl-dev
make clean
make  -j 12
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Ubuntu 18.04上安装nvidia-smi,可以按照以下步骤进行操作: 1. 首先,通过运行以下命令来检查是否已安装NVIDIA驱动: ``` cat /proc/driver/nvidia/version ``` 如果输出为空,表示没有安装NVIDIA驱动。 2. 如果没有安装NVIDIA驱动,可以前往NVIDIA官网(https://www.nvidia.cn/drivers/unix/linux-amd64-display-archive/和https://www.nvidia.com/en-us/drivers/unix/)自行下载适用于您的内核版本的驱动程序。 3. 禁用Nouveau驱动。可以通过在开机界面选择进入Ubuntu高级选项,然后在Recovery Menu中选择root选项。接下来,您将进入控制台,并输入以下命令来卸载已安装NVIDIA驱动: ``` sudo apt remove nvidia-版本号 ``` (请将“版本号”替换为您安装NVIDIA驱动的版本号) 4. 重启系统后,在终端中运行以下命令来自动安装适用于您的硬件的NVIDIA驱动: ``` sudo ubuntu-drivers autoinstall ``` 5. 安装完成后,您可以通过按下Window键(即Super键)并搜索“Software & Updates”来打开软件和更新程序。在“Additional Drivers”页面下,您将看到NVIDIA驱动的选项。 6. 在“Additional Drivers”页面上,选择适合您的NVIDIA显卡的驱动,然后点击“Apply Changes”按钮。系统将自动安装所选驱动程序。 安装完成后,您应该能够在Ubuntu 18.04上使用nvidia-smi命令来查看NVIDIA显卡的相关信息。 <span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值