[centos7.9安裝nvidia驅(qū)動和cuda10]
一, 掛載本地源鏡像
1) 下載操作系統(tǒng)鏡像
所有服務(wù)器操作系統(tǒng)必須統(tǒng)一,本平臺只支持 CentOS 7.3 1611,鏡像下載地址。
2) 上傳鏡像到服務(wù)器 ,假設(shè)上傳在 root 下
3) 建立掛載點(diǎn),掛載
mkdir /mnt/cdrom
# 掛載光驅(qū)
mount -t /root/CentOS-7-x86_64-DVD-1611.iso /mnt/cdrom
# 卸載光驅(qū)
umount /dev/hdc 或直接eject
#強(qiáng)制卸載命令:
(1) fuser -mk /dev/hdc
(2) eject
4) 配置本地yum 源
1.進(jìn)入 /etc/yum.repos.d下新建一個(gè)目錄backup,然后使用 mv *.repo backup/,將之前的yum源剪貼到目錄中。
2.新建local.repo 內(nèi)容如下:
[local]
name=CentOS-$releasever local
baseurl=file:///mnt/cdrom/
gpgcheck=0
enabled=1
3.對yum進(jìn)行初始化操作
yum clean all //清除緩存
yum makecache //建立新緩存
4.使用yum list | wc -l 統(tǒng)計(jì)個(gè)數(shù)
二,安裝nvidia驅(qū)動
1,安裝前的一系列準(zhǔn)備工作
yum -y install kernel-devel
yum -y install epel-release
yum -y install dkms
yum -y install gcc
注:利用uname -a 命令查看系統(tǒng)內(nèi)核版本,安裝kernel-devel,dkms時(shí)的版本需與之對應(yīng)一致。如利用yum安裝時(shí)版本不一致,就掛載本地源的方式進(jìn)行安裝。
2,禁用nouveau
由于nouveau 這個(gè)驅(qū)動和 Nvidia 驅(qū)動沖突,想要繼續(xù)安裝,則必須禁用此驅(qū)動。
- 在啟動項(xiàng)中禁用
vim /etc/default/grub #在GRUB_CMDLINE_LINUX中添加 rd.driver.blacklist=nouveau nouveau.modeset=0
/etc/default/grub 文本內(nèi)容如下:
# 設(shè)定超時(shí)時(shí)間,默認(rèn)為5秒
GRUB_TIMEOUT=5
# 獲得發(fā)行版名稱(比如CentOS Linux)
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
# 該項(xiàng)將使用grub-set-default和grub-reboot命令來配置默認(rèn)啟動項(xiàng)
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
# 將會導(dǎo)入到每個(gè)啟動項(xiàng)
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet rd.driver.blacklist=nouveau nouveau.modeset=0"
GRUB_DISABLE_RECOVERY="true"
2) 把驅(qū)動加入黑名單中
vim /etc/modprobe.d/blacklist.conf
#打開(新建)文件,加入
blacklist nouveau
# 或者執(zhí)行下面的命令
echo -e "blacklist nouveau\noptions nouveau modeset=0" > /etc/modprobe.d/blacklist.conf
- 使用 dracut重新建立 initramfs image file :
* 備份 the initramfs file
$ sudo mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
* 重新建立 the initramfs file
$ sudo dracut -v /boot/initramfs-$(uname -r).img $(uname -r)
- 更新完配置后,重啟
reboot
# 或者 init 3
- 檢查nouveau driver確保沒有被加載!
lsmod | grep nouveau
#應(yīng)該返回空
3,安裝nvidia驅(qū)動
# 先安裝編譯環(huán)境 gcc、kernel-devel、kernel-headers (已經(jīng)裝過則不需要再次安裝)
#"kernel-devel-uname-r == $(uname -r)"可以確保安裝與當(dāng)前運(yùn)行內(nèi)核版本一樣的kernel-header
yum -y install gcc kernel-devel "kernel-devel-uname-r == $(uname -r)" dkms
chmod +x NVIDIA-Linux-x86_64-390.87.run
sudo ./NVIDIA-Linux-x86_64-390.87.run
# 全部選擇 YES
其中的一些選項(xiàng)可自行百度,至此安裝完成。
3.1 ERROR1: 缺少 gcc
ERROR: Unable to find the development tool `cc` in your path; please make sure that you have the package 'gcc' installed. If gcc is installed on your system, then please check that `cc` is in your PATH.
解決方法:
yum install gcc
3.2 ERROR2: 缺少 kernel-devel
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.
解決方法:
yum install kernel-devel
3.3 ERROR3: 缺少 kernels的
ERROR: Failed to run `/sbin/dkms build -m nvidia -v 390.87 -k 3.10.0-514.el7.x86_64`: Error! echo Your kernel headers for kernel 3.10.0-514.el7.x86_64 cannot be found at /lib/modules/3.10.0-514.el7.x86_64/build or /lib/modules/3.10.0-514.el7.x86_64/source.
解決方法:
# 檢查/usr/src/kernels/有沒有kernels的開發(fā)包
cd /usr/src/kernels/ && ls -al
# 有值則表示有
# 顯示 3.10.0-957.10.1.el7.x86_64
cd /lib/modules/ && ls -al
# 顯示 3.10.0-514.el7.x86_64
cd 3.10.0-514.el7.x86_64
# cd /lib/modules/$(uname -r)
rm -f build
ln -s /usr/src/kernels/3.10.0-957.10.1.el7.x86_64 build
4,查看狀態(tài) nvidia-smi ,正常顯示即驅(qū)動安裝完成。
二,安裝cuda9
1, 安裝cuda9注意一點(diǎn),再安裝步驟中的第二步,詢問是否安裝驅(qū)動時(shí),選擇
NO。因?yàn)樯厦娌襟E已經(jīng)安裝完成了nvidia驅(qū)動。
chmod +x cuda_9.0.103_384.59_linux.run
sudo ./cuda_9.0.103_384.59_linux.run
Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.59?
(y)es/(n)o/(q)uit: n
Do you want to install the OpenGL libraries?
(y)es/(n)o/(q)uit [ default is yes ]: y
Do you want to run nvidia-xconfig?
This will update the system X configuration file so that the NVIDIA X driver
is used. The pre-existing X configuration file will be backed up.
This option should not be used on systems that require a custom
X configuration, such as systems with multiple GPU vendors.
(y)es/(n)o/(q)uit [ default is no ]: y
Install the CUDA 9.0 Toolkit?
(y)es/(n)o/(q)uit: y
Enter Toolkit Location
[ default is /usr/local/cuda-9.0 ]:
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit:
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y
Install the CUDA 9.0 Samples?
(y)es/(n)o/(q)uit: y