grub-mkconfig is a command-line utility that is used to generate a configuration file for the GRUB (GRand Unified Bootloader) bootloader. GRUB is a bootloader that is commonly used in Linux and Unix-like systems to load the operating system.
The grub-mkconfig command generates a new configuration file for GRUB based on the current system setup. The configuration file, typically called “grub.cfg”, contains information about the available operating systems and boot options, as well as other settings such as the default boot option and the timeout before the default option is automatically selected.
For example, to generate a new grub.cfg file for your system, you would use the following command:
# grub-mkconfig -o /path/to/grub.cfg
The -o option is used to specify the output file, by default it is /boot/grub/grub.cfg
grub-mkconfig looks for the configuration files in the /etc/grub.d/ directory, and those files have a number prefix that determines the order they are processed. It also looks for any other files with a .cfg extension in the /etc/grub.d/ directory and include them in the generated file.
It’s important to note that after any changes or updates to the system, for example, adding a new OS, adding a new kernel, etc. you should re-run the grub-mkconfig command to update the grub.cfg file and make sure that the changes are reflected in the boot menu. Also, if you run the command with the -o option, you should make sure that the output file is in the correct location and that it’s readable by the bootloader.
If you encounter the below error while running the command grub-mkconfig:
grub-mkconfig: command not found
you may try installing the below package as per your choice of distribution:
|apt-get install grub-pc
|apt-get install lupin-support
|apk add grub
|pacman -S grub
|apt-get install grub-legacy
|dnf install grub2-common
|apt-get install grub2-common
grub-mkconfig Command Examples
1. Do a dry run and print the configuration to stdout:
# sudo grub-mkconfig
2. Generate the configuration file:
# sudo grub-mkconfig --output=/boot/grub/grub.cfg
3. Print the help page:
# grub-mkconfig --help