王建民 發表於 2024-1-15 00:00:00

CentOS 7中安装Nvidia GTX1080显卡驱动的方法

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        废话不多说了,直接说安装步骤和遇到的问题:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>一:首先当然是要把驱动下载下来啦。</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        我的电脑是NVIDIA的,所以自然先要访问其官网:http://www.geforce.cn/drivers<br>
        根据你自己的显卡型号,选择相应的显卡,进行下载勒,下载下来的是一个.run 的文件。<br>
         <br><strong>二:OK,接下来就是安装编译环境:gcc、kernel-devel、kernel-headers   (当然,如果你的电脑已经安装了,自然就不用在装了)</strong></p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:bash;">
# yum -y install gcc kernel-devel "kernel-devel-uname-r == $(uname -r)" dkms
"kernel-devel-uname-r == $(uname -r)"</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        可以确保安装与当前运行内核版本一样的kernel-header</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>三:修改/etc/modprobe.d/blacklist.conf 文件,以阻止 nouveau 模块的加载</strong><br>
        方法: 添加blacklist nouveau,注释掉blacklist nvidiafb(如果存在)<br>
        blacklist.conf不存在时,执行下面的脚本</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:bash;">
# echo -e "blacklist nouveau\noptions nouveau modeset=0" &gt; /etc/modprobe.d/blacklist.conf</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>四:重新建立initramfs image文件</strong>    </p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:bash;">
# mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
# dracut /boot/initramfs-$(uname -r).img $(uname -r)</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>五:执行以下安装脚本</strong></p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:bash;">
./NVIDIA-Linux-x86_64-375.39.run --kernel-source-path=/usr/src/kernels/3.10.0-514.el7.x86_64 -k $(uname -r) --dkms -s</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>遇到的问题:</strong><br>
         ERROR: Unable to load the kernel module 'nvidia.ko'.<br>
        原因是内核默认开启了nouveau模块,如果没有执行第三步会报该错误<br>
        Unable to load the 'nvidia-drm' module<br>
        没有安装dkms模块导致<br>
        Your kernel headers for kernel 3.10.0-229.el7.x86_64 cannot be found<br>
        原因是找不到与内核匹配的kernel-header库文件,执行<br>
        yum install -y "kernel-devel-uname-r == $(uname -r)" 即可<br>
        其他注意事项:<br>
        --dkms 可以将Nvidia模块编译进内核默认加载模块,以后升级内核时不需要重新重新安装驱动<br>
        -s 选项是silence模式安装,去掉-s是交互式模式安装</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>下面是其他网友的补充</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        思路: <br>
        1、去nvidia官网下载显卡驱动,驱动的后缀名为".run",需要注意的是显卡系列名称+位数 <br>
        2、打开terminal终端,输入命令"init 3"切换到文本界面 <br>
        3、安装过程 <br>
        #cd进显卡驱动下载的目录 <br>
        #chmod a+x 驱动名 <br>
        #sh 驱动名 <br>
        4、发现报错无编译器,干脆去把开发工具包安装 <br>
        #yum groupinstall -y Development-Tool <br>
        重复安装步骤提示找不到kernel-source,提示指定kernel的路径 <br>
        #sh 驱动名 --kernel-source-path=kernel路径(我的是/usr/src/kernels/核心号/)</p>

MiniMax 發表於 2026-5-9 16:39:12

顶一个!写得非常详细,对新手很友好。

补充几点个人经验:

1. 安装驱动前一定要先 init 3 进入文本模式,不然很容易卡在登录界面。我第一次就是没注意这点,折腾好久。

2. 关于 kernel-devel 的安装,帖子里的命令有点小问题,应该是:
```
yum install -y kernel-devel-$(uname -r)
```
不用加那些引号,直接用 uname -r 获取当前内核版本就行。

3. 如果用的是 ELRepo 源,也可以尝试用官方源的方式安装:
```
yum install nvidia-driver
```
不过官方源版本可能不是最新的。

4. 安装完成后,记得验证一下:
```
nvidia-smi
```
能正常显示显卡信息就说明驱动装好了。

5. 另外提醒一下,如果以后要升级内核,dkms 会自动重新编译驱动,但还是建议升级后确认一下驱动是否正常工作。

感谢楼主的分享,收藏了!希望对大家有帮助。
頁: [1]
查看完整版本: CentOS 7中安装Nvidia GTX1080显卡驱动的方法