Operation

Ubuntu 删除多余内核

Ubuntu 删除多余内核

  • 查看当前内核
uname -a
Linux rew 4.15.0-42-generic #45~16.04.1-Ubuntu SMP Mon Nov 19 13:02:27 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • 查看所有内核
dpkg --get-selections | grep linux
console-setup-linux                     install
libselinux1:amd64                       install
libselinux1:i386                        install
linux-base                              install
linux-firmware                          install
linux-generic-hwe-16.04                 install
linux-headers-4.15.0-42                 install
linux-headers-4.15.0-39                 install
linux-headers-4.15.0-39-generic         install
linux-headers-4.15.0-42-generic         install
linux-headers-generic-hwe-16.04         install
linux-image-4.15.0-39-generic           install
linux-image-4.15.0-42-generic           install
linux-image-generic-hwe-16.04           install
linux-libc-dev:amd64                    install
linux-libc-dev:i386                     install
linux-modules-4.15.0-39-generic         install
linux-modules-4.15.0-42-generic         install
linux-modules-extra-4.15.0-39-generic   install
linux-modules-extra-4.15.0-42-generic   install
linux-sound-base                        install
pptp-linux                              install
syslinux                                install
syslinux-common                         install
syslinux-legacy                         install
util-linux                              install
  • 移除冗余内核

所有39版本的对我来说都是多余的,进行删除

sudo apt-get remove \
linux-headers-4.15.0-39 \
linux-headers-4.15.0-39-generic \
linux-image-4.15.0-39-generic \
linux-modules-4.15.0-39-generic \
linux-modules-extra-4.15.0-39-generic
  • 卸载后重新检查
dpkg --get-selections | grep linux
console-setup-linux                     install
libselinux1:amd64                       install
libselinux1:i386                        install
linux-base                              install
linux-firmware                          install
linux-generic-hwe-16.04                 install
linux-headers-4.15.0-42                 install
linux-headers-4.15.0-42-generic         install
linux-headers-generic-hwe-16.04         install
linux-image-4.15.0-39-generic           deinstall
linux-image-4.15.0-42-generic           install
linux-image-generic-hwe-16.04           install
linux-libc-dev:amd64                    install
linux-libc-dev:i386                     install
linux-modules-4.15.0-39-generic         deinstall
linux-modules-4.15.0-42-generic         install
linux-modules-extra-4.15.0-39-generic   deinstall
linux-modules-extra-4.15.0-42-generic   install
linux-sound-base                        install
pptp-linux                              install
syslinux                                install
syslinux-common                         install
syslinux-legacy                         install
util-linux                              install

状态为 deinstall 即已经卸载,如果觉得看着不舒服的话可以使用purge连配置文件里一起彻底删除,清理内核列表

sudo apt-get purge \
linux-headers-4.15.0-39 \
linux-headers-4.15.0-39-generic \
linux-image-4.15.0-39-generic \
linux-modules-4.15.0-39-generic \
linux-modules-extra-4.15.0-39-generic
  • 更新系统引导

删除内核后需要更新grub移除失效的启动项

sudo update-grub  # 根据情况选择 grub 或 grub2

# (可选) 通常可能是同一个,可以这样看一下
> ll /usr/sbin/update-grub
-rwxr-xr-x 1 root root 64 Feb 24  2021 /usr/sbin/update-grub

> ll /usr/sbin/update-grub2
lrwxrwxrwx 1 root root 11 May 20 13:50 /usr/sbin/update-grub2 -> 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-4.15.0-42-generic
Found initrd image: /boot/initrd.img-4.15.0-42-generic
Found linux image: /boot/vmlinuz-5.4.0-74-generic
Found initrd image: /boot/initrd.img-4.15.0-42-generic
Found Windows Boot Manager on /dev/nvme0n1p1@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for UEFI Firmware Settings
done

留言

您的电子邮箱地址不会被公开。