Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got 200 MB assigned for the /boot partition. Everytime I try to update the kernel I get an error message that basically says the size of /boot is full.

What can I do to cleanup /boot and remote/backup the older kernels?

share|improve this question
up vote 122 down vote accepted

Command line method:

First check your kernel version, so you won't delete the in-use kernel image, running:

uname -r

Now run this command for a list of installed kernels:

sudo dpkg --list 'linux-image*'

and delete the kernels you don't want/need anymore by running this:

sudo apt-get remove linux-image-VERSION

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:

sudo apt-get autoremove

And finally you can run this to update grub kernel list:

sudo update-grub
share|improve this answer
3  
the command line worked like a charm, thanks! – koba101 Sep 15 '13 at 15:04
19  
sudo dpkg --list 'linux-image*' | grep ^ii makes it a little easier to see just the installed kernels. Also I think the update-grub is harmless but not strictly necessary, that is run automatically when you uninstall a kernel. – Nelson Mar 5 '14 at 16:15
3  
Use sudo dpkg --list 'linux-image*' | grep ^ii | awk '{print $2}' | sort | egrep "[0-9]-generic" | head -n -3 | tr '\n' ' '; echo "" to get the list of package names to be used with sudo apt-get remove. head -n -3 is used to keep 3 most recent kernels left in the system. – Sithsu Nov 16 '14 at 6:31
    
my simple one liner: apt-get remove `dpkg --list 'linux-image*' |grep ^ii | awk '{print $2}'\ | grep -v \`uname -r\`` – gcb Mar 1 '15 at 20:49
    
You can use awk to do one of the greps, but I can't find a way around the backticks in awk for the other one: sudo dpkg --list 'linux-image*'|awk '{ if ($1=="ii") print $2}'|grep -v `uname -r` – flickerfly Jul 15 '15 at 18:03

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 with uname -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}-*.

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 and sudo 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.

share|improve this answer
    
May I ask why to exclude the last two newest kernel images? – nightire Apr 22 '14 at 2:37
2  
This way I have the latest for the next reboot and then the one before just in case something breaks in that one. Usually I have plenty of room so it doesn't hurt to have a few and it satisfies my paranoia for not having enough backup options in any given scenario. – flickerfly Apr 22 '14 at 6:32
    
Great answer! Do you think it's completely safe to enable Unattended-Upgrade::Remove-Unused-Dependencies? – mkataja Apr 15 '15 at 9:50
2  
After seeing this in several vsphere virtual servers (where kernels were being automatically upgraded but not removed afterward), I wrote a python script to automate it. I'd love to have more eyes on it – EvanK Sep 29 '15 at 23:39
1  
If you use dpkg --purge on a full boot you'll get the following $ sudo dpkg --purge linux-image-3.13.0-65-generic dpkg: dependency problems prevent removal of linux-image-3.13.0-65-generic: linux-image-extra-3.13.0-65-generic depends on linux-image-3.13.0-65-generic. dpkg: error processing package linux-image-3.13.0-65-generic (--purge): dependency problems - not removing Errors were encountered while processing: linux-image-3.13.0-65-generic – flickerfly Feb 12 at 22:58

This one-liner from http://ubuntuforums.org/showthread.php?t=1435818 did the trick for me

dpkg --get-selections|grep 'linux-image*'|awk '{print $1}'|egrep -v "linux-image-$(uname -r)|linux-image-generic" |while read n;do apt-get -y remove $n;done

However, this only worked once! The second time I ran it, my computer no longer had a kernel (see comment below). Be careful with this command as I spent about 10 hours figuring out what happened and then replacing the kernel.

share|improve this answer
1  
This will remove the current linux-image-extra and the version-less linux-image-server. I would suggest using dpkg --get-selections | grep 'linux-image.*-[0-9].*' | awk '{print $1}' | egrep -v "$(uname -r)" look at the list carefully and only then append | while read n; do apt-get -y remove $n; done – canaaerus Aug 3 '14 at 10:29
    
Thanks for your input, I wish I knew why this only worked once – Paul Gregoire Aug 3 '14 at 16:08

protected by Community Jan 21 at 14:21

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.