Thursday, June 7, 2018

Cleanup /boot partition on Ubuntu



First check your kernel version, so you won't delete the in-use kernel image, running:
uname -r
Now run this command for a list of installed kernels:
dpkg --list 'linux-image*' | grep ^ii
and delete the kernels you don't want/need anymore by running this:
sudo apt-get remove linux-image-VERSION
Replace VERSION with the version of the kernel you want to remove.
When you're done removing the older kernels, you can run this to remove ever packages you won't need anymore:
sudo apt-get autoremove
And finally you can run this to update grub kernel list:
sudo update-grub
Following command is derived from the above post and customized for my own needs:
dpkg --list 'linux-image*' | grep ^ii | awk '{print "apt-get remove " $2}' | grep -v extra|sort| egrep "[0-9]-generic"|head -n -3