安装N卡驱动时出现问题

在安装N卡驱动时出现报错:ERROR: Unable to find the kernel source tree for the currently running kernel. Please make sure you have installed the kernel source files for your kernel and that they are properly configured; on Red Hat Linux systems, for example, be sure you have the 'kernel-source' or 'kernel-devel' RPM installed. If you know the correct kernel source files are installed, you may specify the kernel source path with the '--kernel-source-path' command line option. ,然后我按照网上说的安装linux-kernel,结果:

brandon@debian:~/Downloads$ uname -r
6.1.0-13-amd64
brandon@debian:~/Downloads$ sudo apt install linux-headers-$(uname -r)
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
E: 无法定位软件包 linux-headers-6.1.0-13-amd64
E: 无法按照 glob ‘linux-headers-6.1.0-13-amd64’ 找到任何软件包
brandon@debian:~/Downloads$ 

然后我看了下我的安装源有的linux-headers:

brandon@debian:~/Downloads$ apt install linux-headers-
linux-headers-6.1.0-11-686                 linux-headers-6.1.0-12-686-pae             linux-headers-6.1.0-15-amd64               linux-headers-6.1.0-16-cloud-amd64         linux-headers-6.1.0-17-common              linux-headers-6.1.0-18-common-rt           linux-headers-6.6.13+bpo-686-pae           linux-headers-rt-686-pae
linux-headers-6.1.0-11-686-pae             linux-headers-6.1.0-12-amd64               linux-headers-6.1.0-15-cloud-amd64         linux-headers-6.1.0-16-common              linux-headers-6.1.0-17-common-rt           linux-headers-6.1.0-18-rt-686-pae          linux-headers-6.6.13+bpo-amd64             linux-headers-rt-amd64
linux-headers-6.1.0-11-amd64               linux-headers-6.1.0-12-cloud-amd64         linux-headers-6.1.0-15-common              linux-headers-6.1.0-16-common-rt           linux-headers-6.1.0-17-rt-686-pae          linux-headers-6.1.0-18-rt-amd64            linux-headers-6.6.13+bpo-cloud-amd64       
linux-headers-6.1.0-11-cloud-amd64         linux-headers-6.1.0-12-common              linux-headers-6.1.0-15-common-rt           linux-headers-6.1.0-16-rt-686-pae          linux-headers-6.1.0-17-rt-amd64            linux-headers-6.5.0-0.deb12.4-686          linux-headers-6.6.13+bpo-common            
linux-headers-6.1.0-11-common              linux-headers-6.1.0-12-common-rt           linux-headers-6.1.0-15-rt-686-pae          linux-headers-6.1.0-16-rt-amd64            linux-headers-6.1.0-18-686                 linux-headers-6.5.0-0.deb12.4-686-pae      linux-headers-6.6.13+bpo-common-rt         
linux-headers-6.1.0-11-common-rt           linux-headers-6.1.0-12-rt-686-pae          linux-headers-6.1.0-15-rt-amd64            linux-headers-6.1.0-17-686                 linux-headers-6.1.0-18-686-pae             linux-headers-6.5.0-0.deb12.4-amd64        linux-headers-6.6.13+bpo-rt-686-pae        
linux-headers-6.1.0-11-rt-686-pae          linux-headers-6.1.0-12-rt-amd64            linux-headers-6.1.0-16-686                 linux-headers-6.1.0-17-686-pae             linux-headers-6.1.0-18-amd64               linux-headers-6.5.0-0.deb12.4-cloud-amd64  linux-headers-6.6.13+bpo-rt-amd64          
linux-headers-6.1.0-11-rt-amd64            linux-headers-6.1.0-15-686                 linux-headers-6.1.0-16-686-pae             linux-headers-6.1.0-17-amd64               linux-headers-6.1.0-18-cloud-amd64         linux-headers-6.5.0-0.deb12.4-common       linux-headers-amd64                        
linux-headers-6.1.0-12-686                 linux-headers-6.1.0-15-686-pae             linux-headers-6.1.0-16-amd64               linux-headers-6.1.0-17-cloud-amd64         linux-headers-6.1.0-18-common              linux-headers-6.6.13+bpo-686               linux-headers-cloud-amd64                  

并没有我想要的header
这种问题应该如何解决?
附加信息:
现在用的软件源

#from 'https://mirrors.tuna.tsinghua.edu.cn/help/debian/'
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware

deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware

#from 'https://wiki.debian.org/SourcesList'
deb http://deb.debian.org/debian bookworm main non-free-firmware
deb-src http://deb.debian.org/debian bookworm main non-free-firmware

