Not enough disk space to update linux

Thu, 05/14/2015 - 18:04

I sometimes get an error from the package manager when trying to update my system. The error reports that I don't have enough disk space. I'm running Xubuntu 14.04. Here's the solution I found.

Cause

The reason I get the error is that the update contain a new linux kernel, which needs to be install in the /boot partition. This partition is relvatively small and the old kernels are not deleted automatically.

Solution

2017-01-13 Update: I'm not sure when this feature became available but om my Ubuntu 16.04 I can now do sudo apt autoremove which will remove old unused linux headers.

There are two solutions. You can increase the /boot partition or you can delete the old kernels. Increasing the partition is not a good idea. Either you make it too small and you will soon run into this problem again, or you end up taking disk space away from other partitions, such as you home directory (where you probably keep your images and music, etc.).

The second solution is what I'm doing. Here's how. For the last part I assume you know how to use the terminal.

Find the current kernel.

First you need to know your current kernel. If you use conky it might be listed there. If not you can use this command:

$ uname -r
3.13.0-30-generic

As you can see I have the 3.13.0-30-generic kernel.

Find installed kernels.

Next you need to list all the installed kernels

$ dpkg --list | grep linux-image 

I had the following:

linux-image-3.13.0.27-generic (3.13.0.27.50)
linux-image-3.13.0.29-generic (3.13.0.29.53)
linux-image-3.13.0.24-generic (3.13.0.24.47)
linux-image-3.13.0.30-generic (3.13.0.30.55)
linux-image-extra-3.13.0.27-generic (3.13.0.27.50)
linux-image-extra-3.13.0.29-generic (3.13.0.29.53)
linux-image-extra-3.13.0.24-generic (3.13.0.24.47)
linux-image-extra-3.13.0.30-generic (3.13.0.30.55)

A recommendation from askubuntu.com says to alway keep at least two kernels. So I will remove 3.13.0.24-generic and 3.13.0.27-generic while keeping 3.13.0.29-generic and 3.13.0.30-generic.

Removing a kernel.

To remove a kernel you only need to remove the linux-image-* and the associated linux-image-extra-* will also be removed. To do this use this command:

$ sudo apt-get purge linux-image-3.13.0.24-generic 

Final comments

You can find different one liners that will find all the old kernels and remove them automatically. These are great, but you have to be cautious when executing commands you found online. You shouldn't blindly trust everything. At least try to understand the commands before executing them. For example you can use the man pages by typing for example man dpkg to check what it does.

Best of luck.