Cleaning up the Ubuntu boot volume
Cleaning up the Ubuntu boot volume

If you've been using an apt update && apt upgrade-ing a linux system for a while, at some you've probably seen this error:

Purging configuration files for linux-image-extra-3.13.0-96-generic (3.13.0-96.143) ...
(Reading database ... 520779 files and directories currently installed.)
Preparing to unpack .../linux-image-3.13.0-117-generic_3.13.0-117.164_amd64.deb ...
Unpacking linux-image-3.13.0-117-generic (3.13.0-117.164) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-3.13.0-117-generic_3.13.0-117.164_amd64.deb (--unpack):
 cannot copy extracted data for './boot/vmlinuz-3.13.0-117-generic' to '/boot/vmlinuz-3.13.0-117-generic.dpkg-new': failed to write (No space left on device)
No apport report written because the error message indicates a disk full error
                                                                              dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.13.0-117-generic /boot/vmlinuz-3.13.0-117-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.13.0-117-generic /boot/vmlinuz-3.13.0-117-generic
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

That's right, the boot volume is full. What do we do?

We'll if you're also getting an unmet dependency error, like:

You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
 linux-generic : Depends: linux-headers-generic (= but is installed
 linux-image-extra-3.13.0-117-generic : Depends: linux-image-3.13.0-117-generic but it is not installed
 linux-image-extra-3.13.0-96-generic : Depends: linux-image-3.13.0-96-generic but it is not installed
 linux-image-generic : Depends: linux-image-3.13.0-117-generic but it is not installed
E: Unmet dependencies. Try using -f.

You'll need to delete some stuff off your boot volume before apt will run.

Start by figuring out what kernels you have installed (run all as sudo):

dpkg --list 'linux-image-[^e]*' | grep ^ii | awk '{print $2}' | sort | egrep "[0-9]-generic"; echo ""

Now find the range for all but the two most recent:

dpkg --list 'linux-image-[^e]*' | grep ^ii | awk '{print $2}' | sort | egrep "[0-9]-generic" | tail -n +3 |tr '\n' ' '; echo ""

And delete all but the two most recent kernels off your boot volume, where 60..93 is the range of kernel versions you have installed (except for the two most recent). This will free up the space we need on /boot to run apt.

rm -rf /boot/*-3.13.0-{60..93}-*

Then use apt to remove them:

apt remove -y $(dpkg --list 'linux-image-[^e]*' | grep ^ii | awk '{print $2}' | sort | egrep "[0-9]-generic" | tail -n +3 |tr '\n' ' '; echo "")

Finally, just in case you accidentally removed the current kernel in one of the above steps, make sure it's installed with:

apt install -y linux-image-$(uname -r)

Now you should be able to apt update && apt upgrade again!

Hope this was helpful. If so, feel free to checkout my YouTube channel, get updates when a new article is posted by following on Feedly and read the the other guides at
comments powered by Disqus