LinuxCommandLibrary

grub-mkconfig

Generate GRUB configuration file

TLDR

Do a dry run and print the configuration to stdout

$ sudo grub-mkconfig
copy

Generate the configuration file
$ sudo grub-mkconfig [[-o|--output]] [/boot/grub/grub.cfg]
copy

Display help
$ grub-mkconfig --help
copy

SYNOPSIS

grub-mkconfig -o output_file

PARAMETERS

-o output_file
    Specifies the output file to write the GRUB configuration to. Usually this is /boot/grub/grub.cfg, but can vary by distro.

-h, --help
    Display help message and exit.

-v, --verbose
    Enable verbose output.

--version
    Output version information and exit.

DESCRIPTION

grub-mkconfig is a command-line utility used to generate the grub.cfg file, which is the main configuration file for the GRUB (GNU GRand Unified Bootloader) bootloader.

It scans the system for installed operating systems and generates menu entries that allow you to choose which operating system to boot at startup. It searches for kernels, initrd images, and other boot-related files, and then constructs the appropriate GRUB configuration entries based on the detected system configuration.

It typically relies on scripts located in /etc/grub.d/ to determine which operating systems to add to the menu, and reads settings from /etc/default/grub to customize the generated configuration, like timeout values and default OS.

grub-mkconfig is a crucial tool for configuring your bootloader and is usually run automatically after kernel updates or when significant changes are made to the system's boot configuration.

CAVEATS

It's crucial to run grub-mkconfig as root or with appropriate privileges, as it modifies system boot files. Also, incorrect configuration can render the system unbootable. Always backup your existing configuration before running grub-mkconfig. Custom scripts in /etc/grub.d/ can affect the generated configuration significantly.

CONFIGURATION SCRIPTS

The scripts in the /etc/grub.d/ directory determine how different operating systems are detected and added to the GRUB menu. Modifying these scripts allows for advanced customization of the boot menu. Changes to /etc/default/grub are also important, as they can influence the settings read by scripts.

BOOTLOADER LOCATION

The location of the GRUB configuration and modules can vary between different Linux distributions. Understanding where these files are located is critical for troubleshooting and customizing the boot process.

HISTORY

grub-mkconfig evolved as part of the GRUB 2 project, aiming for a more flexible and scriptable configuration generation process compared to GRUB legacy. It was designed to automate the creation of the grub.cfg file, which is crucial for a functioning GRUB 2 bootloader. The command has seen continuous development and refinement over the years to handle a wider range of operating systems and hardware configurations.

SEE ALSO

grub-install(8), update-grub(8), grub.cfg(5)

Copied to clipboard