Wednesday 13 March 2013

Remove unused kernels and headers from ubuntu server

Yet again I found my system clogged up with unused kernels and headers. This time I am making a note of the one-liner to remove the unused junk.

(Found at http://tuxtweaks.com/2010/10/remove-old-kernels-in-ubuntu-with-one-command/)

You can first check that the correct packages are selected to remove with;

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

and if you are happy remove those with this;

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


A word of warning, if you have installed a new kernel recently ensure you have rebooted since, and secondly ensure that your current kernel is not on the list of packages to remove of you will end up with a un-bootable system.

No comments:

Post a Comment