Why does Ubuntu keep the old vmlinuz files? Is it safe to delete them?

0

1

So, I was deeply annoyed by the multiple boot options on rEFInd bootup (I run about 6 OSes on my mac, plus some on a USB), and I thought to myself: "Why on earth do they keep multiple boot options for one OS? Wouldn't it be easier to just have the new one, assuming it's properly tested? After all, they do test these things, so, why keep the old one laying around if it'll just keep the boot option up? Can I get rid of them to ease my OCD?

Addison Crump

Posted 2015-07-15T15:45:41.467

Reputation: 170

They can't test every single hardware setup and every set of programs with each possible configuration. New kernels are sometimes buggy. – gronostaj – 2015-07-15T15:51:58.447

Answers

1

I generally recommend keeping at least two kernels for each Linux distribution. This is especially true when installing a new one; occasionally a new bug creeps in, or a filesystem error occurs, which causes a new kernel to not work. In such cases, having an older kernel around as a backup can greatly simplify recovery.

That said, you can limit the number of kernels on an Ubuntu system by doing:

sudo apt-get autoremove

This command will remove packages that were pulled in automatically by packages you've since removed. It will also remove all but two or three kernels, at least in most cases. (Sometimes it seems to leave more, but I'm not sure why.) It's possible to remove more kernels by using dpkg, but that's a little more tedious. You can simply use rm to delete kernels in /boot, but that creates package/filesystem inconsistencies, which are generally best avoided. (Such issues won't cause your system to blow up, but they might cause warnings when adding or deleting packages in the future.)

FWIW, I'm rEFInd's developer, and a feature that I've been wanting to add for a while is one to "fold" multiple kernels in a single directory into one icon on the rEFInd menu. Such a feature would not address the problem of having too many kernels installed (and it can be a problem if you've got a separate /boot partition), but it will help de-clutter the rEFInd menu. I hope to add this feature soon, but I can't make any promises about precisely when that will happen.

Rod Smith

Posted 2015-07-15T15:45:41.467

Reputation: 18 427

Ehhm... sorry, but this is NOT my experience of Ubuntu 14.04.x and kernels. I have to manually purge the items listed by dpkg --list | grep -E ' linux-[a-z]+-[0-9.-]+' while excluding the ones matching the version of uname -r. =>> sudo apt-get purge ... – Hannu – 2015-07-15T16:49:12.493

sudo apt-get autoremove works for me. It won't remove the first kernel installed (the default one for whatever you installed), the one you're currently using, and often one more; but past three installed, it usually deletes the rest. This assumes they were installed via normal sudo apt-get update && sudo apt-get dist-upgrade processes; if you explicitly installed certain kernels, sudo apt-get autoremove won't remove them. – Rod Smith – 2015-07-15T16:53:44.537

This is just the answer I was looking for, thanks! Also, since you're here, and because I was just about to post another question about it:: I read the tutorial on how to disable certain items from appearing at boot, but I couldn't figure out how to disable the ones that say stuff like "Boot Linux from 43gb Volume" or "Boot Linux from Whole Drive", as neither of these work for me. Is there a more thorough explanation as to how to do this that I can find somewhere? – Addison Crump – 2015-07-15T17:19:58.347