3

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?

1
  • 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, 2013 at 22:32

1 Answer 1

4

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

That should leave only 1 old kernel, in case the new kernel borks something.

5
  • 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. May 18, 2013 at 7:42
  • Okay, let me accept the answer as is (but you should fix the spacing-problem). May 18, 2013 at 19:51
  • Not my problem, SE is screwing up the spacing May 19, 2013 at 21:55
  • To get the functional code, click the edit button and copy-paste what's in the ```s May 19, 2013 at 21:56
  • Indeed amazing that SE messes up the spacing... thanks for pointing this out. May 19, 2013 at 22:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .