ubuntu恢復指定版本內核

ubuntu重啓後,nvidia-smi命令無法使用

~# nvidia-smi 
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

1. dpkg --get-selections | grep linux-image,查看內核,安裝顯卡驅動時使用的linux-image-4.15.0-66-generic

~# dpkg --get-selections | grep linux-image
linux-image-4.13.0-36-generic			install
linux-image-4.15.0-66-generic			install
linux-image-4.15.0-91-generic			purge
linux-image-extra-4.13.0-36-generic		install

2. 卸載並清理高版本內核

~# apt-get remove linux-image-4.15.0-88-generic linux-image-4.15.0-91-generic
~# aptitude purge linux-image-4.15.0-88-generic linux-image-4.15.0-91-generic

3. 刪除內核啓動文件

~# ll /boot/
total 144832
drwxr-xr-x  3 root root     4096 3月  31 12:58 ./
drwxr-xr-x 27 root root     4096 3月  31 12:58 ../
-rw-r--r--  1 root root  1501359 2月  17  2018 abi-4.13.0-36-generic
-rw-r--r--  1 root root   213220 2月  17  2018 config-4.13.0-36-generic
-rw-r--r--  1 root root   217370 10月  1 23:24 config-4.15.0-66-generic
-rw-r--r--  1 root root   217503 2月  12 13:35 config-4.15.0-88-generic
-rw-r--r--  1 root root   217465 2月  29 01:24 config-4.15.0-91-generic
drwxr-xr-x  5 root root     4096 3月  31 12:58 grub/
-rw-r--r--  1 root root 49708971 2月  27 06:51 initrd.img-4.13.0-36-generic
-rw-r--r--  1 root root  9400228 2月  27 06:52 initrd.img-4.15.0-50-generic
-rw-r--r--  1 root root 22996286 3月  31 12:58 initrd.img-4.15.0-66-generic
-rw-r--r--  1 root root 23055216 3月  31 12:56 initrd.img-4.15.0-91-generic
-rw-r--r--  1 root root   182704 1月  28  2016 memtest86+.bin
-rw-r--r--  1 root root   184380 1月  28  2016 memtest86+.elf
-rw-r--r--  1 root root   184840 1月  28  2016 memtest86+_multiboot.bin
-rw-r--r--  1 root root     2850 2月  17  2018 retpoline-4.13.0-36-generic
-rw-------  1 root root  3879946 2月  17  2018 System.map-4.13.0-36-generic
-rw-------  1 root root  4062584 10月  1 23:24 System.map-4.15.0-66-generic
-rw-------  1 root root  4067466 2月  12 13:35 System.map-4.15.0-88-generic
-rw-------  1 root root  4067536 2月  29 01:24 System.map-4.15.0-91-generic
-rw-r--r--  1 root root  7710912 2月  25 00:52 vmlinuz-4.13.0-36-generic
-rw-------  1 root root  8181656 10月  3 21:23 vmlinuz-4.15.0-66-generic
-rw-------  1 root root  8193432 3月   1 18:28 vmlinuz-4.15.0-91-generic
~# rm -rf /boot/*-88-generic
~# rm -rf /boot/*-91-generic

4.重新引導啓動文件

~# update-grub
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.13.0-36-generic
Found initrd image: /boot/initrd.img-4.13.0-36-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done

5. 若無法找到linux-image-4.15.0-66-generic,則需要按裝linux-image-4.15.0-66-generic

~# apt install linux-image-4.15.0-66-generic linux-headers-4.15.0-66-generic -y

6. 重新引導啓動文件

~# update-grub

7. 重啓

~# reboot

8.查看內核版本

~# uname -r
4.15.0-66-generic

 9.查看nvidia版本

~# ll /usr/src/
total 36
drwxr-xr-x  9 root root 4096 3月  19 06:56 ./
drwxr-xr-x 12 root root 4096 6月  28  2019 ../
drwxr-xr-x 27 root root 4096 3月   1  2018 linux-headers-4.13.0-36/
drwxr-xr-x  7 root root 4096 3月   1  2018 linux-headers-4.13.0-36-generic/
drwxr-xr-x 25 root root 4096 2月  27 06:54 linux-headers-4.15.0-88/
drwxr-xr-x  8 root root 4096 2月  27 06:54 linux-headers-4.15.0-88-generic/
drwxr-xr-x 25 root root 4096 3月  19 06:56 linux-headers-4.15.0-91/
drwxr-xr-x  8 root root 4096 3月  19 06:56 linux-headers-4.15.0-91-generic/
drwxr-xr-x  7 root root 4096 2月  26 16:42 nvidia-418.88/

10. dkms將nvidia版本寫入內核模塊

~# dkms build -m nvidia -v 418.88

11.運行nvidia-smi

~# nvidia-smi 
Tue Mar 31 13:02:47 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.88       Driver Version: 418.88       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 108...  Off  | 00000000:05:00.0 Off |                  N/A |
|  0%   31C    P5    25W / 265W |      0MiB / 11177MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 108...  Off  | 00000000:09:00.0 Off |                  N/A |
|  0%   27C    P5    25W / 260W |      0MiB / 11178MiB |      5%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

12. 禁止內核自動升級,修改/etc/apt/apt.conf.d/10periodic和/etc/apt/apt.conf.d/20auto-upgrades 內容如下

~# cat /etc/apt/apt.conf.d/10periodic 
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "1";
~# cat /etc/apt/apt.conf.d/20auto-upgrades 
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "1";
~# apt-mark hold linux-headers-4.15.0-66-generic linux-image-4.15.0-66-generic
linux-headers-4.15.0-66-generic set on hold.
linux-image-4.15.0-66-generic set on hold.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章