No Space on the boot Partition

When I installed my Ubuntu Linux virtual machines I just let the installer do whatever it felt was right in terms of disk partitioning. In hindsight that was probably a mistake because it gave me a separate 256Mb boot partition. While this partition is large enough to store several kernels I do find myself running out of space about twice a year if I keep the servers up to date.

The problem with running out of space is that you can (and I have) find yourself in the position where you can’t complete the install of a new kernel but apt doesn’t have sufficient space on the drive to remove an old kernel. In that situation you have to start getting your hands dirty and carefully remove things by hand – not a fun experience. In order to prevent this situation from arising I now have a Webmin alarm set up to warn me if there is less than 20% free space available on the /boot partition and at that point I perform the following clean up procedure:

Start by confirming what kernel is currently running (you don’t want to remove this one):

uname -r

3.13.0-66-generic

Now list all the kernels that are installed on your system:

sudo dpkg --list 'linux-image*'

[sudo] password for username:
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==================================-======================-======================-==========================================================================
un linux-image <none> <none> (no description available)
un linux-image-3.0 <none> <none> (no description available)
rc linux-image-3.13.0-32-generic 3.13.0-32.57 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc linux-image-3.13.0-39-generic 3.13.0-39.66 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc linux-image-3.13.0-40-generic 3.13.0-40.69 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc linux-image-3.13.0-43-generic 3.13.0-43.72 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc linux-image-3.13.0-44-generic 3.13.0-44.73 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc linux-image-3.13.0-52-generic 3.13.0-52.86 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc linux-image-3.13.0-53-generic 3.13.0-53.89 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc linux-image-3.13.0-54-generic 3.13.0-54.91 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc linux-image-3.13.0-55-generic 3.13.0-55.94 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii linux-image-3.13.0-57-generic 3.13.0-57.95 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii linux-image-3.13.0-58-generic 3.13.0-58.97 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii linux-image-3.13.0-61-generic 3.13.0-61.100 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii linux-image-3.13.0-62-generic 3.13.0-62.102 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii linux-image-3.13.0-63-generic 3.13.0-63.103 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii linux-image-3.13.0-65-generic 3.13.0-65.106 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii linux-image-3.13.0-66-generic 3.13.0-66.108 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
iF linux-image-3.13.0-67-generic 3.13.0-67.110 amd64 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc linux-image-extra-3.13.0-32-generi 3.13.0-32.57 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rc linux-image-extra-3.13.0-39-generi 3.13.0-39.66 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rc linux-image-extra-3.13.0-40-generi 3.13.0-40.69 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rc linux-image-extra-3.13.0-43-generi 3.13.0-43.72 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rc linux-image-extra-3.13.0-44-generi 3.13.0-44.73 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rc linux-image-extra-3.13.0-52-generi 3.13.0-52.86 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rc linux-image-extra-3.13.0-53-generi 3.13.0-53.89 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rc linux-image-extra-3.13.0-54-generi 3.13.0-54.91 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rc linux-image-extra-3.13.0-55-generi 3.13.0-55.94 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii linux-image-extra-3.13.0-57-generi 3.13.0-57.95 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii linux-image-extra-3.13.0-58-generi 3.13.0-58.97 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii linux-image-extra-3.13.0-61-generi 3.13.0-61.100 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii linux-image-extra-3.13.0-62-generi 3.13.0-62.102 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii linux-image-extra-3.13.0-63-generi 3.13.0-63.103 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii linux-image-extra-3.13.0-65-generi 3.13.0-65.106 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii linux-image-extra-3.13.0-66-generi 3.13.0-66.108 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
iU linux-image-extra-3.13.0-67-generi 3.13.0-67.110 amd64 Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
iU linux-image-generic 3.13.0.67.73 amd64 Generic Linux kernel image

You are interested in the lines start “ii” as this indicates that the kernel is installed. The lines starting “rc” are just configuration files. Next remove the kernels that you no longer want. I was in the process of installing kernel 3.13.0-67 when I ran out of space so I’ll keep that one and 3.13.0.66 as that is what I’m using. Issue this command, changing the version number as needed to remove the older kernels:

sudo apt-get remove linux-image-3.13.0-57-generic

The above command produces quite a bit of output which I’ve not shown. Essentially though it removes the kernel and then updates the grub selection list.

Once you’ve removed all the old kernels run an autoremove to make sure there are no old packages hanging around. This isn’t strictly necessary but I like to do it:

sudo apt-get autoremove

Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Finally update grub. Again this isn’t usually necessary but if you ran out of space part way through a kernel install I’ve noticed it can sometimes need to be run manually after everything is fixed up.

sudo update-grub

Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.13.0-67-generic
Found initrd image: /boot/initrd.img-3.13.0-67-generic
Found linux image: /boot/vmlinuz-3.13.0-66-generic
Found initrd image: /boot/initrd.img-3.13.0-66-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
done

Additional Reading