How To Fix A Full /boot Partition on Linux

How To Fix A Full /boot Partition on Linux

Utilities such as apt-get generally install kernel updates by adding the new kernel to the Linux boot list and set it as the default. This means that the next time the system boots, the new kernel will be loaded. The problem is that the old kernel is still there (just incase the new one doesn’t work, you’ve got a fall back!), and the kernel before that, and the kernel before that…

The current 3.x kernel for Ubuntu is around 20MB so it doesn’t take long for the kernel updates to fill a tiny 200-or-so-Mb boot partition where they are stored.

The good news is that it’s easy to clear out the old updates, but it’s important to not remove the latest one that you’re using.

Which Kernel am I Running?

It’s quick and easy to see which kernel version you are running. Use the uname command with the -a switch and pay attention to the version numbers reported.

1

2

uname-a

3.19.0-47-generic

This shows that you’re using version 3.19.0-47.

List Currently Installed Kernels

Next you’ll need to list the kernel packages that are currently installed so that you can remove any outdated ones to free up the space on the /boot partition.

Run the below dpkg command to list the installed kernel packages and their versions.

1

dpkg--list'linux-image*'

The above output shows several versions of kernel that are all taking up space on the /boot partition however we only really need the current running version given by the above uname -a command. It’s a good idea to keep the last 2 kernels just incase you notice an issue down the line, but the above list is quite excessive.

Remove Unused Kernel Packages to Free Space on /boot

Once you’ve identified your current kernel and the kernel packages you have installed it’s time to remove the ones you don’t need.

Using apt-get enter the package names of the kernel packages to remove.

1

apt-getremove linux-image-3.19.0-25-generic

If you get an error running this command then see the next section.

note: the above screenshot of the installed packages cropped the full version name – it’s missing the generic part. You can use tab completion with the apt-get command, or use an asterisk after the version number to remove the required package.

Errors Removing Packages

If you get an error warning about dependencies similar to the below then you may need to manually remove a few kernel packages to free up some space.

1

2

3

4

5

6

7

8

9

10

[root@server:~]$apt-get remove linux-image-extra-3.19.0-25-generic

Reading packagelists...Done

Building dependency tree

Reading state information...Done

You might want torun'apt-get -f install'tocorrect these:

The following packages have unmet dependencies.

linux-image-generic-lts-vivid:Depends:linux-image-3.19.0-49-generic but it isnotgoing tobe installed

Depends:linux-image-extra-3.19.0-49-generic but it isnotgoing tobe installed

The problem here is that the original update failed to install the latest version of the kernel (version 3.19.0-49-generic in this case) and apt-get doesn’t like doing anything else until that problem has been resolved.

First we need to free up some space. Carefully delete 2 of the older kernel packages with a command similar to the below, but with old version numbers from your system returned by the above section List Currently Installed Kernels.

1

2

rm/boot/*-3.19.0-25*

rm/boot/*-3.19.0-33*

Check and double check this command because there’s no going back once it’s ran! It’s perfectly safe to do as long as you are using old version numbers that you’re no longer using.

You can now run apt-get to complete the original upgrade now that it has the space. This will remove the error when trying to remove the unused kernel packages in the above section.

1

apt-get install-f

Now go back to the above section and remove the old kernel packages that you no longer need.

And there are other kernels in the dpkg
I didn’t rebooted the machine because is in production, hope with apt-get upgrade and a reboot all of this will go away.
I’m just asking if it unsafe or the machine will not boot at all if the kernel files from /boot are not in sync with the dpkg list or even if the current kernel version isn’t present in the boot folder?

James Coyle

31-May-2017 at 11:56 am

You need to run apt-get install -f to resolve the dependencies, and ensure that at least one kernel is installed. You don’t need to have the current running kernel installed, but you do need to have at least one available.

raul

So in this case I’ll backup all the things and reboot the machine at a low traffic hour and hope it reboots. There are some worrying discrepancies between /boot folder contents, dpkg listing and current uname -a.

Thanks a lot and hope it helps others too…

James Coyle

31-May-2017 at 1:19 pm

Good luck!

Sandeep

1-Jun-2017 at 11:25 am

I was randomly googling the issue I faced on boot disk full and stumbled upon your website. It was spot on. Your steps solved my issue in 5 minutes. Thank you so much.

jhice

Dan

Jac

16-Dec-2018 at 2:39 am

Thank you man! After trying 6 other useless commands and solutions, This is the cleanest written solution to this problem that was easy to comprehend and implement.. and it worked! Thank you so much, Im finally able to upgrade this f*ing box.