Ubuntu doesn’t remove old kernels when upgrading to new kernel versions, which is a great because sometimes there’s a compatibility problem and you want to roll back. If you don’t pay attention to free disk space, though, it’s really easy to fill up your boot partition which is only a couple hundred megs by default. When this happens, kernel upgrades start failing and apt may start throwing errors for all package operations, which isn’t fun. It’s relatively straightforward to recover from, but it happens infrequently enough that it always takes me too long to remember the details. Next time I’ll check here:
- Find the currently running kernel version, I never uninstall the currently running kernel in case there are compatibility issues with newer kernels:
- Find what kernel versions are installed. I generally keep the most recent 2-3 (plus the currently running kernel):
sudo dpkg --list | grep linux-image
- For each older kernel you want to remove:
sudo dpkg --purge linux-image-x.x.x-xx-generic \ linux-image-extra-x.x.x-xx-generic
You can do this with apt-get or aptitude as well, but dpkg is less likely to run into problems with broken dependencies or half-configured kernel installs (as is common if you discover this problem while upgrading your kernel).
- I almost always also have kernel headers installed. While they don’t take up space in /boot, they’re not needed once the old kernel is removed either. Might as well clean them up as well:
sudo dpkg --list | grep linux-headers sudo dpkg --purge linux-headers-x.x.x-xx \ linux-headers-x.x.x-xx-generic
- At this point apt-get can probably finish whatever installs/upgrades were in-flight when this issue started:
apt-get --fix-broken install
Now to set up free disk space monitoring so this doesn’t happen every few months.