我无法在 Ubuntu 22.04 上安装 Nvidia 驱动程序。以前,我有可用的 Nvidia 驱动程序和 CUDA 安装。但是,要安装 pyTorch 等 Python 库,我不得不多次卸载并安装 CUDA。同时,我还必须将我的 gcc 从 11.3 降级到 9,因为其中一些库与更高版本不兼容。现在的问题是,当我尝试安装 Nvidia 驱动程序(最新或推荐)时,内核出现了一些问题。它说我的内核是使用 gcc 版本 11.3 编译的,但你正尝试使用 gcc 9.5 进行构建。
生成日志:
$cat /var/lib/dkms/nvidia/470.182.03/build/make.log
DKMS make.log for nvidia-470.182.03 for kernel 5.15.0-69-generic (x86_64)
Do 27. Apr 12:11:09 IST 2023
make[1]: Entering directory '/usr/src/linux-headers-5.15.0-69-generic'
test -e include/generated/autoconf.h -a -e include/config/auto.conf || ( \
echo >&2; \
echo >&2 " ERROR: Kernel configuration is invalid."; \
echo >&2 " include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
echo >&2 ; \
/bin/false)
warning: the compiler differs from the one used to build the kernel
The kernel was built by: gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
You are using: gcc (Ubuntu 9.5.0-1ubuntu1~22.04) 9.5.0
make -f ./scripts/Makefile.build obj=/var/lib/dkms/nvidia/470.182.03/build \
single-build= \
need-builtin=1 need-modorder=1
ln -sf /var/lib/dkms/nvidia/470.182.03/build/nvidia/nv-kernel.o_binary /var/lib/dkms/nvidia/470.182.03/build/nvidia/nv-kernel.o
ln -sf /var/lib/dkms/nvidia/470.182.03/build/nvidia-modeset/nv-modeset-kernel.o_binary /var/lib/dkms/nvidia/470.182.03/build/nvidia-modeset/nv-modeset-kernel.o
CONFTEST: hash__remap_4k_pfn
.
.
.
gcc: error: unrecognized command line option ‘-mharden-sls=all’
make[2]: *** [scripts/Makefile.build:297: /var/lib/dkms/nvidia/470.182.03/build/nvidia/nv.o] Error 1
make[2]: *** Waiting for unfinished jobs....
gcc: error: unrecognized command line option ‘-mharden-sls=all’
make[2]: *** [scripts/Makefile.build:297: /var/lib/dkms/nvidia/470.182.03/build/nvidia/nv-pci.o] Error 1
gcc: error: unrecognized command line option ‘-mharden-sls=all’
make[2]: *** [scripts/Makefile.build:297: /var/lib/dkms/nvidia/470.182.03/build/nvidia/nv-acpi.o] Error 1
make[1]: *** [Makefile:1906: /var/lib/dkms/nvidia/470.182.03/build] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-69-generic'
make: *** [Makefile:80: modules] Error 2
当我尝试使用升级 gcc 时sudo apt install gcc
出现以下错误:
ERROR: Cannot create report: [Errno 17] File exists: '/var/crash/nvidia-kernel-s
ource-470.0.crash'
Error! Bad return status for module build on kernel: 5.15.0-69-generic (x86_64)
Consult /var/lib/dkms/nvidia/470.182.03/build/make.log for more information.
dpkg: error processing package nvidia-dkms-470 (--configure):
installed nvidia-dkms-470 package post-installation script subprocess returned
error exit status 10
dpkg: dependency problems prevent configuration of nvidia-driver-470:
nvidia-driver-470 depends on nvidia-dkms-470 (<= 470.182.03-1); however:
Package nvidia-dkms-470 is not configured yet.
nvidia-driver-470 depends on nvidia-dkms-470 (>= 470.182.03); however:
Package nvidia-dkms-470 is not configured yet.
dpkg: error processing package nvidia-driver-470 (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup erro
r from a previous failure.
Processing triggers for initramfs-tools (0.140ubuntu13
.1) ...
update-initramfs: Generating /boot/initrd.img-5.15.0-71-generic
Errors were encountered while processing:
nvidia-dkms-470
nvidia-driver-470
E: Sub-process /usr/bin/dpkg returned an error code (1)