linux · 2021年7月4日 0

Centos7 旧版本安装NVIDIA驱动

本文仅限于Centos 7.2,7.3,7.4,7.5,7.6,7.7 ,最新版本7.8随便搞,不用看。

本文仅供学习与交流,请勿用于商业用途。

下载NVIDIA驱动

登录英伟达中文官网,选择正确的显卡,下载驱动。

https://www.nvidia.cn/Download/index.aspx?lang=cn

这里以特斯拉T4为例

wget https://cn.download.nvidia.cn/tesla/450.51.05/NVIDIA-Linux-x86_64-450.51.05.run

屏蔽默认显示驱动

echo "blacklist nouveau" >> /etc/modprobe.d/blacklist.conf
echo "options nouveau modeset=0" >> /etc/modprobe.d/blacklist.conf

安装编译环境

如果使用网络yum源安装包,一定是Centos7.8的,为了保证旧版本环境,一定要使用安装介质内的包。

检查当前内核版本

uname -r
3.10.0-1062.18.1.el7.x86_64

准备当前系统的安装介质,配置本地介质yum源

cat /etc/yum.repos.d/CentOS-Media.repo 
# CentOS-Media.repo
#
#  This repo can be used with mounted DVD media, verify the mount point for
#  CentOS-7.  You can use this repo and yum to install items directly off the
#  DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
#  yum --enablerepo=c7-media [command]
#  
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c7-media [command]

[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
        file:///media/cdrom/
        file:///media/cdrecorder/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

从上面配置文件看出,将安装介质挂载到/media/cdrom,并将enabled=0改为enabled=1,屏蔽/etc/yum.repos.d/CentOS-Base.repo,即可启动本地yum源。

挂载安装介质到相对应路径

lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   20G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   19G  0 part 
  ├─centos-root 253:0    0   17G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sr0              11:0    1  4.4G  0 rom
mount /dev/sr0 /media/cdrom

创建yum缓存

yum makecache

安装同版本的开发环境包

yum grouplist
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Installed Environment Groups:
   Server with GUI
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
yum groupinstall "Development Tools" -y

检查gcc版本,检查编译内核版本,编译内核版本要等于当前内核版本。

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)

rpm -qa | grep kernel
kernel-3.10.0-1062.el7.x86_64
kernel-3.10.0-1062.18.1.el7.x86_64
kernel-devel-3.10.0-1127.13.1.el7.x86_64
abrt-addon-kerneloops-2.1.11-55.el7.centos.x86_64
kernel-headers-3.10.0-1062.18.1.el7.x86_64
kernel-tools-libs-3.10.0-1062.18.1.el7.x86_64
kernel-tools-3.10.0-1062.18.1.el7.x86_64

安装驱动

下载好驱动后,添加执行权限,直接跟随向导走

chmod +x ./NVIDIA-Linux-x86_64-450.51.05.run
./NVIDIA-Linux-x86_64-450.51.05.run

检查驱动状态

lsmod | grep nvidia 
nvidia-smi