When the /boot partition is full, it might not be possible anymore to remove old kernel versions by just using apt. A full /boot partition can lead to problems during boot as well. In this case, the following error might be shown during apt operations that trigger an `update-initramfs`:

gzip: stdout: No space left on device
E: mkinitramfs failure cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-3.2.0-68-generic-pae with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return
code 1
Failed to process /etc/kernel/postinst.d at
/var/lib/dpkg/info/linux-image-3.2.0-68-generic-pae.postinst line 1010.

In order to free space from the /boot partition, you need to temporary move old kernel images to a different directory that is not in that partition. First check the Kernel Version that is currently running, and make sure not to remove it:

user@machine ~$ uname -r
user@machine ~$ cd /boot
user@machine /boot$ sudo mkdir ../backup-boot

Determine all Kernel Versions that are not required. This command will list all kernel header and image versions installed, except the currently running one:

user@machine /boot$ sudo dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'

Move all files named `*version-name*` to the backup directory:

user@machine /boot$ sudo mv *3.13.0-24* ../backup-boot
user@machine /boot$ df -ha | grep boot
Filesystem  Size  Used  Avail  Use%  Mounted on
/dev/sda1   228M  151M  65M    70%   /boot

Now that some space is free again, it is possible to remove unused kernels via apt. Do not try to remove kernels currently in the /backup-boot directory.

user@machine /boot$ sudo apt-get remove linux-headers-3.13.0-24 linux-image-3.13.0-24-generic linux-image-extra-3.13.0-24-generic

You can remove all unused kernel images via `apt-get autoremove` without having to select them indivudially. This however wont work if your /boot partition is already to full for `update-initramfs` to work properly. In this case, it is necessary to move some kernel images out of place to be able to work again.

Ubuntu does not automatically remove old kernel images. You can use this oneliner in a crontab entry to do that automatically:

user@machine ~$ sudo crontab -e
# append:
0 0 1 * * dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs apt-get -y remove

This will remove old kernels on the first day of every month at 12.00pm. Make sure that the computer is running at that time, if you are configuring a workstation.

When you want to do this on a server, make sure that the server has been rebootet to run the newest kernel available bevore doing this. Check, that the currently running kernel is then newest version available, otherwise the newest kernel will be listed and removed by the onliner command.

Tipp: Make a /boot partition no smaller than 1GB. With newer drives and ssd’s, 1GB of Space is no concern anymore. There is just no good reason anymore for a smaller /boot partition.