Removing Old Linux Kernels

Running some Linux machines for long periods of time can cause some older kernels to hang around on the /boot partition. As the /boot partition is small by design, this can cause a situation where space runs out. On my lab system, errors that have been created from this includes VMware Tools failing to load and package upgrade issues. Fortunately, the fix is not too difficult.
There are several different sites avaliable on this topic, but all very slightly.  Below is what worked well for me in my systems.

First, lets verify that the boot partition is actually full.

#check free space
df -h

Next, we need to verify what the current kernel is so we do not select it to be removed.

#check current kernel
uname -r

This was the kernel on my particular system.

3.2.0-59-generic

Now that we know what is currently being ran, we can determine what to remove.

#check what kernels are loaded
dpkg-query -l | awk '/linux-image-*/ {print $2}'

At this point, we can remove the unused kernels. This first example allows you to select specific kernels to remove.

#removes specific unused kernels
sudo apt-get --purge remove linux-image-3.8.0-29-generic

This section allows you to remove all unneeded packages.

#removes any unneeded packages including all unneeded kernels
sudo apt-get autoremove

 

Leave a Reply

Your email address will not be published. Required fields are marked *