侧边栏壁纸
博主头像
qiql博主等级

水能载舟,亦可赛艇

  • 累计撰写 33 篇文章
  • 累计创建 28 个标签
  • 累计收到 4 条评论

目 录CONTENT

文章目录

最小化 CentOS7.9 操作系统上安装 NVIDIA GPU 驱动

qiql
2023-06-07 / 0 评论 / 1 点赞 / 755 阅读 / 848 字

零 概述

本文介绍如何在一台刚刚安装完CentOS7.9操作系统(最小化安装)的机器上安装 NVIDIA GPU 驱动,同时安装CUDA 11.8

一 检查是否有卡

lspci | grep -i nvidia

image-20230524142642501

如果没有 lspci 这个命令,需要执行:

yum whatprovides */lspci
yum -y install pciutils

进入/opt目录新建support目录,笔者习惯将文件都放在/opt/support 目录下

cd /opt/support
mkdir pkgs
mkdir soft
mkdir bench
cd pkgs
yum -y install wget
yum -y install vim

二 检查自带驱动是否被禁用

lsmod | grep nouveau

image-20230524142412191

如果有输出,说明没有被禁用,如果不禁用此驱动,会报错:

-> For some distributions, Nouveau can be disabled by adding a file in the modprobe configuration directory.  Would you like nvidia-installer to attempt to create this modprobe file for you? (Answer: Yes)
-> One or more modprobe configuration files to disable Nouveau have been written.  For some distributions, this may be sufficient to disable Nouveau; other distributions may require modification of the initial ramdisk.  Please reboot your system and attempt NVIDIA driver installation again.  Note if you later wish to re-enable Nouveau, you will need to delete these files: /usr/lib/modprobe.d/nvidia-installer-disable-nouveau.conf, /etc/modprobe.d/nvidia-installer-disable-nouveau.conf

image-20230524142016185

按照以下方式禁用该驱动:

#新建一个配置文件
sudo vim /etc/modprobe.d/blacklist-nouveau.conf
#写入以下内容
blacklist nouveau
options nouveau modeset=0
#保存并退出
:wq
#备份当前的镜像
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
#建立新的镜像
sudo dracut /boot/initramfs-$(uname -r).img $(uname -r)
#重启
sudo reboot
#最后输入上面的命令验证
lsmod | grep nouveau

三 检查 kernels 版本是否匹配

如果不检查kernels版本是否匹配,会报错:

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.

先进入相应目录查看是否有相应内核:

cd /usr/src/kernels/ && ls -al

如果为空表示没有,需要自己下载:

不要直接 yum install kernel-devel

因为这样下载下来的内核版本不一定匹配,所以实际的下载命令应该为:

yum install -y kernel-devel-$(uname -r) kernel-headers-$(uname -r) 

image-20230524154237782

如果发现还是报错,cd /lib/modules/$(uname -r) 进入到该目录执行ll

image-20230524160341190

如果发现build所指向的目录为空,说明内核没有安装正确,要么修改build的软链接,要么重新安装,如果修改build的软链接到另一个与内核不匹配的kernels目录,可能会报形如这个链接中所提到的错误.

四 安装必要依赖

安装 gcc g++ make 等常用工具,已有忽略

yum -y install gcc
yum -y install gcc-c++
yum -y install make

五 安装驱动

init 3 # 关闭图形化界面
wget https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
sh cuda_11.8.0_520.61.05_linux.run

等待一小会儿,进入后,填写accept选择我接受

image-20230524163736061

然后直接install

image-20230524141845041

image-20230524161903751

出现以上图示即为安装成功

六 声明环境变量

export PATH=/usr/local/cuda-11.8/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:$LD_LIBRARY_PATH

然后执行nvcc -V,如果有回显,说明cuda也没问题了

image-20230524162208519

1

评论区