deb http://deb.debian.org/debian-security/ bookworm-security main non-free-firmware
deb-src http://deb.debian.org/debian-security/ bookworm-security main non-free-firmware

deb http://deb.debian.org/debian bookworm-updates main non-free-firmware
deb-src http://deb.debian.org/debian bookworm-updates main non-free-firmware
brandon@debian:~/Downloads$ lspci
0000:00:00.0 Host bridge: Intel Corporation Device a702 (rev 01)
0000:00:01.0 PCI bridge: Intel Corporation Device a70d (rev 01)
0000:00:02.0 VGA compatible controller: Intel Corporation Raptor Lake-S UHD Graphics (rev 04)
0000:00:04.0 Signal processing controller: Intel Corporation Raptor Lake Dynamic Platform and Thermal Framework Processor Participant (rev 01)
0000:00:08.0 System peripheral: Intel Corporation GNA Scoring Accelerator module (rev 01)
0000:00:0e.0 RAID bus controller: Intel Corporation Volume Management Device NVMe RAID Controller Intel Corporation
0000:00:14.0 USB controller: Intel Corporation Device 7a60 (rev 11)
0000:00:14.2 RAM memory: Intel Corporation Device 7a27 (rev 11)
0000:00:14.3 Network controller: Intel Corporation Device 7a70 (rev 11)
0000:00:15.0 Serial bus controller: Intel Corporation Device 7a4c (rev 11)
0000:00:15.1 Serial bus controller: Intel Corporation Device 7a4d (rev 11)
0000:00:16.0 Communication controller: Intel Corporation Device 7a68 (rev 11)
0000:00:1a.0 PCI bridge: Intel Corporation Device 7a48 (rev 11)
0000:00:1c.0 PCI bridge: Intel Corporation Device 7a3d (rev 11)
0000:00:1f.0 ISA bridge: Intel Corporation Device 7a0c (rev 11)
0000:00:1f.3 Audio device: Intel Corporation Device 7a50 (rev 11)
0000:00:1f.4 SMBus: Intel Corporation Device 7a23 (rev 11)
0000:00:1f.5 Serial bus controller: Intel Corporation Device 7a24 (rev 11)
0000:01:00.0 VGA compatible controller: NVIDIA Corporation AD107M [GeForce RTX 4060 Max-Q / Mobile] (rev a1)
0000:01:00.1 Audio device: NVIDIA Corporation Device 22be (rev a1)
0000:02:00.0 PCI bridge: Intel Corporation Device 1133 (rev 02)
0000:03:00.0 PCI bridge: Intel Corporation Device 1133 (rev 02)
0000:03:01.0 PCI bridge: Intel Corporation Device 1133 (rev 02)
0000:03:02.0 PCI bridge: Intel Corporation Device 1133 (rev 02)
0000:03:03.0 PCI bridge: Intel Corporation Device 1133 (rev 02)
0000:04:00.0 USB controller: Intel Corporation Device 1134
0000:38:00.0 USB controller: Intel Corporation Device 1135
0000:6c:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 15)
10000:e0:1b.0 System peripheral: Intel Corporation RST VMD Managed Controller
10000:e0:1b.4 PCI bridge: Intel Corporation Device 7a44 (rev 11)
10000:e1:00.0 Non-Volatile memory controller: Sandisk Corp WD Black SN770 NVMe SSD (rev 01)

你更新到有 headers 的版本的内核呀。

怎么更新内核啊?

已经没有6.1.0-13的headers了,debian已经没有那个包了,但各镜像源还有,手动下载headers,和headers-common,还有linux-kbuid6.1,就可以安装。
但是,重要的来了,nvidia新出驱动470.229.06支持新内核,你的系统新内核是6.1.0-15,有image和headers,不稳定版也支持。

我下载了个 linux-6.7.9.tar.gz 文件包,准备跟着 8.10. 编译内核 教程走,这么做对吗?

完全错误。

如果你没有特殊需求,如果你是 debian12,应当更新到 debian12 的最新版本内核且安装 nvidia-driver 包即可。如果你要用最新版本内核,应当使用 backport,不过这样需要你有能力解决可能会出现的问题。

编辑:

我猜你没有更新系统?

最近刚装的

brandon@debian:~$ uname -a
Linux debian 6.1.0-13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.55-1 (2023-09-29) x86_64 GNU/Linux

操作系统名称

Debian GNU/Linux 12 (bookworm)

