Random Stuff About Stuff

Ubuntu can't apt-get upgrade because boot partition is full

April 23, 2014

When trying to do an upgrade I got the error below

sudo apt-get upgrade  
Reading package lists... Done  
Building dependency tree   
Reading state information... Done  
You might want to run 'apt-get -f install' to correct these.  
The following packages have unmet dependencies:  
 linux-server : Depends: linux-headers-server (= 3.2.0.55.65) but 3.2.0.60.71 is installed  

E: Unmet dependencies. Try using -f.  
When you run sudo apt-get -f install as suggested you might get something like
sudo apt-get -f install  
gzip: stdout: No space left on device  
E: mkinitramfs failure cpio 141 gzip 1  
update-initramfs: failed for /boot/initrd.img-3.2.0-60-generic with 1.  
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1  
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-3.2.0-60-generic.postinst line 1010.  
dpkg: error processing linux-image-3.2.0-60-generic (--configure):  
 subprocess installed post-installation script returned error exit status 2  
Setting up linux-image-server (3.2.0.55.65) ...  
Setting up linux-headers-server (3.2.0.60.71) ...  
dpkg: dependency problems prevent configuration of linux-server:  
 linux-server depends on linux-headers-server (= 3.2.0.55.65); however:  
 Version of linux-headers-server on system is 3.2.0.60.71.  
dpkg: error processing linux-server (--configure):  
 dependency problems - leaving unconfigured  
No apport report written because the error message indicates its a followup error from a previous failure.  
 Errors were encountered while processing:  
 linux-image-3.2.0-60-generic  
 linux-server  
E: Sub-process /usr/bin/dpkg returned an error code (1)  

If you do a df you will probably see your boot partition is full.

Freeing up space seems to be no fun, to find the list of old images

sudo dpkg --list | grep linux-image  

ii linux-image-3.2.0-41-generic 3.2.0-41.66 Linux kernel image for version 3.2.0 on 64 bit x86 SMP  
ii linux-image-3.2.0-43-generic 3.2.0-43.68 Linux kernel image for version 3.2.0 on 64 bit x86 SMP  
ii linux-image-3.2.0-44-generic 3.2.0-44.69 Linux kernel image for version 3.2.0 on 64 bit x86 SMP  
ii linux-image-3.2.0-45-generic 3.2.0-45.70 Linux kernel image for version 3.2.0 on 64 bit x86 SMP  
ii linux-image-3.2.0-48-generic 3.2.0-48.74 Linux kernel image for version 3.2.0 on 64 bit x86 SMP  
ii linux-image-3.2.0-51-generic 3.2.0-51.77 Linux kernel image for version 3.2.0 on 64 bit x86 SMP  
ii linux-image-3.2.0-52-generic 3.2.0-52.78 Linux kernel image for version 3.2.0 on 64 bit x86 SMP  
ii linux-image-3.2.0-53-generic 3.2.0-53.81 Linux kernel image for version 3.2.0 on 64 bit x86 SMP  
ii linux-image-3.2.0-54-generic 3.2.0-54.82 Linux kernel image for version 3.2.0 on 64 bit x86 SMP  
iF linux-image-3.2.0-55-generic 3.2.0-55.85 Linux kernel image for version 3.2.0 on 64 bit x86 SMP  
iF linux-image-3.2.0-56-generic 3.2.0-56.86 Linux kernel image for version 3.2.0 on 64 bit x86 SMP  
iU linux-image-server 3.2.0.55.65 Linux kernel image on Server Equipment.  

Trying to remove the oldest one of these gives the error below

sudo apt-get purge linux-image-3.2.0-41-generic  
Reading package lists... Done  
Building dependency tree   
Reading state information... Done  
You might want to run 'apt-get -f install' to correct these:  
The following packages have unmet dependencies:  
 linux-server : Depends: linux-headers-server (= 3.2.0.55.65) but 3.2.0.60.71 is to be installed  
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).  

Get the current kernel and take note!

uname -r  
3.2.0-54-generic  

Make sure you don’t remove this image!

sudo dpkg -r linux-image-3.2.0-41-generic  

and

sudo dpkg --purge linux-image-3.2.0-41-generic  

Do this for a few of the older versions and you should have space again on the /boot partition

But you will now probably get

sudo apt-get -f install  
Setting up linux-image-server (3.2.0.60.71) ...  
dpkg: dependency problems prevent configuration of linux-server:  
 linux-server depends on linux-image-server (= 3.2.0.55.65); however:  
 Version of linux-image-server on system is 3.2.0.60.71.  
 linux-server depends on linux-headers-server (= 3.2.0.55.65); however:  
 Version of linux-headers-server on system is 3.2.0.60.71.  
dpkg: error processing linux-server (--configure):  
 dependency problems - leaving unconfigured  
No apport report written because the error message indicates its a followup error from a previous failure.  
 Errors were encountered while processing:  
 linux-server  
E: Sub-process /usr/bin/dpkg returned an error code (1)  

I’m not admin as you may have guessed but it’s a virtual server and I took a snapshot, anyway time to get nuclear on it.

sudo dpkg --remove --force-remove-reinstreq linux-image-server  
sudo dpkg --remove --force-remove-reinstreq linux-headers-server  
sudo dpkg --remove --force-remove-reinstreq linux-server  

Then run -f install again

sudo apt-get -f install  
Reading package lists... Done  
Building dependency tree   
Reading state information... Done  
The following packages were automatically installed and are no longer required:  
 linux-headers-3.2.0-44-generic linux-headers-3.2.0-52-generic linux-headers-3.2.0-41 linux-headers-3.2.0-43 linux-headers-3.2.0-44 linux-headers-3.2.0-45 linux-headers-3.2.0-51 linux-headers-3.2.0-52 linux-headers-3.2.0-53  
 linux-headers-3.2.0-48 linux-headers-3.2.0-45-generic linux-headers-3.2.0-53-generic linux-headers-3.2.0-48-generic linux-headers-3.2.0-43-generic linux-headers-3.2.0-51-generic linux-headers-3.2.0-41-generic  
Use 'apt-get autoremove' to remove them.  
0 upgraded, 0 newly installed, 0 to remove and 130 not upgraded.  

Progress at last, clean up the old packages by following it’s recommendation

sudo apt-get autoremove  

Try the install again

sudo apt-get -f install  
Reading package lists... Done  
Building dependency tree   
Reading state information... Done  
0 upgraded, 0 newly installed, 0 to remove and 130 not upgraded.  

You should now be in a happy state again, I found the below which should purge all the remaining old images, you might need to modify it if you want to keep more than the current

sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")  

Should be back to normal now and can perform ann update and upgrade.

sudo apt-get update  
sudo apt-get upgrade  

Written by David Kerwick who lives and works Dublin as a Java Technical Lead.