How to fix an out of space /boot partition?

Introduction

/boot is part of the critical partition to any Linux flavor, it exists so that we can boot the Linux System using the kernels that are installed in there. Often times we tend to forget about the /boot partition or some may size the boot partition too small until the disk space in the /boot partition is full or out of space. In Ubuntu, you may find the below message when you are trying to update or install a package:

The “No space left on device” message is the catch message here. In this screenshot, it tried to generate a new ramfs for the system but unable to do so.

In this tutorial, you will find a way on how to fix this “no space left on device” and be able to install the latest kernel.

Prerequisites

  • This tutorial only applies to Ubuntu Linux OS
  • If you are doing this on a production OS, please do a backup. A good riddance to always make sure you have a backup all the time.

Step 1:

Let’s do a few checks first to confirm that is in fact the /boot partition is at 100% by issuing this command:

df -h | grep boot

With this you know that it is at 100% almost full but yet unable to generate a new ramfs for the system. Let’s see what the files are inside the /boot partition by issuing the command:

ls -la /boot

You see a bunch of kernels that are installed but why there are so many kernels? It seems that by default Ubuntu when doing an update will install the latest kernel but not removing the old kernels. Let’s check which kernel this Ubuntu system is using. You may issue the command:

‘uname -ar’

You see that the system is currently using the 4.4.0-66-generic kernel in which the boot partition contains the latest kernel is at 4.4.0-150-generic version.

Step 2:

The cleaning act. You have to remove the unwanted kernel, the official way is to use the command ‘apt-get autoremove‘ or ‘apt-get remove <package name>‘ but what happen if you use that command for the first run:

You ran into the same problem where there is “no space left on device” and unable to remove the unused kernels and update to the latest one.

This is where the hacking part needs to be done :

WARNING BEFORE PROCEEDING, HAVE YOU BACKUP YOUR SYSTEM?

You need to make some more space available to the /boot partition but how? You can either resize the /boot partition if it’s part of a LVM or userspace. Or you can delete some of the older files. Let’s choose the later one.

To delete the old unused kernel files, you have to remove them manually by using the ‘rm -fr‘ command.

cd /boot

rm -fr *137* *148*

The above command will change the directory to /boot and then removing any files that have 137 and 148 in the filenames. You do not remove the kernel that is currently being used by the system. Once you have done that, you are safe to execute the following:

apt-get autoremove

Once you have completed and no additional errors, you may proceed in uninstalling the unused kernel by using the command ‘apt-get remove <package name>

Conclusion:

In this tutorial, you have learned on how to resolve the out of disk space on the /boot partition. Moving forward do not forget to always clean or maintain the packages in your system.

Author:

I have been in love with computer since I was like seven years old and now doing the things that I love to do @ Wowrack. First in-love with how computer ran, and then starting to hack few games back then with MS-DOS, started to code (the first xDSL provisioning system in an ISP company), jump into the sea of network devices and now doing some automation as well as big data. Currently, serving employees and customers at https://www.wowrack.co.id We'll see what else will come up in the next few years.

Leave a Reply

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