因為一些意外,Ubuntu 中的 nvidia 驅動被卸載了。。。
於是我就開始了一個漫長的爬坑之旅。。。這里記錄一下過程
我的Ubuntu版本是 18.04 按住ctrl+alt+ f3 切換到純命令行模式
使用以下命令進一步卸載干凈
sudo apt-get --purge remove nvidia* sudo apt autoremove
然后切換到下載好的NVIDIA 驅動目錄
使用
sudo sh NVIDIA***.run
命令嘗試安裝。
結果出現了問題:
ERROR: An NVIDIA kernel module 'nvidia-drm' appears to already be loaded in your kernel. This may be because it is in use (for example, by an X server, a CUDA program, or the NVIDIA Persistence Daemon), but this may also happen if your kernel was configured without support for module unloading. Please be sure to exit any programs that may be using the GPU(s) before attempting to upgrade your driver. If no GPU-based programs are running, you know that your kernel supports module unloading, and you still receive this message, then an error may have occured that has corrupted an NVIDIA kernel module's usage count, for which the simplest remedy is to reboot your computer.
在這個網址(https://unix.stackexchange.com/questions/440840/how-to-unload-kernel-module-nvidia-drm) 找到了一個相同的問題。於是開始進行類似的解決操作
結果在第一步就開始出現問題
在 執行
systemctl isolate multi-user.target
命令時 ,屏幕開始報錯,如下所示

於是在網上又重新尋找這個問題解決方法,嘗試了一些方法都沒有解決成功。
這時我突然想到打開文件看下具體內容,如果不重要直接刪除試試。
我的對應文件58行左右的內容是如下兩句話
blacklist nouveau options nouveau modeset=0
也就是禁用 nouveau 驅動 。這里我暫時將這兩句注釋掉,然后運行
sudo update-initramfs -u
刷新內核。
這時 在繼續之前的步驟
systemctl isolate multi-user.target modprobe -r nvidia-drm
然后重新安裝 nvidia 驅動
這時就不再出現錯誤,安裝成功 !
接下來在一次將文件都復原,並運行一下命令
systemctl start graphical.target
重啟,然后將其他的cuda與cudnn 重新安裝上去。
注意 :這里 安裝cudnn 時 有一個小問題,不知道時我之前沒卸載干凈還是需要其他操做,但是按照官網的安裝指導使用 2 中的 包進行安裝的時候,cuda中的cudnn是5.1.10
而cudnn7.6.5 安裝到了 /usr/include 目錄中 在使用官方測試示例時顯示的確實是 cudnn 5.1.10 。於是 有重新下載 1 ,進行相關的安裝操作才正確安裝成功。

參考網址
【1】https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html
【2】https://unix.stackexchange.com/questions/440840/how-to-unload-kernel-module-nvidia-drm
【3】https://clay-atlas.com/blog/2020/03/04/linux-english-note-how-to-disable-nvidia-drm/
【4】https://devtalk.nvidia.com/default/topic/1037973/linux/can-t-install-new-driver-cannot-unload-module/
