centos7.3安裝nvidia驅動和cuda9

一, 掛載本地源鏡像

1) 下載操做系統鏡像linux

全部服務器操做系統必須統一,本平臺只支持 CentOS 7.3 1611,鏡像下載地址shell

2) 上傳鏡像到服務器 ,假設上傳在 root 下vim

3) 創建掛載點,掛載centos

mkdir /mnt/cdrom

# 掛載光驅
mount -t /root/CentOS-7-x86_64-DVD-1611.iso /mnt/cdrom

# 卸載光驅
 umount /dev/hdc 或直接eject

#強制卸載命令:
(1) fuser -mk /dev/hdc
(2) eject

4) 配置本地yum 源緩存

1.進入 /etc/yum.repos.d下新建一個目錄backup,而後使用 mv *.repo backup/,將以前的yum源剪貼到目錄中。

2.新建local.repo 內容以下:
[local]
name=CentOS-$releasever local
baseurl=file:///mnt/cdrom/
gpgcheck=0
enabled=1

3.對yum進行初始化操做
    yum clean all  //清除緩存
    yum makecache   //創建新緩存

4.使用yum list | wc -l 統計個數

二,安裝nvidia驅動

1,安裝前的一系列準備工做

yum -y install kernel-devel
yum -y install epel-release
yum -y install dkms
yum -y install gcc

注:利用uname -a 命令查看系統內核版本,安裝kernel-devel,dkms時的版本需與之對應一致。如利用yum安裝時版本不一致,就掛載本地源的方式進行安裝。服務器

2,禁用nouveau

因爲nouveau 這個驅動和 Nvidia 驅動衝突,想要繼續安裝,則必須禁用此驅動。ui

1) 在啓動項中禁用url

vim /etc/default/grub #在GRUB_CMDLINE_LINUX中添加rd.driver.blacklist=nouveau nouveau.modeset=0操作系統

/etc/default/grub 文本內容以下:code

# 設定超時時間,默認爲5秒
GRUB_TIMEOUT=5
# 得到發行版名稱(好比CentOS Linux)
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
# 該項將使用grub-set-default和grub-reboot命令來配置默認啓動項
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
# 將會導入到每一個啓動項
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) 把驅動加入黑名單中

vim /etc/modprobe.d/blacklist.conf 

#打開(新建)文件,加入
blacklist nouveau

# 或者執行下面的命令
echo -e "blacklist nouveau\noptions nouveau modeset=0" > /etc/modprobe.d/blacklist.conf

3) 使用 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)

4) 更新完配置後,重啓

reboot
# 或者  init 3

5) 檢查nouveau driver確保沒有被加載!

lsmod | grep nouveau
#應該返回空

3,安裝nvidia驅動

# 先安裝編譯環境 gcc、kernel-devel、kernel-headers  (已經裝過則不須要再次安裝)
#"kernel-devel-uname-r == $(uname -r)"能夠確保安裝與當前運行內核版本同樣的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

其中的一些選項可自行百度,至此安裝完成。

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的開發包
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,查看狀態 nvidia-smi ,正常顯示即驅動安裝完成。

二,安裝cuda9

1, 安裝cuda9注意一點,再安裝步驟中的第二步,詢問是否安裝驅動時,選擇
NO。由於上面步驟已經安裝完成了nvidia驅動。

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
相關文章
相關標籤/搜索