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 [[-h|--help]]
copy

SYNOPSIS

grub-mkconfig [OPTION...] -o OUTFILE

PARAMETERS

-h, --help
    Display help message and exit

-o, --output=FILE
    Path for output config file (default: /boot/grub/grub.cfg)

-q, --quiet
    Suppress output messages

--version
    Print version information and exit

DESCRIPTION

grub-mkconfig is a key utility in Linux distributions using GRUB2 (GRand Unified Bootloader version 2). It automatically generates the bootloader configuration file, usually /boot/grub/grub.cfg, by scanning the system for bootable kernels, operating systems, and other entries.

The tool executes a series of scripts in the /etc/grub.d/ directory, such as 10_linux for Linux kernels, 20_memtest86+ for memory tests, and 30_os-prober for detecting other OSes like Windows. These scripts output menu entries in a standardized format.

It incorporates user-defined settings from /etc/default/grub, controlling aspects like boot timeout, default entry, graphical menu, serial console, and kernel command-line parameters (e.g., GRUB_TIMEOUT=5, GRUB_CMDLINE_LINUX_DEFAULT="quiet splash").

Invoked directly or via the update-grub wrapper (common in Debian-based distros), it's run after kernel updates, new installations, or GRUB customizations to refresh the boot menu. The process is non-interactive and safe for multi-boot environments, ensuring reliable booting.

This command replaced manual grub.conf editing from GRUB Legacy, promoting automation and maintainability.

CAVEATS

Requires root privileges (sudo). Overwrites output file without backup—consider manual backup first. Fails if /boot/grub is missing or unreadable. Custom scripts in /etc/grub.d/ must be executable (chmod +x).

CONFIGURATION SOURCES

Sources settings from /etc/default/grub and executable scripts in /etc/grub.d/ (e.g., 10_linux, 40_custom). Add custom entries by creating/editing these scripts.

COMMON USAGE

Typically run via sudo update-grub, a wrapper that calls grub-mkconfig -o /boot/grub/grub.cfg. Verbose output shows detected kernels/OSes.

HISTORY

Introduced with GRUB 2.00 in 2009 by the GNU GRUB project, replacing GRUB Legacy's manual config editing. Evolved for better automation, supporting UEFI, complex filesystems, and modular scripts. Widely adopted in distros like Ubuntu, Fedora since 2010.

SEE ALSO

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

Copied to clipboard