0

This question already has an answer here:

I've read many answers on this site answering this question. I'm on 16.04, so the following should take care of old kernels:

sudo apt-get autoremove

Failing that, I can remove old ones manually (keeping recent kernels as backup):

sudo apt-get remove linux-image-3.*
sudo apt-get remove linux-image-extras-3.*
sudo apt-get remove linux-headers-3.*
sudo apt-get remove linux-image-4.0.0-x*
sudo apt-get remove linux-image-extras-4.0.0-x*
sudo apt-get remove linux-headers-4.0.0-x*

where I performed the last three commands for x = 3, 4, 5, 6, 7, 8. This did result in disk space being cleared, up to ~500M in some cases. However, I still see many MB of disk space being used on these old kernels in /boot:

ls -lh /boot

...

-rw-r--r-- 1 root root  14M Dec 17  2016 initrd.img-3.19.0-33-generic.old-dkms
-rw-r--r-- 1 root root  14M Dec 17  2016 initrd.img-3.19.0-61-generic.old-dkms
-rw-r--r-- 1 root root  14M Dec 17  2016 initrd.img-3.19.0-64-generic.old-dkms
-rw-r--r-- 1 root root  14M Dec 17  2016 initrd.img-3.19.0-65-generic.old-dkms
-rw-r--r-- 1 root root  14M Dec 17  2016 initrd.img-3.19.0-66-generic.old-dkms
-rw-r--r-- 1 root root  14M Dec 17  2016 initrd.img-3.19.0-68-generic.old-dkms
-rw-r--r-- 1 root root  14M Dec 17  2016 initrd.img-3.19.0-74-generic.old-dkms
-rw-r--r-- 1 root root  14M Dec 17  2016 initrd.img-3.19.0-75-generic.old-dkms
-rw-r--r-- 1 root root  14M Dec 17  2016 initrd.img-3.19.0-77-generic.old-dkms
-rw-r--r-- 1 root root  39M Nov 28 09:41 initrd.img-4.4.0-101-generic
-rw-r--r-- 1 root root  15M Dec 17  2016 initrd.img-4.4.0-31-generic.old-dkms
-rw-r--r-- 1 root root  18M Aug 27 18:51 initrd.img-4.4.0-57-generic.old-dkms
-rw-r--r-- 1 root root  18M Aug 27 18:51 initrd.img-4.4.0-59-generic.old-dkms
-rw-r--r-- 1 root root  18M Aug 27 18:52 initrd.img-4.4.0-62-generic.old-dkms
-rw-r--r-- 1 root root  18M Aug 27 18:52 initrd.img-4.4.0-64-generic.old-dkms
-rw-r--r-- 1 root root  18M Aug 27 18:53 initrd.img-4.4.0-71-generic.old-dkms
-rw-r--r-- 1 root root  18M Aug 27 18:53 initrd.img-4.4.0-72-generic.old-dkms
-rw-r--r-- 1 root root  18M Aug 27 18:53 initrd.img-4.4.0-75-generic.old-dkms
-rw-r--r-- 1 root root  18M Sep 23 11:33 initrd.img-4.4.0-78-generic.old-dkms
-rw-r--r-- 1 root root  39M Nov  4 17:00 initrd.img-4.4.0-98-generic  

...

and also, the old kernels are still listed as large installed packages by dpkg:

dpkg-query -W --showformat='${Installed-Size} ${Package}\n' | sort -nr | less

...

158659 linux-image-extra-4.4.0-47-generic
158555 linux-image-extra-4.4.0-36-generic
158443 linux-image-extra-4.4.0-34-generic
158201 linux-image-extra-4.4.0-31-generic
157559 linux-image-extra-4.4.0-53-generic
157559 linux-image-extra-4.4.0-51-generic
156386 linux-image-extra-3.19.0-77-generic
156386 linux-image-extra-3.19.0-75-generic
156385 linux-image-extra-3.19.0-74-generic
156384 linux-image-extra-3.19.0-68-generic
156384 linux-image-extra-3.19.0-66-generic
156384 linux-image-extra-3.19.0-65-generic
156383 linux-image-extra-3.19.0-64-generic
156380 linux-image-extra-3.19.0-61-generic
156178 linux-image-extra-3.19.0-33-generic
150341 linux-image-extra-4.4.0-57-generic
150205 linux-image-extra-4.4.0-62-generic
150198 linux-image-extra-4.4.0-59-generic
149214 linux-image-extra-4.4.0-101-generic
149191 linux-image-extra-4.4.0-98-generic
149156 linux-image-extra-4.4.0-96-generic
148953 linux-image-extra-4.4.0-72-generic
148953 linux-image-extra-4.4.0-71-generic
148940 linux-image-extra-4.4.0-64-generic
148663 linux-image-extra-4.4.0-87-generic
148621 linux-image-extra-4.4.0-78-generic
148598 linux-image-extra-4.4.0-75-generic

...

How can I fully clean my system of these old kernels?

marked as duplicate by N0rbert, karel, Eric Carvalho, WinEunuuchs2Unix, Charles Green Feb 7 '18 at 13:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

You need to purge the kernels instead of just remove.

A handy tool is purge-old-kernels which is shipped with the byobu package on Ubuntu 16.04.

0

Get a list of all kernel-related packages with apt list --installed | grep linux, and apt remove those you don't want. It's that simple. You cab use --purge if you want, but it should not have any significant effect in that case.

Not the answer you're looking for? Browse other questions tagged or ask your own question.