Ubuntu 16.04 install NVIDIA driver

System: Ubuntu 16.04. Graphics card: GTX 960, independent graphics without integrated graphics.


0. Overview

At present, there are 3 ways to install the Nvidia card driver:
1. PPA source: the easiest, but there may not be the latest driver (pro-test), or there may be problems (rumour).

sudo add-apt-repository ppa:xorg-edgers/ppa #添加ppa源
sudo add-apt-repository ppa:graphics-drivers/ppa #添加ppa源
sudo apt-get update #更新apt-get

Then go to: System Settings -> Software and Updates -> Accessory Drivers, select the updated graphics card driver.
2. When installing CUDA, install the driver by the way: but it may not be the latest driver (pro-test).
3. Go to the official website to download the latest driver, and then install it locally (runfile is used in this article).

1. Uninstall the original Nvidia card driver first

#for case1: original driver installed by apt-get:
sudo apt-get remove --purge nvidia*

#for case2: original driver installed by runfile:
sudo chmod +x *.run
sudo ./NVIDIA-Linux-x86_64-384.59.run --uninstall

If the original driver was installed with apt-get, use the first method to uninstall.
If the original driver was installed with runfile, use the --uninstall command to uninstall it. In fact, when you install with runfile, the previous driver will also be uninstalled, so you can uninstall it manually.

2. Disable nouveau driver

sudo gedit /etc/modprobe.d/blacklist.conf

Add at the end of the text: (disable the nouveau third-party driver, you don't need to change it back later)

blacklist nouveau
options nouveau modeset=0

Then execute:sudo update-initramfs -u

After restarting, execute: lsmod | grep nouveau. If there is no screen output, the nouveau is disabled successfully.

3. Disable X-Window Services

sudo service lightdm stop #这会关闭图形界面,但不用紧张

Press Ctrl-Alt+F1to enter the command line interface, enter the user name and password to log in.

Tips: Enter: at the command line sudo service lightdm start, then press Ctrl-Alt+F7to return to the graphical interface.

4. Install the driver from the command line

#给驱动run文件赋予执行权限:
sudo chmod +x NVIDIA-Linux-x86_64-384.59.run
#后面的参数非常重要,不可省略:
sudo ./NVIDIA-Linux-x86_64-384.59.run –no-opengl-files
  • –no-opengl-files: Indicates that only the driver files are installed, and the OpenGL files are not installed. This parameter cannot be omitted, otherwise it will lead to an infinite loop of the login interface, which is generally called "login loop" or "stuck in login" in English.
  • –no-x-check: Indicates that the X service is not checked when installing the driver, not required.
  • –no-nouveau-check: Indicates that nouveau is not checked when installing the driver, not required.
  • -Z, --disable-nouveau: disable nouveau. This parameter is not required because nouveau has been manually disabled before.
  • -A: View more advanced options.

Explanation of required parameters: Because the NVIDIA driver will install OpenGL by default, and the Ubuntu kernel itself also has OpenGL, which is closely related to GUI display. Once the NVIDIA driver overrides OpenGL, it will cause problems when the GUI needs to dynamically link the OpenGL library.

After that, follow the prompts to install and restart after success.
If it prompts that the installation fails, do not rush to restart the computer, repeat the above steps, and install it a few more times.

Driver test:

nvidia-smi #若列出GPU的信息列表,表示驱动安装成功
nvidia-settings #若弹出设置对话框,亦表示驱动安装成功

5. Adjust screen resolution (successful)

If the screen cannot reach the best resolution, please refer to: http://blog.csdn.net/nostandby/article/details/69383543

#查看显示器标识符:我的是DVI-I-0,在'connected'之前。
xrandr
#查看分辨率的属性:我要看1920x1080的分辨率,在'Modeline'之后。
cvt 1920 1080
#创建新分辨率模式:拷贝'Modeline'之后的信息即可。
sudo xrandr --newmode "1920x1080"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync
#为显示器添加分辨率模式:
sudo xrandr --addmode DVI-I-0 "1920x1080"
#将分辨率模式应用到显示器:
sudo xrandr --output DVI-I-0 --mode "1920x1080"

PS: In the end, it was found that the inferior graphics card-monitor adapter caused the monitor and the resolution to be unrecognized. After changing the adapter, the resolution will be restored naturally without the above steps.

6. Install CUDA

sudo ./cuda_8.0.61_375.26_linux.run --no-opengl-libs
  • --no-opengl-libs: Indicates that only the driver files are installed, and the OpenGL files are not installed. Required parameter for the same reason as above. Note: -no-opengl-filesNo.
  • --uninstall (deprecated): Used to uninstall the CUDA Driver (obsolete).
  • --toolkit: Indicates that only CUDA Toolkit is installed, and Driver and Samples are not installed.
  • --help: View more advanced options.

After that, follow the prompts to install. I chose in turn:

accept #同意安装
n #不安装Driver,因为已安装最新驱动
y #安装CUDA Toolkit
<Enter> #安装到默认目录
y #创建安装目录的软链接
n #不复制Samples,因为在安装目录下有/samples

CUDA Sample test:

#编译并测试设备 deviceQuery:
cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery

#编译并测试带宽 bandwidthTest:
cd ../bandwidthTest
sudo make
./bandwidthTest

If the final results of these two tests are the same Result = PASS, the CUDA installation is successful.

sudo ./cuda_8.0.61.2_linux.run #最后安装补丁CUDA官方补丁

References:
http://blog.csdn.net/u012759136/article/details/53355781
http://blog.csdn.net/u012581999/article/details/52433609
http://hyichao.github.io/cv/2016 /10/15/ubuntu-cuda-caffe.html
http://blog.csdn.net/nostandby/article/details/69383543
http://www.linuxdiyf.com/linux/24659.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325448349&siteId=291194637