最新版是 6.1.0-18(截止到 2024 年 3 月 7 日),你差了 5 个版本。

可以贴一下你的 /etc/apt/sources.list 吗?

我刚才下载了个nvidia-driver

brandon@debian:~$ dpkg -l nvidia-driver*
期望状态=未知(u)/安装(i)/删除(r)/清除(p)/保持(h)
| 状态=未安装(n)/已安装(i)/仅存配置(c)/仅解压缩(U)/配置失败(F)/不完全安装(H)/触发器等待(W)/触发器未决(T)
|/ 错误?=(无)/须重装(R) (状态,错误:大写=故障)
||/ 名称                         版本                 体系结构     描述
+++-============================-====================-============-==================================================
ii  nvidia-driver                525.147.05-7~deb12u1 amd64        NVIDIA metapackage
un  nvidia-driver-any            <无>                 <无>         (无描述)
ii  nvidia-driver-bin            525.147.05-7~deb12u1 amd64        NVIDIA driver support binaries
un  nvidia-driver-bin-470.223.02 <无>                 <无>         (无描述)
un  nvidia-driver-bin-525.147.05 <无>                 <无>         (无描述)
un  nvidia-driver-binary         <无>                 <无>         (无描述)
ii  nvidia-driver-libs:amd64     525.147.05-7~deb12u1 amd64        NVIDIA metapackage (OpenGL/GLX/EGL/GLES libraries)
ii  nvidia-driver-libs:i386      525.147.05-7~deb12u1 i386         NVIDIA metapackage (OpenGL/GLX/EGL/GLES libraries)
un  nvidia-driver-libs-any       <无>                 <无>         (无描述)
un  nvidia-driver-libs-nonglvnd  <无>                 <无>         (无描述)

软件好像还是识别不到

我上面给到了

#from 'https://mirrors.tuna.tsinghua.edu.cn/help/debian/'
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware

deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware

#from 'https://wiki.debian.org/SourcesList'
deb http://deb.debian.org/debian bookworm main non-free-firmware
deb-src http://deb.debian.org/debian bookworm main non-free-firmware

deb http://deb.debian.org/debian-security/ bookworm-security main non-free-firmware
deb-src http://deb.debian.org/debian-security/ bookworm-security main non-free-firmware

deb http://deb.debian.org/debian bookworm-updates main non-free-firmware
deb-src http://deb.debian.org/debian bookworm-updates main non-free-firmware

抱歉,没注意到…

nvidia-smi 输出是什么?看上去你的显卡应该正常工作了?

题外话,如果你之前尝试安装过英伟达的 *.run 驱动,你可能需要清理干净才行。

brandon@debian:~$ 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.

如果我没理解错的话它应该是没有识别到我的显卡

我之前装过,后来报错就直接退了,感觉什么都没装上

也许你应该试试 sudo apt update && sudo apt upgrade 更新系统…然后把完整输出贴一下。

另外,文明 6 的 steam 分发有 linux 原生版本,不过那个版本略低。如果要用 windows 版本可能需要参考 protondb 的提示,比如跳过启动器什么的。

已经是最新了

brandon@debian:~$ sudo apt update && sudo apt upgrade
[sudo] brandon 的密码:
命中:1 https://mirrors.tuna.tsinghua.edu.cn/debian bookworm InRelease
命中:2 https://mirrors.tuna.tsinghua.edu.cn/debian bookworm-updates InRelease  
命中:3 https://mirrors.tuna.tsinghua.edu.cn/debian bookworm-backports InRelease
命中:4 http://deb.debian.org/debian bookworm InRelease                         
命中:5 http://deb.debian.org/debian-security bookworm-security InRelease       
命中:6 http://deb.debian.org/debian bookworm-updates InRelease                 
命中:7 https://repo.steampowered.com/steam stable InRelease                    
命中:8 https://security.debian.org/debian-security bookworm-security InRelease
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
所有软件包均为最新。
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
正在计算更新... 完成
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。

如果你有 apt-mark,贴一下 apt-mark showmanual 输出?看看你具体都装了什么包。还有 dkms status 的输出

