1、禁用 nouveau 驅動
sudo vim /etc/modprobe.d/nvidia-installer-disable-nouveau.conf
或者
sudo vim /etc/modprobe.d/blacklist.conf
追加內容為:
# generated by nvidia-installer blacklist nouveau options nouveau modeset=0
再執行:
sudo update-initramfs -u sudo shutdown -r now
介紹一下 update-initramfs :
NAME update-initramfs - generate an initramfs image SYNOPSIS update-initramfs -c|-d|-u [-k version] [-t] [-v] [-b directory] [-h] DESCRIPTION The update-initramfs script manages your initramfs images on your local box. It keeps track of the existing initramfs archives in /boot. There are three modes of operation create, update or delete. You must at least specify one of those modes. The initramfs is a gzipped cpio archive. At boot time, the kernel unpacks that archive into RAM disk, mounts and uses it as initial root file system. All finding of the root device happens in this early userspace. OPTIONS -k version Set the specific kernel version for whom the initramfs will be generated. For example the output of uname -r for your currently running kernel. This argument is optional for update. The default is the latest kernel version. The use of "all" for the version string specifies update-initramfs to execute the chosen action for all kernel versions, that are already known to update-initramfs. -c This mode creates a new initramfs. -u This mode updates an existing initramfs. -d This mode removes an existing initramfs. -t Allows one to take over an custom initramfs with a newer one. -v This option increases the amount of information you are given during the chosen action. -b directory Set an different bootdir for the image creation. -h Print a short help page describing the available options in update-initramfs.
2、關閉顯示管理器
sudo /etc/init.d/lightdm stop
或者
sudo service lightdm stop
3、單獨安裝驅動
(1) 用cuda安裝驅動
sudo <CudaInstaller>.run -silent -driver
(2) 下載驅動安裝
下載路徑:https://www.nvidia.com/Download/index.aspx?lang=cn
sudo ./NVIDIA-Linux-x86_64-430.40.run --no-opengl-files
- --no-opengl-files:表示只安裝驅動文件,不安裝OpenGL文件。這個參數不可省略,否則會導致登陸界面死循環,英語一般稱為“login loop”或者“stuck in login”。
- 必選參數解釋:因為NVIDIA的驅動默認會安裝OpenGL,而Ubuntu的內核本身也有OpenGL、且與GUI顯示息息相關,一旦NVIDIA的驅動覆寫了OpenGL,在GUI需要動態鏈接OpenGL庫的時候就引起問題。
- --no-x-check:表示安裝驅動時不檢查X服務,非必需,我們已經禁用圖形界面。
- --no-nouveau-check:表示安裝驅動時不檢查nouveau,非必需,我們已經禁用驅動。
- -Z, --disable-nouveau:禁用nouveau。此參數非必需,因為之前已經手動禁用了nouveau。
- -A:查看更多高級選項。
4、安裝cuda、cudnn
cuda下載路徑:https://developer.nvidia.com/cuda-toolkit-archive
sudo <CudaInstaller>.run
NVIDIA官網cuda安裝文檔:https://docs.nvidia.com/cuda/index.html
cudnn下載路徑(需要登錄):https://developer.nvidia.com/rdp/cudnn-download
tar -zxvf cudnn-10.0-linux-x64-v7.3.1.20.tgz sudo cp cuda/include/cudnn.h /usr/local/cuda-10.0/include/ sudo cp cuda/lib64/libcudnn* /usr/local/cuda-10.0/lib64/ sudo chmod a+r /usr/local/cuda-10.0/include/cudnn.h sudo chmod a+r /usr/local/cuda-10.0/lib64/libcudnn*
sudo vim /etc/profile
追加內容為:
export PATH="/usr/local/cuda-10.0/bin:$PATH" export LD_LIBRARY_PATH="/usr/local/cuda-10.0/lib64:/usr/local/cuda-10.0/extras/CUPTI/lib64:$LD_LIBRARY_PATH"