grub2-mkconfig command is used to generate the
grub.cfg configuration file for the GRUB2 bootloader. This file contains the menu entries and settings for booting the operating system. This command is typically used after installing or updating the kernel or other system components that require changes to the bootloader configuration.
To generate the
grub.cfg file, run the following command as root:
grub2-mkconfig -o /boot/grub2/grub.cfg
This command will scan the system for installed operating systems and generate a menu with entries for each one. It will also detect any changes to the system’s hardware configuration and update the bootloader accordingly.
grub2-mkconfig looks for configuration files in
/etc/grub.d and includes them in the generated
grub.cfg file. These files contain scripts that define the menu entries and settings for specific operating systems or system components.
To customize the generated configuration, you can modify the scripts in
/etc/grub.d or create your own. The scripts are executed in numerical order, so you can control the order in which menu entries are displayed by renaming the files with appropriate prefixes (e.g.,
The following table lists the available options for
||Specify the output file for the generated configuration. Default is
||Specify the directory containing the GRUB2 configuration files. Default is
||Print verbose output.|
||Display help information.|
- If the generated
grub.cfgfile does not contain the expected menu entries, check that the configuration scripts in
/etc/grub.dare properly configured and executable.
- If the system fails to boot after updating the
grub.cfgfile, try booting from a live CD or USB and regenerate the configuration with
- If the system still fails to boot, check that the bootloader is installed correctly and that the correct partition is set as the boot device in the system’s BIOS or UEFI settings.
grub.cfgfile is automatically updated when the kernel or other system components are updated with the system package manager (e.g.,
- Changes to the configuration files in
/etc/grub.dwill not take effect until
grub2-mkconfigis run again.
grub.cfgfile should not be edited manually, as changes may be overwritten by future updates or cause the system to fail to boot.