Ubuntu clean boot partition

Just a short note so we can remember how to remove excess (old) kernel packages from an Ubuntu installation.

For some reason default Ubuntu installations have a small /boot partition and after only a few updates it is full of old kernel packages. Here is how to remove the old ones:

First, figure out which running kernel you have:

uname -r

Do NOT remove that kernel!

Figure out which kernels you have installed

dpkg -l | grep linux-image | grep ii

Then remove them:

apt-get autoremove <package 1> <package 2>

 

Here is a way to do it in two lines. This is a little cleaner than the one line version. Also I deliberately don’t use -y on autoremove so I can see what is happening!

CURRENT=$(uname -r)
apt-get  autoremove `dpkg -l | grep linux-image | grep ii | grep -v $CURRENT | awk '{print $2}'`