fbpx

For Ubuntu installations (prior to Ubuntu version 15.10) with separate / boot partition , it may fill up after installing several updates . The issue occurs because older kernel versions are not automatically removed. In this article, we’ll show you how to manually uninstall older kernel versions, freeing up space in the / boot partition.

Problem

Installing new kernel versions using apt-get upgrade will result in more and more kernel versions in / boot over time. Calling apt-get autoremove should automatically remove older kernel versions. However, due to a bug, kernel packages are marked as manually installed , preventing automatic removal of older kernel versions. [1] [2] [3]

Affected systems:

  • Ubuntu before Ubuntu 15.10 (so Ubuntu 12.04 LTS , Ubuntu 14.04 LTS )

Workarounds

Manually uninstall old kernels

You can uninstall older kernel versions manually.

To do this, first call up the list of installed packages (in the example here we show an Ubuntu 14.04 with kernel version 3.13. *):

user @ ubuntu-14-04: ~ $ dpkg -l | awk '{print $ 2}' | grep -i 3.13
linux-headers-3.13.0-67
linux-headers-generic-3.13.0-67
linux-headers-3.13.0-68
linux-headers-generic-3.13.0-68
linux-headers-3.13.0-74
linux-headers-generic-3.13.0-74
linux-image-generic-3.13.0-67
linux-image-generic-3.13.0-68
linux-image-generic-3.13.0-74
linux-image-extra-3.13.0-67-generic
linux-image-extra-3.13.0-68-generic
linux-image-extra-3.13.0-74-generic
linux-image-signed-3.13.0-67-generic
linux-image-signed-3.13.0-68-generic
linux-image-signed-3.13.0-74-generic

Now query the currently used kernel version (in the example 3.13.0-74). This kernel version must NOT be removed!

user @ ubuntu-14-04: ~ $ uname -a
Linux ubuntu-14-04 3.13.0-74-generic # 118-Ubuntu SMP Thu Dec 17 22:52:10 UTC 2015 x86_64 x86_64 x86_64 GNU / Linux

You can now remove older kernel versions with sudo apt-get purge …. Enter all packages. Make sure that you only remove packages from the older kernel versions and leave the packages of the currently used version . In the example here we remove the packages from the older kernel version 3.13.0-67:

user @ ubuntu-14-04: ~ $ sudo apt-get purge linux-headers-3.13.0-67 linux-headers-3.13.0-67-generic linux-image-3.13.0-67-generic linux-image- extra-3.13.0-67-generic linux-signed-image-3.13.0-67-generic

apt-mark and apt-get autoremove

Alternatively, you can mark the kernel packages incorrectly marked as manually installed as automatically installed :

sudo apt-mark auto $ (dpkg -l | grep -e "^ ii" | awk '{print $ 2}' | grep -e linux-signed-image -. * - generic -e linux-image -. * - generic -e linux-headers -. * - generic)

Then check which kernel you are currently using and which kernel versions would be preserved after an apt-get autoremove :

uname -r
cat /etc/apt/apt.conf.d/01autoremove-kernels

Example:

wfischer @ ubuntu-14-04: ~ $ uname -a
Linux ubuntu-14-04 3.13.0-95-generic # 142-Ubuntu SMP Fri Aug 12 17:00:09 UTC 2016 x86_64 x86_64 x86_64 GNU / Linux
wfischer @ tpw: ~ $ cat /etc/apt/apt.conf.d/01autoremove-kernels
// DO NOT EDIT! File autogenerated by /etc/kernel/postinst.d/apt-auto-removal
APT :: NeverAutoRemove
{
   "^ Linux-image-3 \ .13 \ .0-87-generic $";
   "^ Linux-image-3 \ .13 \ .0-95-generic $";
   "^ Linux-headers-3 \ .13 \ .0-87-generic $";
   "^ Linux-headers-3 \ .13 \ .0-95-generic $";
   "^ Linux-image-extra-3 \ .13 \ .0-87-generic $";
   "^ Linux-image-extra-3 \ .13 \ .0-95-generic $";
   "^ Linux-signed-image-3 \ .13 \ .0-87-generic $";
   "^ Linux-signed-image-3 \ .13 \ .0-95-generic $";
   "^ Kfreebsd-image-3 \ .13 \ .0-87-generic $";
   "^ Kfreebsd-image-3 \ .13 \ .0-95-generic $";
   "^ Kfreebsd-headers-3 \ .13 \ .0-87-generic $";
   "^ Kfreebsd-headers-3 \ .13 \ .0-95-generic $";
   "^ Gnumach-image-3 \ .13 \ .0-87-generic $";
   "^ Gnumach-image-3 \ .13 \ .0-95-generic $";
   "* ^ - modules-3 \ .13 \ .0-87-generic $.";
   "* ^ - modules-3 \ .13 \ .0-95-generic $.";
   "* ^ - kernel-3 \ .13 \ .0-87-generic $.";
   "* ^ - kernel-3 \ .13 \ .0-95-generic $.";
   ". ^ Linux-backports-modules - 3 \ .13 \ .0-87-generic $ - *";
   ". ^ Linux-backports-modules - 3 \ .13 \ .0-95-generic $ - *";
   "^ Linux-tools-3 \ .13 \ .0-87-generic $";
   "^ Linux-tools-3 \ .13 \ .0-95-generic $";
};
wfischer @ ubuntu-14-04: ~ $ 

If the currently used kernel is preserved (this should always be the case), remove the older kernel packages with the following command:

sudo apt-get autoremove --purge
Categories: Tutorials

0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: