ubuntu1804 安装Nvidia驱动-nvidia-docker

时间:2024-03-20 15:09:37

操作

看显卡

 
  1.  
  2. lspci | grep N
  3. 01:00.0 3D controller: NVIDIA Corporation GM107M [GeForce GTX 960M] (rev a2)
  4. 07:00.0 Network controller: Intel Corporation Dual Band Wireless-AC 3165 Plus Bluetooth (rev 99)
  5.  
  6. ubuntu-drivers devices
  7. lshw -numeric -C display

驱动下载
https://www.nvidia.com/Download/index.aspx?lang=en-us
http://www.nvidia.cn/Download/driverResults.aspx/156091/cn

删除原有驱动

 
  1. sudo apt-get remove --purge nvidia*
  2.  
  3. #sudo apt-get purge bumblebee* bbswitch-dkms

禁用nouveau驱动

 
  1. sudo bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf
  2. sudo bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nvidia-nouveau.conf"

看是否成功禁用了开源驱动

 
  1. cat /etc/modprobe.d/blacklist-nvidia-nouveau.conf
  2. blacklist nouveau
  3. options nouveau modeset=0

禁用nouveau生效

 
  1. sudo update-initramfs -u

重启

 
  1. reboot
  2.  
  3. lsmod | grep nouveau
  4. #看是否成功

获取相应的kernel

https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#system-requirements
ubuntu1804 安装Nvidia驱动-nvidia-docker

 
  1. $ apt-get install linux-source gcc
  2. $ apt-get install linux-headers-4.15.0-38-generic
  3.  
  4. $cat /proc/version

进入命令行操作

 
  1. 重启成功后打开终端,输入如下命令:sudo telinit 3。然后按快捷键:CTRL+ALT+F1 进入字符界面,输入用户名和密码,然后登录系统,进入我们保存下载 NVIDIA 驱动的目录,默认是:Downloads/ 目录,cd Downloads/,然后执行:bash NVIDIA-Linux-x86_64-418.43.bin。注意:NVIDIA-Linux-x86_64-418.43.bin 要根据你下载的驱动文件的名字相应改动。

#安装

 
  1. $ sudo chmod +x NVIDIA-Linux-x86_64-410.66.run
  2. $ sudo ./NVIDIA-Linux-x86_64-410.66.run

ubuntu1804 安装Nvidia驱动-nvidia-docker
ubuntu1804 安装Nvidia驱动-nvidia-docker

报错没有32bite-libriaries ,选择继续安装,然后出现下图

ubuntu1804 安装Nvidia驱动-nvidia-docker
选择中间的选项

检查

 
  1. $ nvidia-smi

nvidia-docker

先安装docker
https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/amd64/

 
  1. # 更新源
  2. $ sudo apt update
  3.  
  4. # 启用HTTPS
  5. $ sudo apt install -y \
  6. apt-transport-https \
  7. ca-certificates \
  8. curl \
  9. gnupg-agent \
  10. software-properties-common
  11.  
  12. # 添加GPG key
  13. $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  14.  
  15. # 添加稳定版的源
  16. $ sudo add-apt-repository \
  17. "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  18. $(lsb_release -cs) \
  19. stable"
  20.  
  21. # 更新源
  22. $ sudo apt update
  23.  
  24. # 安装Docker CE
  25. $ sudo apt install -y docker-ce
  26.  

配置nvidia-docker

 
  1. # 添加源
  2. $ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
  3. $ distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
  4. $ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \
  5. sudo tee /etc/apt/sources.list.d/nvidia-docker.list
  6.  
  7. # 更新源
  8. $ sudo apt update

安装nvidia-docker2

 
  1. # 安装nvidia-docker2
  2. $ sudo apt install -y nvidia-docker2
  3.  
  4. # 重启Docker daemon
  5. $ sudo pkill -SIGHUP dockerd

验证nvidia-docker2

 
  1. $ sudo nvidia-docker run --rm nvidia/cuda nvidia-smi

普通用户可访问

 
  1. $ sudo groupadd docker
  2. $ sudo usermod -aG docker $USER

nvidia-docker 插件

https://github.com/NVIDIA/nvidia-docker

nvidia-docker 安装

https://github.com/NVIDIA/nvidia-docker/wiki/Installation-(version-2.0)

cuda-cudnn

https://www.cnblogs.com/journeyonmyway/p/10316292.html#4329767