grub-mkconfig Command Examples in Linux

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.

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
Related Post