Grub2 config file may need to be re-generated after changing Grub2 configurations such as configuration changes and setting default boot entries. The Grub2’s config file may be at different locations depending on your Linux distro and whether your Linux is booted in BIOS or UEFI mode. This makes regenerating Grub2 config file not easy for Linux users especially beginners. In this post, I will introduce a way that should be portable and easy to use. This method is tested on Fedora and will likely work on RHEL / CentOS / Scientific Linux . For Ubuntu users, please check the “Notes for Ubuntu users” at the end.
The quick way: use the grub2-regen-cfg.bash script
Table of Contents
We provide a script
grub2-regen-cfg.bash that you can directly use to regenerate the Grub2 config file.
The manual way: step by step
Depending whether your Linux systems is under BIOS or UEFI mode, we choose different config file locations. The files under
/etc/ is the most portable location as far as I know as some Linux distros may change the default location that grub2 choose to store the config files under /boot/.
if [ -d /sys/firmware/efi ]; then grubcfg="/etc/grub2-efi.cfg" else grubcfg="/etc/grub2.cfg" fi
After choosing the correct location of the grub2 config file and store it in
$grubcfg, we can re-generate the config file by:
# cp $grubcfg $grubcfg.bak # make a backup in case bad things happened # grub2-mkconfig -o $grubcfg
Okay, it is done.
Notes for Ubuntu users
Ubuntu and its derived distros have a useful script named
update-grub and you can use it to update your grub configuration file by running