在 Debian 12 上安装 Nvidia 显卡驱动程序

原创 2024年 9月 5日
标签: LINUX

系列: Debian 12 装系统

先打个广告:欢迎关注我的公众号,参与 文史大挑战 趣味题目。使用方法见 这篇文章

公众号:晚花行乐

正文开始:

最近新安装了一套 Debian 12,下面记录安装 Nvidia 显卡驱动的过程。

检测显卡硬件

执行下列命令

# lspci

得到类似下列结果:

# lspci

...
07:00.0 VGA compatible controller: NVIDIA Corporation GK208B [GeForce GT 730] (rev a1)
07:00.1 Audio device: NVIDIA Corporation GK208 HDMI/DP Audio Controller (rev a1)

如果能看到上面两行,说明操作系统已经检测到硬件。可以继续安装驱动程序。

检测显卡驱动版本

这块旧显卡是 Nvidia Geforce GT730,不知道它对应的驱动版本是多少,有两种方法可以查询驱动的版本:

方法1:使用 nvidia-detect

我没有尝试这种方法,仅 转载 来源: https://wiki.debian.org/NvidiaGraphicsDrivers#nvidia-detect 这里供参考。执行命令:

# apt -y install nvidia-detect

输出结果的示例:

$ nvidia-detect
Detected NVIDIA GPUs:
07:00.0 VGA compatible controller [0300]: NVIDIA Corporation GM206 [GeForce GTX 960] [10de:1401] (rev a1)

Checking card:  NVIDIA Corporation GM206 [GeForce GTX 960] (rev a1)
Your card is supported by all driver versions.
Your card is also supported by the Tesla 440 drivers series.
Your card is also supported by the Tesla 418 drivers series.
It is recommended to install the
    nvidia-driver
package.

上面的示例是较新的显卡,如果是旧型号(比如上面我用的 GT730),就不能用例子中的 nvidia-driver ,而要根据 nvidia-detect 运行实际给出的结果。

方法2:到 Nvidia 网站上寻找

网站链接:(https://www.nvidia.cn/drivers/lookup/),在页面表单上输入具体的型号,然后由网页待到下载界面。

点击“查看”按钮

点击下载链接

得到名为类似 NVIDIA-Linux-x86_64-470.256.02.run 的文件。

安装必要的组件

为了顺利安装驱动程序,需要安装一些必要的组件,执行下面的命令:

# apt -y install linux-headers-$(uname -r) build-essential libglvnd-dev pkg-config

为了防止无意升级内核造成驱动不能用,要先禁止: 内核更新 来源: https://blog.csdn.net/CanvaChen/article/details/131254870

# dpkg --get-selections | grep linux-(image|headers)

将结果里的 linux-imagelinux-headers 固定版本,例如:

# apt-mark hold linux-image-6.1.0-25-amd64 linux-headers-6.1.0-25-amd64 linux-headers-6.1.0-25-common

得到如下的结果说明版本已经 hold:

linux-image-6.1.0-25-amd64 set on hold.
linux-headers-6.1.0-25-amd64 set on hold.
linux-headers-6.1.0-25-common set on hold.

运行驱动程序

找到驱动程序所在的目录,赋予执行权限:

# chmod u+x NVIDIA-Linux-x86_64-470.256.02.run

接下来就可以运行驱动程序了:

# ./NVIDIA-Linux-x86_64-470.256.02.run

提示当前使用的是 Nouveau 驱动,不能与即将安装的 Nvidia 共存,需要预先禁用。 Nouveau 驱动的说明参考 这篇文章

选择 OK 后,程序会询问你是否希望由程序来将 Nouveau 驱动列入黑名单,这里选择 Yes ,就不需要自己手动操作了。

提示已经成功将 Nouveau 驱动加入黑名单,需要重启后再次运行安装程序。

在下面几个命令中任意选择一个重启,可能有些命令因为 $PATH 没有配置,导致提示命令不存在。如果遇到了,就按顺序逐个尝试。

# init 6
或
# reboot
或
# systemctl reboot
或
# shutdown -r now

因为这时并没有开始安装驱动,所以关机仍会碰到 Failed to finalize DM devices, ignoring 的错误提示

同时服务器前面板上的红灯闪烁。

重启后再次安装驱动

重启服务器后,再次运行驱动程序:

# ./NVIDIA-Linux-x86_64-470.256.02.run

进入编译界面

这个界面等待2分钟左右,进入下一步提示:

按回车进入下一步:

提示不安装32位程序了,按回车确认进入下一步:

安装进度条,持续1分钟以内:

选择 Yes 后按回车确认:

提示驱动程序安装完成。

执行 nvidia-smi 确认驱动安装完毕:

这时还没有安装 CUDA,下一篇将介绍。

如果您对本文有疑问或者寻求合作,欢迎 联系邮箱邮箱已到剪贴板

标签: LINUX

系列: Debian 12 装系统

给个免费的赞吧~

精彩评论

本站 是个人网站,采用 署名协议 CC-BY-NC 授权。
欢迎转载,请保留原文链接 https://www.lfhacks.com/tech/debian-nvidia-driver/ ,且不得用于商业用途。