删除系统旧版本内核

系统用得久了,积累下来很多升级后留下的旧版本内核,今天升级的时候自动更新了OPENJDK11后发现报出磁盘空间不足了,于是开始删除各种文件,删除了从OPENJDK8开始的所有JAVA包之后自然想到了旧的内核文件,一查果然占用空间也不小:

┌─[root@xxx]─[/boot]
└──╼ #ll -h
total 587M
-rw-r--r-- 1 root root 200K Oct  7 03:04 config-4.18.0-parrot10-amd64
-rw-r--r-- 1 root root 200K Sep  7 23:04 config-4.18.0-parrot8-amd64
drwx------ 7 root root 4.0K Jan  1  1970 efi
drwxr-xr-x 5 root root 4.0K Oct 11 09:10 grub
-rw-r--r-- 1 root root  29M Oct 12  2017 initrd.img-4.11.0-parrot6-amd64.old-dkms
-rw-r--r-- 1 root root  30M Nov 16  2017 initrd.img-4.12.0-parrot6-amd64.old-dkms
-rw-r--r-- 1 root root  30M Dec 15  2017 initrd.img-4.13.0-parrot10-amd64.old-dkms
-rw-r--r-- 1 root root  30M Jan  2  2018 initrd.img-4.13.0-parrot13-amd64.old-dkms
-rw-r--r-- 1 root root  30M Dec  4  2017 initrd.img-4.13.0-parrot4-amd64.old-dkms
-rw-r--r-- 1 root root  34M Feb 26  2018 initrd.img-4.14.0-parrot12-amd64.old-dkms
-rw-r--r-- 1 root root  36M May  4 09:18 initrd.img-4.14.0-parrot13-amd64.old-dkms
-rw-r--r-- 1 root root  33M Jan 15  2018 initrd.img-4.14.0-parrot2-amd64.old-dkms
-rw-r--r-- 1 root root  33M Jan 23  2018 initrd.img-4.14.0-parrot7-amd64.old-dkms
-rw-r--r-- 1 root root  36M May 14 09:19 initrd.img-4.15.0-parrot11-amd64.old-dkms
-rw-r--r-- 1 root root  36M Jun  2 10:39 initrd.img-4.15.0-parrot17-amd64.old-dkms
-rw-r--r-- 1 root root  54M Aug 20 09:07 initrd.img-4.16.0-parrot12-amd64.old-dkms
-rw-r--r-- 1 root root  54M Jul 22 13:57 initrd.img-4.16.0-parrot5-amd64.old-dkms
-rw-r--r-- 1 root root  56M Oct 31 13:29 initrd.img-4.18.0-parrot10-amd64
-rw-r--r-- 1 root root  56M Oct 11 08:57 initrd.img-4.18.0-parrot8-amd64
-rw-r--r-- 1 root root 3.2M Oct  7 03:04 System.map-4.18.0-parrot10-amd64
-rw-r--r-- 1 root root 3.2M Sep  7 23:04 System.map-4.18.0-parrot8-amd64
-rw-r--r-- 1 root root 4.9M Oct  7 03:04 vmlinuz-4.18.0-parrot10-amd64
-rw-r--r-- 1 root root 4.9M Sep  7 23:04 vmlinuz-4.18.0-parrot8-amd64

找大佬分享的经验,参考到如下查询命令:dpkg --get-selections | grep linux

┌─[root@xxx]─[/boot]
└──╼ #dpkg --get-selections | grep linux
binutils-x86-64-linux-gnu			install
console-setup-linux				install
enum4linux					install
firmware-linux					install
firmware-linux-free				install
firmware-linux-nonfree				install
fonts-linuxlibertine				install
libnvpair1linux					install
libselinux1:amd64				install
libuutil1linux					install
libzfs2linux					install
libzpool2linux					install
linux-base					install
linux-compiler-gcc-7-x86			install
linux-exploit-suggester				install
linux-headers-4.18.0-parrot10-amd64		install
linux-headers-4.18.0-parrot10-common		install
linux-headers-4.18.0-parrot8-amd64		install
linux-headers-4.18.0-parrot8-common		install
linux-headers-amd64				install
linux-image-4.11.0-parrot6-amd64		deinstall
linux-image-4.12.0-parrot6-amd64		deinstall
linux-image-4.13.0-parrot10-amd64		deinstall
linux-image-4.13.0-parrot13-amd64		deinstall
linux-image-4.13.0-parrot4-amd64		deinstall
linux-image-4.14.0-parrot12-amd64		deinstall
linux-image-4.14.0-parrot13-amd64		deinstall
linux-image-4.14.0-parrot2-amd64		deinstall
linux-image-4.14.0-parrot7-amd64		deinstall
linux-image-4.15.0-parrot11-amd64		deinstall
linux-image-4.15.0-parrot17-amd64		deinstall
linux-image-4.16.0-parrot12-amd64		deinstall
linux-image-4.16.0-parrot16-amd64		deinstall
linux-image-4.16.0-parrot5-amd64		deinstall
linux-image-4.17.0-parrot17-amd64		deinstall
linux-image-4.17.0-parrot8-amd64		deinstall
linux-image-4.18.0-parrot10-amd64		install
linux-image-4.18.0-parrot8-amd64		install
linux-image-amd64				install
linux-kbuild-4.18				install
linux-libc-dev:amd64				install
python-selinux					install
python3-selinux					install
selinux-policy-default				deinstall
selinux-policy-dev				deinstall
selinux-utils					install
util-linux					install
zfsutils-linux					install

