Removing old Linux Kernels In Ubuntu

Ever get this on linux?

$ df -h /boot/
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 228M 228M 0M 100% /boot

Looks like ubuntu has been updating the kernels without cleaning itself up. Bad ubuntu! And it is terrible that the default boot partition is only 230MB. A quick google search gives me this one-liner:

$ dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | xargs sudo apt-get -y purge

Thanks tuxtweats!

**UPDATE**: You don’t have to do this anymore… You can now just do:

$ sudo apt-get autoremove

This will clean up old kernels. The only way this won’t work is if you’re at 100%. Then you have to clear a few old kernels out manually and then resume installation of the latest kernel, then run the autoremove command.

Leave a Reply

Your email address will not be published. Required fields are marked *