Is it safe to delete the old kernels from menu.lst? [duplicate]

When the computer starts, GRUB shows a long list of previous kernels in addition to the usual stuff, e.g.

Ubuntu 10.10, kernel 2.6.35-23-generic
Ubuntu 10.10, kernel 2.6.35-23-generic (recovery mode)
Ubuntu 10.10, kernel 2.6.35-22-generic
Ubuntu 10.10, kernel 2.6.35-22-generic (recovery mode)
[6 more similar]
Ubuntu 10.10, memtest86+
Other operating systems:
Dell Utility Partition
Windows Vista (loader)

Is it safe to delete those extra "Ubuntu 10.10, kernel" lines from /etc/grub/menu.lst? Currently I have commented-out from the third one up to (not including) memtest86. But I wonder if they are ever needed for a particular reason?


Safe but pointless. The next time update-grub runs, they'll probably pop back up.

Kernels are installed as packages and so can be removed like other packages. The massive benefit over just hitting on grub is you will free up hundreds of megabytes of disk space.

They used to be installed as non-auto but can now be safely removed with:

sudo apt-get autoremove

If you have manually installed kernels and various auxiliary packages, you can see the kernel versions installed with this command:

dpkg -l | awk '$2~/linux-(im|he|to).+[0-9]/ {print $2}'

And that'll show you something like this:

linux-headers-3.13.0-24
linux-headers-3.13.0-24-generic
linux-image-3.13.0-24-generic
linux-image-extra-3.13.0-24-generic

From there you can remove things using sudo apt-get purge <package-name>. Just make sure you don't remove your current or latest kernel (uname -a to see what version you're on) and I agree with what other have said, keep the next newest one in case things blow up.

Here's my best effort at detecting and performing this safely:

current=$(uname -r)
kernels=( /lib/firmware/[0-9].* )

dpkg -l | awk '$2~/linux-(im|he|to).+[0-9]/ {print $2}' \
| grep -Ev "$current|${kernels[-1]##*/}" \
| xargs sudo apt-get purge

Notes: This will still trample over tricky situations. It'll remove things like linux-image-generic if you have a HWE stack installed. This may or may not be a big issue for you. Those packages (though they look important) won't cascade-delete your entire desktop. You'll be left with the current (because it works) and the highest version kernels. That may be one and the same if you've rebooted recently.


Yes. But i recommend leaving the previous one in there, just in case the default one you have gives any kind of weird problem. If you happen to have at least a full week of testing with no problem you can delete the old ones and update the configuration of grub. Or if you just want to NOT SEE the other version then just simply edit the grub.cfg file and remove the options for the menu there without removing the actual old kernel. That way you have them just in case. Besides the kernel is not that big to worry about hehe.


Yes it's safe. But do it only if you're sure the latest kernel works fine. Also keep old kernel so you can manually boot them if something goes wrong.