ubuntu清理Linux内核和禁用Linux内核自动更新

OS版本

Ubuntu 20.04 LTS

查看已安装内核

$ dpkg --get-selections | grep linux

查看正在使用的内核

$ uname -sr

删除不用内核

$ sudo apt-get remove linux-headers-5.4.0-74 -y
$ sudo apt-get remove linux-headers-5.4.0-74-generic -y
$ sudo apt-get remove linux-image-5.4.0-74-generic -y
$ sudo apt-get remove linux-modules-5.4.0-74-generic -y
$ sudo apt-get remove linux-modules-extra-5.4.0-74-generic -y

关闭内核自动更新

$ sudo apt-mark hold linux-image-generic linux-headers-generic 
linux-image-generic set on hold.
linux-headers-generic set on hold.

如果要重启启动内核更新:

$ sudo apt-mark unhold linux-image-generic linux-headers-generic

更新grub文件

$ sudo update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.0-89-generic
Found initrd image: /boot/initrd.img-5.4.0-89-generic
...
done