查看当前版本的内核

终端输入uname -a

root@VM-16-8-ubuntu:~# uname -a
Linux VM-16-8-ubuntu 6.4.0-060400-generic #202306271339 SMP PREEMPT_DYNAMIC Tue Jun 27 14:26:34 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

查看已安装的内核

终端输入dpkg --get-selections | grep linux

root@VM-16-8-ubuntu:~# dpkg --get-selections | grep linux
binutils-x86-64-linux-gnu                       install
console-setup-linux                             install
libselinux1:amd64                               install
libselinux1-dev:amd64                           install
linux-base                                      install
linux-firmware                                  install
linux-headers-6.3.5-060305                      install
linux-headers-6.3.5-060305-generic              install
linux-headers-6.4.0-060400                      install
linux-headers-6.4.0-060400-generic              install
linux-image-unsigned-6.3.5-060305-generic       install
linux-image-unsigned-6.4.0-060400-generic       install
linux-libc-dev:amd64                            install
linux-modules-6.3.5-060305-generic              install
linux-modules-6.4.0-060400-generic              install
util-linux                                      install

删除不需要的内核

以删除6.3.5内核为例,使用purge命令删除多余内核,同时也会删除相应的配置文件

apt-get purge linux-headers-6.3.5-060305 \
linux-headers-6.3.5-060305-generic \
linux-image-unsigned-6.3.5-060305-generic \
linux-modules-6.3.5-060305-generic

控制台输出内容大致如下

root@VM-16-8-ubuntu:~# apt-get purge linux-headers-6.3.5-060305 linux-headers-6.3.5-060305-generic linux-image-unsigned-6.3.5-060305-generic linux-modules-6.3.5-060305-generic
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-6.3.5-060305* linux-headers-6.3.5-060305-generic* linux-image-unsigned-6.3.5-060305-generic* linux-modules-6.3.5-060305-generic*
0 upgraded, 0 newly installed, 4 to remove and 6 not upgraded.
After this operation, 689 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 132080 files and directories currently installed.)
Removing linux-headers-6.3.5-060305-generic (6.3.5-060305.202305301445) ...
Removing linux-headers-6.3.5-060305 (6.3.5-060305.202305301445) ...
Removing linux-image-unsigned-6.3.5-060305-generic (6.3.5-060305.202305301445) ...
I: /boot/vmlinuz.old is now a symlink to vmlinuz-6.4.0-060400-generic
I: /boot/initrd.img.old is now a symlink to initrd.img-6.4.0-060400-generic
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-6.3.5-060305-generic
/etc/kernel/postrm.d/kdump-tools:
kdump-tools: Removing /var/lib/kdump/initrd.img-6.3.5-060305-generic
/etc/kernel/postrm.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Sourcing file `/etc/default/grub.d/kdump-tools.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.4.0-060400-generic
Found initrd image: /boot/initrd.img-6.4.0-060400-generic
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.
done
Removing linux-modules-6.3.5-060305-generic (6.3.5-060305.202305301445) ...
(Reading database ... 95134 files and directories currently installed.)
Purging configuration files for linux-modules-6.3.5-060305-generic (6.3.5-060305.202305301445) ...
dpkg: warning: while removing linux-modules-6.3.5-060305-generic, directory '/lib/modules/6.3.5-060305-generic' not empty so not removed
Purging configuration files for linux-image-unsigned-6.3.5-060305-generic (6.3.5-060305.202305301445) ...

再次查看已安装的内核,多余的内核已被删除

root@VM-16-8-ubuntu:~# dpkg --get-selections | grep linux
binutils-x86-64-linux-gnu                       install
console-setup-linux                             install
libselinux1:amd64                               install
libselinux1-dev:amd64                           install
linux-base                                      install
linux-firmware                                  install
linux-headers-6.4.0-060400                      install
linux-headers-6.4.0-060400-generic              install
linux-image-unsigned-6.4.0-060400-generic       install
linux-libc-dev:amd64                            install
linux-modules-6.4.0-060400-generic              install
util-linux                                      install
最后更新于 2023-08-04