Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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:… – Kevin Oct 3 '13 at 22:32
up vote 4 down vote accepted

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.

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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