I have 200 MB assigned for the /boot
partition. Whenever I try to update the kernel, I receive an error message that basically states /boot
is full.
What can I do to cleanup /boot
and remove/backup the older kernels?
I have 200 MB assigned for the /boot
partition. Whenever I try to update the kernel, I receive an error message that basically states /boot
is full.
What can I do to cleanup /boot
and remove/backup the older kernels?
Command line method:
First check your kernel version, so you won't delete the in-use kernel image, running:
Now run this command for a list of installed kernels:
and delete the kernels you don't want/need anymore by running this:
Replace VERSION with the version of the kernel you want to remove.
When you're done removing the older kernels, you can run this to remove ever packages you won't need anymore:
And finally you can run this to update grub kernel list:
NOTE: this is only if you can't use apt to clean up due to a 100% full /boot
If apt-get isn't functioning because your /boot is at 100%, you'll need to clean out /boot first. This likely has caught a kernel upgrade in a partial install which means apt has pretty much froze up entirely and will keep telling you to run
apt-get -f install
even though that command keeps failing.Get the list of kernel images and determine what you can do without. This command will show installed kernels except the currently running one
sudo dpkg --list 'linux-image*'|awk '{ if ($1=="ii") print $2}'|grep -v `uname -r`
. Note the two newest versions in the list. You don't need to worry about the running one as it isn't listed here. You can check that withuname -r
.Craft a command to delete all files in /boot for kernels that don't matter to you using brace expansion to keep you sane. Remember to exclude the current and two newest kernel images. Example:
sudo rm -rf /boot/*-3.2.0-{23,45,49,51,52,53,54,55}-*
. You can also use a range with the syntax {80..84}.sudo apt-get -f install
to clean up what's making apt grumpy about a partial install.If you run into an error that includes a line like "Internal Error: Could not find image (/boot/vmlinuz-3.2.0-56-generic)", then run the command
sudo apt-get purge linux-image-3.2.0-56-generic
(with your appropriate version).Finally,
sudo apt-get autoremove
to clear out the old kernel image packages that have been orphaned by the manual boot clean.Suggestion, run
sudo apt-get update
andsudo apt-get upgrade
to take care of any upgrades that may have backed up while waiting for you to discover the full /boot partition.Suggestion2, Review https://help.ubuntu.com/community/AutomaticSecurityUpdates and consider setting Unattended-Upgrade::Remove-Unused-Dependencies to true in /etc/apt/apt.conf.d/50unattended-upgrades. This will be the equivalent of running autoremove after each security updates to be sure you clean out unused kernels but will also remove other things it thinks are unused saving you from this problem in the future.
There is documentation about this at https://help.ubuntu.com/community/RemoveOldKernels
In summary: Use
The
purge-old-kernels
tool can be installed viasudo apt install byobu
. Here is the description from its man-page:If you want a copy-paste solution, ReSearchIT Eng suggested the following:
I found that it is far easier to abandon the small partition and move
/boot
to the root. This also prevents any out of space issues in the future.First move your data from the boot partition to root (run as
sudo -s
):Remove (or comment) the
/boot
entry in/etc/fstab
:Update grub and make sure everything is correct:
apt
should now be able to upgrade without problems.This leaves an unused 200mb partition (which you could use for something else if you find it worth the trouble).
Removing old Kernels (to free space on /boot) see: http://askubuntu.com/questions/89710/how-do-i-free-up-more-space-in-boot
Then run
sudo apt-get autoremove
This removes all but last 2 kernels. Tested on Ubuntu 16.04 LTS when
/boot
was at 100% capacity andapt-get upgrade
failed it's last kernel upgrade. The kernel autoremove is iterative, so if you've got several kernels, they'll be removed one at a time. So be patient.Why do it by hand when you can do it with a tool? You know you're going to need it again in 30 seconds, because it takes 30 seconds for them to push a new kernal update these days =P
I recommend using this tool, bootnukem
Then
Remove
--dry-run
once you confirm it looks safethe short answer is to use my script: ubuntu-kernel-cleanup