brandon@debian:~$ apt-mark showmanual
adduser
apt
apt-listchanges
apt-utils
base-files
base-passwd
bash
bash-completion
bind9-dnsutils
bind9-host
bsdutils
busybox
bzip2
ca-certificates
cmake
com.alibabainc.dingtalk
console-setup
coreutils
cpio
cron
cron-daemon-common
dash
dbus
debconf
debconf-i18n
debian-archive-keyring
debian-faq
debianutils
diffutils
discover
dmidecode
dmsetup
dnf
doc-debian
dosfstools
dpkg
dpkg-dev
e2fsprogs
fcitx5-pinyin
fdisk
file
findutils
firmware-iwlwifi
firmware-misc-nonfree
firmware-realtek
firmware-sof-signed
gcc
gcc-12-base
gdebi-core
gettext-base
git
gnupg
gpgv
grep
groff-base
grub-common
grub-efi-amd64
gzip
hostname
ifupdown
inetutils-telnet
init
init-system-helpers
initramfs-tools
installation-report
intel-microcode
iproute2
iputils-ping
isc-dhcp-client
isc-dhcp-common
iw
kdeconnect
keyboard-configuration
kmod
krb5-locales
laptop-detect
less
libacl1
libapparmor1
libapt-pkg6.0
libargon2-1
libattr1
libaudit-common
libaudit1
libblkid1
libbpf1
libbsd0
libbz2-1.0
libc-bin
libc6
libc6-i386
libc6:i386
libcap-ng0
libcap2
libcap2-bin
libcom-err2
libcrypt1
libcryptsetup12
libdb5.3
libdebconfclient0
libdevmapper1.02.1
libedit2
libegl1
libegl1:i386
libelf1
libext2fs2
libfdisk1
libffi8
libgbm1
libgbm1:i386
libgcc-s1
libgcrypt20
libgl1
libgl1-mesa-dri
libgl1-mesa-dri:i386
libgl1:i386
libgmp10
libgnutls30
libgpg-error0
libgssapi-krb5-2
libhogweed6
libidn2-0
libip4tc2
libjansson4
libjson-c5
libk5crypto3
libkeyutils1
libkmod2
libkrb5-3
libkrb5support0
liblocale-gettext-perl
liblockfile-bin
liblz4-1
liblzma5
libmd0
libmnl0
libmount1
libncursesw6
libnettle8
libnewt0.52
libnftables1
libnftnl11
libnss-systemd
libnss3-tools
libp11-kit0
libpam-modules
libpam-modules-bin
libpam-runtime
libpam-systemd
libpam0g
libpcre2-8-0
libpopt0
libproc2-0
libreadline8
libseccomp2
libselinux1
libsemanage-common
libsemanage2
libsepol2
libslang2
libsmartcols1
libss2
libssl3
libstdc++6
libsystemd-shared
libsystemd0
libtasn1-6
libtext-charwidth-perl
libtext-iconv-perl
libtext-wrapi18n-perl
libtinfo6
libtirpc-common
libtirpc3
libudev1
libunistring2
libuuid1
libxtables12
libxxhash0
libzstd1
locales
login
logrotate
logsave
lsof
make
man-db
manpages
mawk
media-types
mime-support
mount
musicfree
nano
ncurses-base
ncurses-bin
ncurses-term
netbase
netcat-traditional
nftables
nmap
npm
nvidia-driver
nvidia-driver-bin
nvidia-driver-libs
nvidia-tesla-470-driver-bin
onlyoffice-desktopeditors
onlyoffice-desktopeditors-help
openjdk-17-jdk
openssh-client
os-prober
passwd
pciutils
perl
perl-base
procps
python3-pip
python3-reportbug
qalculate-gtk
qbittorrent
qtcreator
qtqr
readline-common
reportbug
sed
sensible-utils
shim-signed
steam-launcher
steam-libs-amd64
steam-libs-i386:i386
steam:i386
sunloginclient
systemd
systemd-sysv
systemd-timesyncd
sysvinit-utils
tar
task-chinese-s
task-chinese-s-desktop
task-chinese-s-gnome-desktop
task-desktop
task-gnome-desktop
task-laptop
tasksel
tasksel-data
traceroute
tree
tzdata
ucf
udev
usbutils
usr-is-merged
util-linux
util-linux-extra
v2ray
v2raya
vim-common
vim-tiny
vlc
w3m
wamerican
wget
whiptail
wine
wine32:i386
wine64
wireless-tools
wireshark
wpasupplicant
xz-utils
zip
zlib1g
zstd
brandon@debian:~$ sudo apt install dkms
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
dkms 已经是最新版 (3.0.10-8+deb12u1)。
dkms 已设置为手动安装。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
brandon@debian:~$ dkms status
bash: dkms: 未找到命令
brandon@debian:~$ 

sudo dkms status

抱一丝

brandon@debian:~$ sudo dkms status
nvidia-current/525.147.05: added
nvidia-tesla-470/470.223.02: added