升级Ubuntu 22.04后因NVIDIA驱动问题导致系统更新失败
升级Ubuntu 22.04后因NVIDIA驱动问题导致系统更新失败
问题描述
升级到Ubuntu 22.04后,执行sudo apt update && sudo apt install signal-desktop这类命令时,会触发NVIDIA DKMS驱动编译失败,进而导致系统更新流程卡住。核心问题表现为:
- DKMS构建模块时提示内核配置无效,缺少
include/generated/autoconf.h或include/config/auto.conf文件 dpkg无法完成nvidia-dkms-470、nvidia-driver-470、nvidia-driver-460的配置,出现依赖链错误- 尝试手动执行
make oldconfig && make prepare时,系统提示找不到对应规则
关键报错片段:
Setting up nvidia-dkms-470 (470.161.03-0ubuntu0.22.04.1) ... update-initramfs: deferring update (trigger activated) INFO:Enable nvidia DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/lenovo_thinkpad DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/dell_latitude DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/put_your_quirks_here Removing old nvidia-470.161.03 DKMS files... Deleting module nvidia-470.161.03 completely from the DKMS tree. Loading new nvidia-470.161.03 DKMS files... Building for 5.15.0-60-generic Building for architecture x86_64 Building initial module for 5.15.0-60-generic ERROR: Cannot create report: [Errno 17] File exists: '/var/crash/nvidia-kernel-source-470.0.crash' Error! Bad return status for module build on kernel: 5.15.0-60-generic (x86_64) Consult /var/lib/dkms/nvidia/470.161.03/build/make.log for more information.
/var/lib/dkms/nvidia/470.161.03/build/make.log中的核心错误:
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:750: include/config/auto.conf] Error 1 make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-60-generic' make: *** [Makefile:80: modules] Error 2
解决方案
针对这个问题,我们可以通过修复内核头文件配置、清理损坏的DKMS模块、重新安装适配的NVIDIA驱动来解决,步骤如下:
- 清理重复的崩溃报告
先删除已存在的崩溃文件,避免后续报错被干扰:
sudo rm /var/crash/nvidia-kernel-source-470.0.crash
- 移除损坏的NVIDIA DKMS模块
强制清除当前DKMS中损坏的NVIDIA驱动模块,为重新安装扫清障碍:
sudo dkms remove nvidia/470.161.03 --all
- 修复内核头文件配置
虽然你已经安装了对应内核的头文件,但配置文件可能未正确生成,我们重新安装并手动生成配置:
# 重新安装内核相关包,确保文件完整性 sudo apt reinstall linux-headers-$(uname -r) linux-image-$(uname -r) linux-generic # 更新系统模块依赖 sudo depmod -a # 进入内核头文件目录生成配置文件 cd /usr/src/linux-headers-$(uname -r) sudo make oldconfig sudo make prepare
执行make oldconfig时如果出现配置选项提示,直接按回车选择默认值即可。
- 修复dpkg依赖并重新配置驱动
先尝试让dpkg自动修复依赖问题:
sudo dpkg --configure -a
如果上述命令仍然失败,彻底卸载现有NVIDIA驱动后重新安装系统推荐版本:
# 彻底清除所有NVIDIA相关包 sudo apt purge nvidia-dkms-470 nvidia-driver-470 nvidia-driver-460 nvidia-kernel-source-470 sudo apt autoremove --purge sudo apt clean # 安装系统适配的NVIDIA驱动 sudo ubuntu-drivers autoinstall
- 重启系统并验证修复结果
完成上述步骤后重启系统:
sudo reboot
重启后执行以下命令验证:
nvidia-smi:如果能正常显示GPU信息,说明驱动安装成功sudo apt update && sudo apt upgrade:检查是否还会出现之前的更新错误
备注:内容来源于stack exchange,提问作者retrodans




