17

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?

0

5 Answers 5

19

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.

3
  • 1
    I always come back to this answer... thanks a lot again!
    – ecoologic
    Jan 20, 2013 at 0:48
  • @ecoologic if you keep having to come back, you could use the "clean up old kernels" functionality in Unity Tweak. Not necessary since the above works well, but not something that one needs to remind oneself how it works, either.
    – Jon Hanna
    May 2, 2014 at 9:26
  • 1
    @ecoologic, As for removing older kernels, check out these scripts You can save scripts in executable files for easy access.
    – jarno
    May 3, 2015 at 16:50
9

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.

1
  • Yes, leaving the previous one is probably a good idea. Dec 14, 2010 at 21:57
1

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.

0

Well the memtest and the current kernel and current kernel recovery mode should be left on there, but as long as the new kernel is working properly then there is no problem with removing the old kernels.

0

delete them from package manager and they will disappear automatically

for example:

apt-get remove linux-image-2.6.35-22-generic

Not the answer you're looking for? Browse other questions tagged .