Equivalent of update-grub for RHEL/Fedora/CentOS systems?

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.


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):
<snip>
/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


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
../boot/grub2/grub.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