我有一台联想 Z70-80,并将 Ubuntu 从 v20.04 升级到 v22.04。
升级时,系统显示正在下载最新的 nvidia-drivers-525,但无法安装。请注意,我有
产品:GM108M [GeForce 840M] 供应商:NVIDIA Corporation
每当我尝试使用以下命令安装驱动程序时:
sudo apt install nvidia-driver-525 nvidia-dkms-525
它引发了以下错误:
user@Lenovo-Z70-80:~$ sudo apt install nvidia-driver-525 nvidia-dkms-525
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
nvidia-dkms-525 is already the newest version (525.60.11-0ubuntu0.22.04.1).
nvidia-driver-525 is already the newest version (525.60.11-0ubuntu0.22.04.1).
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up nvidia-dkms-525 (525.60.11-0ubuntu0.22.04.1) ...
update-initramfs: deferring update (trigger activated)
INFO:Enable nvidia
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/dell_latitude
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/put_your_quirks_here
DEBUG:Parsing /usr/share/ubuntu-drivers-common/quirks/lenovo_thinkpad
Removing old nvidia-525.60.11 DKMS files...
Deleting module nvidia-525.60.11 completely from the DKMS tree.
Loading new nvidia-525.60.11 DKMS files...
Building for 5.15.0-56-generic
Building for architecture x86_64
Building initial module for 5.15.0-56-generic
ERROR: Cannot create report: [Errno 17] File exists: '/var/crash/nvidia-kernel-source-525.0.crash'
Error! Bad return status for module build on kernel: 5.15.0-56-generic (x86_64)
Consult /var/lib/dkms/nvidia/525.60.11/build/make.log for more information.
dpkg: error processing package nvidia-dkms-525 (--configure):
installed nvidia-dkms-525 package post-installation script subprocess returned error exit status 10
dpkg: dependency problems prevent configuration of nvidia-driver-525:
nvidia-driver-525 depends on nvidia-dkms-525 (<= 525.60.11-1); however:
Package nvidia-dkms-525 is not configured yet.
nvidia-driver-525 depends on nvidia-dkms-525 (>= 525.60.11); however:
Package nvidia-dkms-525 is not configured yet.
dpkg: error processing package nvidia-driver-525 (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Processing triggers for initramfs-tools (0.140ubuntu13.1) ...
update-initramfs: Generating /boot/initrd.img-5.15.0-56-generic
I: The initramfs will attempt to resume from /dev/sda9
I: (UUID=b839824a-2800-4868-b38c-064d54ed0eb9)
I: Set the RESUME variable to override this.
Errors were encountered while processing:
nvidia-dkms-525
nvidia-driver-525
E: Sub-process /usr/bin/dpkg returned an error code (1)
命令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.
谁能告诉我还能做些什么来安装最新的驱动程序并使其正常工作?
谢谢。
答案1
就我而言,问题出在错误的 GCC 编译器版本上。以下是我发现的方法:
从以下位置下载安装程序https://www.nvidia.com/Download/index.aspx?lang=en-us
运行安装程序
当安装程序失败时,它会在 /var/log/nvidia-installer.log 下创建一个日志。阅读日志会发现错误:
warning: the compiler differs from the one used to build the kernel The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.2.0-3ubuntu1) 12.2.0 You are using: cc (Ubuntu 10.4.0-5ubuntu2) 10.4.0 Warning: Compiler version check failed: The major and minor number of the compiler used to compile the kernel: x86_64-linux-gnu-gcc-12 (Ubuntu 12.2.0-3ubuntu1) 12.2.0, GNU ld (GNU Binutils for Ubuntu) 2.39 does not match the compiler used here: cc (Ubuntu 10.4.0-5ubuntu2) 10.4.0 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is recommended to set the CC environment variable to the compiler that was used to compile the kernel.
根据错误,在我的系统配置中将 GCC 版本更改回 12 并运行以下命令:
sudo apt install nvidia-driver-525
导致安装成功。
答案2
删除所有 nvidia 包...然后更新内核...
sudo update-initramfs -u
重启...
再次安装驱动程序:
sudo apt install nvidia-driver-525
(不要添加任何其他东西)
之后它应该可以正常工作了...请特别注意 initramfs 是否已构建并完成。如果没有,您必须再次手动重建它,否则机器可能无法启动。
答案3
sudo mv /var/lib/dpkg/info/nvidia-dkms-535* /tmp
sudo dpkg --configure -a
对我有用。