/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.
- 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.
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:
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.
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.
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:
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>‘
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.