Debian卸载内核

避免删除所有内核:确保系统始终保留至少一个可用的内核版本。如果在卸载内核时意外删除了所有内核版本,系统将无法启动。

1.查询内核信息

1
dpkg --list | grep `uname -r`

显示信息:

1
2
3
4
root@s4247 /opt # dpkg --list | grep `uname -r`
ii linux-headers-4.19.0-26-cloud-amd64 4.19.304-1 amd64 Header files for Linux 4.19.0-26-cloud-amd64
ii linux-image-4.19.0-26-cloud-amd64 4.19.304-1 amd64 Linux 4.19 for x86-64 cloud (signed)

2.卸载内核

1
apt autoremove linux-headers-4.19.0-26-cloud-amd64 linux-image-4.19.0-26-cloud-amd64 --purge

显示信息:

1
2
3
4
5
6
7
8
9
root@s4247 /opt # apt autoremove linux-headers-4.19.0-26-cloud-amd64 linux-image-4.19.0-26-cloud-amd64 --purge
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
linux-compiler-gcc-8-x86* linux-headers-4.19.0-26-cloud-amd64* linux-headers-4.19.0-26-common* linux-headers-cloud-amd64* linux-image-4.19.0-26-cloud-amd64* linux-image-cloud-amd64* linux-kbuild-4.19*
0 upgraded, 0 newly installed, 7 to remove and 0 not upgraded.
After this operation, 131 MB disk space will be freed.
Do you want to continue? [Y/n] Y

3.更新启动信息

1
update-initramfs -u && update-grub

显示信息:

1
2
3
4
5
6
root@s4247 /opt # update-initramfs -u && update-grub
update-initramfs: Generating /boot/initrd.img-4.19.0-26-cloud-amd64
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.19.0-26-cloud-amd64
Found initrd image: /boot/initrd.img-4.19.0-26-cloud-amd64
done

如果出现:

1
2
3
4
Warning: os-prober will not be executed to detect other bootable partitions.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...

则更新/etc/default/grub配置

1
GRUB_DISABLE_OS_PROBER=false