天天看點

NVIDIA無法連接配接:NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driver

前言

在使用Ubuntu伺服器的時候,有時會碰到GPU無法使用的情況,即當輸入指令‘nvidia-smi’顯示NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver

情況有二:

第一種:顯示卡驅動型号自動改變

NVIDIA無法連接配接:NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driver

有時候顯示卡驅動自動切換到開源的顯示卡驅動“Nouveau”上,導緻NVIDIA顯示卡驅動失效,把驅動調回第一個驅動即可解決問題。(這裡沒想通這裡的驅動為啥會自動切換,也許跟核心自動更新有關)

第二種:核心更新導緻原顯示卡驅動不可用

這裡許多部落客說用安裝DKMS的方式解決,但是對我無效。遂采用降低核心版本并禁用核心更新的方式解決。

修改系統引導檔案:sudo gedit /etc/default/grub

更改内容如下:

GRUB_TIMEOUT=10

GRUB_CMDLINE_LINUX_DEFAULT=“text”

# grub_timeout_style=hidden(以#号注釋該語句)

更新使生效:sudo update-grub

重新開機後系統引導多了一個選擇界面,分别是:

*ubuntu

*ubuntu的進階選項

選擇最老的核心版本并啟動,此時輸入nvidia-smi正常

但是為了以絕後患,接下來關閉自動更新和自動更新核心:

NVIDIA無法連接配接:NVIDIA-SMI has failed because it couldn‘t communicate with the NVIDIA driver

在terminal輸入 uname -a檢視目前核心版本,部落客的是5.11.0-40-generic

輸入指令

sudo apt-mark hold linux-headers-5.11.0-40-generic

sudo apt-mark hold linux-image-5.11.0-40-generic

sudo apt-mark hold linux-modules-5.11.0-40-generic

sudo apt-mark hold linux-modules-extra-5.11.0-40-generic

sudo apt-mark hold linux-modules-nvidia-470-5.11.0-40-generic

檢視啟動項grep menuentry /boot/grub/grub.cfg

并編輯啟動項

sudo gedit /etc/default/grub

設定預設啟動項,更改GRUB_DEFAULT=0為 GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu,Linux 5.11.0-40-generic"

(如果是中文則為**“Ubuntu 進階選項>Ubuntu,Linux 5.11.0-40-generic”**)

繼續閱讀