I work with Ubuntu 13.04 ("64-bit PC (AMD64) desktop image"). On updates/upgrades, I quite often get messages of the type The volume "boot" has only 11 MB disk space. I then uninstall older kernel version to free some space on the boot partition.

Is it possible to automatically remove unused, older kernels when doing sudo apt-get upgrade?

  • If you're getting the volume "boot" has only 11 MB disk space message and don't know what the OP is talking about, this answer explains a non-automatic solution: askubuntu.com/questions/218783/… – Kevin Oct 3 '13 at 22:32

You could add system ("sudo apt-get remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)"); to some line in the apt source code for upgrading packages.

Alternatively, just make a script called aptupgrade and paste this in it: sudo apt-get remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`); sudo apt-get upgrade, which should leave only 1 old kernel, in case the new kernel borks something.

  • Thanks for helping. I realized that you need exactly 2 (!) spaces after ^ii to make it work (copy-pasting the above does not work as such); you might want to correct this. Also, why does it leave one old kernel (?) Doesn't it remove all except the current one? It would be great if you could add a word here. – Marius Hofert May 18 '13 at 7:42
  • Okay, let me accept the answer as is (but you should fix the spacing-problem). – Marius Hofert May 18 '13 at 19:51
  • Not my problem, SE is screwing up the spacing – Yet Another User May 19 '13 at 21:55
  • To get the functional code, click the edit button and copy-paste what's in the ```s – Yet Another User May 19 '13 at 21:56
  • Indeed amazing that SE messes up the spacing... thanks for pointing this out. – Marius Hofert May 19 '13 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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