Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Recently, I executed the following command:

grub2-mkconfig -o /boot/grub2/grub.cfg

Now I have 6-7 Linux entries + 1 windows entry. How do I remove older kernel entries?

I don't want to remove all the recovery kernel options by using:

share|improve this question
Any reason not to just comment out the ones you don't want? – Kevin Feb 10 '12 at 18:41
If your distribution auto generates the grub config, the easiest thing to do is to uninstall the older kernels. – jw013 Feb 10 '12 at 19:05
@Kevin is right, just comment out the ones you don't want in /boot/grub2/grub.cfg. The way these scripts work you get an entr – sr_ Feb 10 '12 at 19:06
@Kevin : Thanks for improving the question. I don't mind commenting out unwanted entries but which file should I edit? /etc/grub.cfg suggests that it is autogenerated & should not be edited. – Nitish Parkar Feb 10 '12 at 19:18
@sr_ : It says 'DO NOT EDIT THIS FILE'. I commented the unwanted entries but isn't there any other way to do it? – Nitish Parkar Feb 10 '12 at 19:29
up vote 2 down vote accepted

The file /boot/grub2/grub.cfg is generated automatically by the grub2-mkconfig command, which will be run automatically when a new kernel is installed. This command iterates over available kernel packages on your system. Attempts to directly edit this file will ultimately fail (because the entries you commented out will simply be regenerated).

As @jw013 says, the easiest solution is to simply remove kernel packages if you don't want to use them anymore.

If you need to edit options in this file, you can edit /etc/default/grub, which defines shell variables used in the generation scripts. You can also look in /etc/grub.d, which is a collection of shell scripts that are run to generate the configuration.

share|improve this answer
I didn't want to mess with the shell scripts so just removed older kernels. – Nitish Parkar Feb 12 '12 at 14:32

Fedora tries to keep 3 kernels around when updating (for the rare case of spectacular fireworks on boot).

share|improve this answer

you could just run package-cleanup --oldkernels. There's a lot more options available to that command, just read the manual or execute: package-cleanup --help.

Additionally, if you comment out(add # at the beginning) the line GRUB_DISABLE_RECOVERY="true", it will generate an "Advanced" submenu for the recovery menuentries, etc. Each OS will be displayed 2; Once for default options, and an additional for "advanced" options. Your Grub2 menu will look much cleaner.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.