Free space on /boot path in Linux

When executing apt-get upgrade on my Linux machine I got the error that it could not execute because the /boot folder was full. And indeed, when executing du -h there was only 3% of space left on /boot.

As it turns out, there are old kernels stored in /boot, limiting me from updating. Since I only use the latest one the older versions can be removed.

This link explains in simple steps how to find and remove the older kernel versions.

The summary of the page above is to execute the command below (at your own risk!). First execute the dry-run to check what is removed:

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | grep -E "(image|headers)" | xargs sudo apt-get --dry-run remove

If everything checks out run:

dpkg -l linux-* | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | grep -E "(image|headers)" | xargs sudo apt-get -y purge