找到了就大刀向内核文件砍去吧 :

┌─[root@xxx]─[/boot]
└──╼ #apt remove --purge  linux-image-4.12.0-parrot6-amd64 linux-image-4.13.0-parrot10-amd64 linux-image-4.13.0-parrot13-amd64 linux-image-4.13.0-parrot4-amd64 linux-image-4.14.0-parrot12-amd64 linux-image-4.14.0-parrot13-amd64 linux-image-4.14.0-parrot2-amd64 linux-image-4.14.0-parrot7-amd64 linux-image-4.15.0-parrot11-amd64 linux-image-4.15.0-parrot17-amd64 linux-image-4.16.0-parrot12-amd64 linux-image-4.16.0-parrot16-amd64 linux-image-4.16.0-parrot5-amd64 linux-image-4.17.0-parrot17-amd64 linux-image-4.17.0-parrot8-amd64 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gvfs-bin icedtea-netx-common java-wrappers libadns1 python-adns python-easygui python-metaconfig
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  linux-image-4.12.0-parrot6-amd64* linux-image-4.13.0-parrot10-amd64* linux-image-4.13.0-parrot13-amd64*
  linux-image-4.13.0-parrot4-amd64* linux-image-4.14.0-parrot12-amd64* linux-image-4.14.0-parrot13-amd64*
  linux-image-4.14.0-parrot2-amd64* linux-image-4.14.0-parrot7-amd64* linux-image-4.15.0-parrot11-amd64*
  linux-image-4.15.0-parrot17-amd64* linux-image-4.16.0-parrot12-amd64* linux-image-4.16.0-parrot16-amd64*
  linux-image-4.16.0-parrot5-amd64* linux-image-4.17.0-parrot17-amd64* linux-image-4.17.0-parrot8-amd64*
0 upgraded, 0 newly installed, 15 to remove and 0 not upgraded.
3 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
(Reading database ... 524662 files and directories currently installed.)
Purging configuration files for linux-image-4.14.0-parrot13-amd64 (4.14.13-1parrot13) ...
Purging configuration files for linux-image-4.15.0-parrot17-amd64 (4.15.17-1parrot17) ...
Purging configuration files for linux-image-4.16.0-parrot5-amd64 (4.16.5-1parrot5) ...
Purging configuration files for linux-image-4.12.0-parrot6-amd64 (4.12.6-1parrot6) ...
Purging configuration files for linux-image-4.13.0-parrot13-amd64 (4.13.13-1parrot13) ...
Purging configuration files for linux-image-4.13.0-parrot4-amd64 (4.13.4-2parrot0) ...
Purging configuration files for linux-image-4.17.0-parrot8-amd64 (4.17.8-1parrot8) ...
rmdir: failed to remove '/lib/modules/4.17.0-parrot8-amd64': Directory not empty
dpkg: warning: while removing linux-image-4.17.0-parrot8-amd64, directory '/lib/modules/4.17.0-parrot8-amd64' not empty so not removed
Purging configuration files for linux-image-4.13.0-parrot10-amd64 (4.13.10-1parrot10) ...
Purging configuration files for linux-image-4.16.0-parrot12-amd64 (4.16.12-1parrot12.1) ...
Purging configuration files for linux-image-4.14.0-parrot12-amd64 (4.14.12-2parrot12) ...
Purging configuration files for linux-image-4.15.0-parrot11-amd64 (4.15.11-1parrot11) ...
Purging configuration files for linux-image-4.17.0-parrot17-amd64 (4.17.17-1parrot17) ...
rmdir: failed to remove '/lib/modules/4.17.0-parrot17-amd64': Directory not empty
dpkg: warning: while removing linux-image-4.17.0-parrot17-amd64, directory '/lib/modules/4.17.0-parrot17-amd64' not empty so not removed
Purging configuration files for linux-image-4.16.0-parrot16-amd64 (4.16.16-2parrot16) ...
Purging configuration files for linux-image-4.14.0-parrot7-amd64 (4.14.7-1parrot7) ...
Purging configuration files for linux-image-4.14.0-parrot2-amd64 (4.14.2-1parrot2) ...
Configuring sandbox profiles....
Sandbox profiles updated!

最后并未自动删除old-dkms文件,手动删除了且不要忘记嘱咐sudo update-grub更新开机启动控制文件。

过程参考链接


服务器资源由ZeptoVM赞助

Partners Wiki Discord