I've just run out of disk space on /. Looking into the situation I realised that since first installing 12.04, Ubuntu has upgraded the kernel ~23 times and has kept every old kernel, binaries and header sources.
I've just manually apt-get purge
-ed all but the last couple, saving ~4Gb space (on a 20Gb partition, so that's v. significant). Why would Ubuntu want to keep all of those? Is it lack of a feature such as "keep last 4" or is there some other reason?
Ubuntu used to keep the old kernels around for safety reasons, however it should be autocleaning old kernels now.
The system should be auto cleaning old kernels per this bug:
So you might want to ensure that your system is up to date and that you have apt (0.9.7.5ubuntu5.5) installed. If you're still getting the wrong behavior then please report a bug on the apt package.
This is also useful if you want to clean up stuff:
You don't need to manually purge each kernel package, doing a
sudo apt-get autoremove
every once in a while will remove kernels you don't need anymore. However finding the root cause as to why your system isn't autocleaning old kernels is probably easier.