In Ubuntu (and I guess in Debian too) there is a system script named update-grub which automatically executes grub-mkconfig -o with the correct path for the GRUB configuration file.

Is there a similar command for Red Hat-based distributions?

If not, how does the system know where the GRUB configuration file is to update when a new kernel version is installed?

11 Answers 11


After analyzing the scripts in Fedora, I realize that the configuration file path is read from the symlink /etc/grub2.conf. The correct grub2-mkconfig line is thus:

grub2-mkconfig -o "$(readlink -e /etc/grub2.conf)"

As noted in comments, it might be /etc/grub2.cfg, or /etc/grub2-efi.cfg on a UEFI system. Actually, both links might be present at the same time and pointing to different locations. The -e flag to readlink will error out if the target file does not exist, but on my system both existed... Check your commands, I guess.

  • 10
    On CentOS 7 the links seems to be /etc/grub2.cfg
    – Anthon
    Commented Dec 22, 2014 at 13:28
  • 9
    grub2-mkconfig --output=/boot/grub2/grub.cfg seems to be the approved way in the fedora manual
    – Kendrick
    Commented Aug 11, 2015 at 23:12
  • 1
    For more CentOS 7-specific grub steps, check the official wiki: wiki.centos.org/HowTos/Grub2
    – sshow
    Commented Feb 21, 2019 at 15:40
  • 6
    If you have a UEFI system you'll want sudo grub2-mkconfig -o "$(readlink /etc/grub2-efi.cfg)" Commented Jun 15, 2019 at 4:01
  • I see no point in doing readlink
    – poige
    Commented May 9, 2020 at 9:14

In Fedora, the /etc/grub2.cfg symlink points at the BIOS version. On a UEFI system, use:

$ sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg

In CentOS:

$ sudo grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg

Generally, you could use instead:

$ sudo grub2-mkconfig -o $(readlink -f /etc/grub2-efi.cfg)

See https://docs.fedoraproject.org/en-US/fedora/f27/system-administrators-guide/kernel-module-driver-configuration/Working_with_the_GRUB_2_Boot_Loader/index.html#sec-Editing_a_Menu_Entry


Specific actions that need to happen when a RPM package is installed or removed are included within the RPM package itself in pre-install, post-install, pre-uninstall and post-uninstall sections.

For every installed RPM package you can query the RPM database for the exact scripts that are included with the rpm command:

rpm -q --scripts <package-name>

Running that command on a kernel package for CentOS 6 returns among others:

postinstall scriptlet (using /bin/sh):
/sbin/new-kernel-pkg --package kernel --install 2.6.32-431.17.1.el6.x86_64 || exit $?

From the manual:

new-kernel-package - tool to script kernel installation

  • 2
    running the same command on Fedora 20 yields /bin/kernel-install instead. Please edit your answer to include this information for future reference
    – pqnet
    Commented Aug 26, 2014 at 11:26
  • 5
    That is exactly why I started my answer with the steps needed to find out. I think querying the installation scripts is likely to be pretty universal in the RPM world in helping you understand how the kernel update is effected. That way my answer will withstand the test of time much better than only naming a tool/command/support-script which you already demonstrated is very release and distribution dependent.
    – HBruijn
    Commented Aug 26, 2014 at 12:16
  • 4
    Yeah @HBruijn's right. There's too much variability across Fedora, RHEL, and CentOS to provide a single answer, better to show how to find it.
    – slm
    Commented Nov 25, 2014 at 2:41
  • 1
    I managed to do this on CentOS 7 with rpm -q --scripts kernel. The output wasn't that easy to decipher, but it's nice to have a definitive way to find the answer.
    – mwfearnley
    Commented Oct 21, 2021 at 9:08

On Fedora I use:

grub2-mkconfig -o "$(readlink -e /etc/grub2.cfg)"

because executing with no option to readlink returns a relative path, and grub2-mkconfig gives an error:

$ ls -l /etc/grub2.cfg
lrwxrwxrwx. 1 root root 22 Dec 10  2015 /etc/grub2.cfg -> ../boot/grub2/grub.cfg

$ readlink /etc/grub2.cfg

$ sudo grub2-mkconfig -o "$(readlink /etc/grub2.cfg)"
/usr/sbin/grub2-mkconfig: line 244: ../boot/grub2/grub.cfg.new: No such file or directory

I use the -e option so that if the symlink doesn't resolve to a file that exists, output displays on stdout so I know something went wrong.

From the man page for readlink:

      -e, --canonicalize-existing
          canonicalize  by  following  every symlink in every component of
          the given name recursively, all components must exist
  • Heads up: This command does not work with sudo! (The readlink part will run withoud priviledges and can't read the symlink as intended.) You'll need to run the whole thing in a root shell, for example sudo -i will give you one. It may still not be the right path on EFI systems though.
    – dreua
    Commented Apr 8, 2023 at 1:09

Per the RedHat documentation:

Changes to /etc/default/grub require rebuilding the grub.cfg file as follows:

  • On BIOS-based machines, issue the following command as root:

    ~]# grub2-mkconfig -o /boot/grub2/grub.cfg

  • On UEFI-based machines, issue the following command as root:

    ~]# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg


In the Fedora 33 guidelines, it gives the following after changing the GRUB configuration:

sudo grub2-mkconfig --output=/boot/grub2/grub.cfg


The update-grub script in Ubuntu is actually just a stub for grub-mkconfig, and it can be adapted to other distros without too much pain. Here it is in its entirety:

set -e
exec grub-mkconfig -o /boot/grub/grub.cfg "$@"

This effectively does what is recommended in the CentOS wiki, and in other answers here - the only difference is that you need to change grub to grub2 in the command and the output path.

(Note that the path will be different for UEFI-based systems - see the wiki link)


Edit the GRUB configuration file with vi or vim, save the changes and close the editor with :wq!.

This is what you need to run to update the GRUB configuration in RHEL or CentOS:

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

On Fedora 32:

sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg

Boot Loader Specification and blscfg in GRUB

If not, how do the system knows where is the grub configuration file to update when a new kernel version is installed?

Until a few hours ago this was also my understanding of how things work with GRUB. An Oracle Linux 8.4 system we have here just taught me something new. I was a bit irritated staring at the "empty" section where I expected to find the configuration that builds the list of boot entries. I stumbled across blscfg and found this article: Changes/BootLoaderSpecByDefault

HBruijn's answer makes a lot more sense in that context, even though it was valid before.

Now, you have your grub.cfg file, which can read BLS files and you don't have to touch grub.cfg for every kernel update. Which is great in from my point of view.

One more attempt at grub-mkconfig

Since there have been many answers posted here from different systems and configurations, let's have one last shot at this with a regular expression.

# Search for an existing GRUB configuration file symbolic link in '/etc'.
# This should only yield one path.
grub_cfg="$(find "/etc" -maxdepth=1 -regextype posix-egrep \
 -regex "/etc/grub2((|-efi).cfg|.conf)")"

# Resolve symbolic link and generate new grub configuration
sudo grub2-mkconfig -o "$(sudo readlink -e $grub_cfg)"

This worked on CentOS 8:

sudo grub2-mkconfig --output=/boot/grub2/grub.cfg

My Demo

  • Can you provide the output as text, please? See e.g. PSA: Please don't post images of text Commented Jul 22, 2022 at 16:34
  • Thankyou for mentioning, yet if you read carefully, I've posted the command separately. That image is just to show it is working.
    – Shubham
    Commented Jul 23, 2022 at 17:31

You must log in to answer this question.

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