Not enough disk space on boot

Ubuntu never has enough free disk space on `/boot`, and when it doesn't have enough free disk space it won't update. This is the crazy command I run to fix it.

By on

Ever been greeted with this friendly error while attempting to apply regular old everyday updates to Ubuntu?

Not enough free disk space

The upgrade has aborted. The upgrade needs a total of 25.7 M free space on disk ‘/boot’. Please free at least an additional 25.7 M of disk space on ‘/boot’. Empty your trash and remove temporary packages of former installations using ‘sudo apt-get clean’.

Yeah. This shit happens to me all the time. You’d think it would be a solved problem and that a solution would be widely available, if not built in. But it’s not, so here’s how I fix it, via Ask Ubuntu:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge