How update-grub Rebuilds GRUB Configuration
The update-grub command is a vital utility in
Debian-based Linux distributions used to regenerate the GRUB 2
bootloader configuration. Rather than executing a complex internal
routine, it acts as a streamlined wrapper script that calls
grub-mkconfig to inspect the system, discover installed
kernels and alternative operating systems, and write a unified boot
configuration file to /boot/grub/grub.cfg.
The Execution Process
When executed with root privileges, update-grub runs a
single command under the hood:
grub-mkconfig -o /boot/grub/grub.cfgThis triggers a step-by-step process where the operating system compiles dynamic scripts and static settings into a single, static configuration that the GRUB bootloader can parse at machine startup.
1. Reading System Defaults
The generation process begins by loading settings from
/etc/default/grub. This file contains the administrative
preferences defined by the user or installation defaults, including:
GRUB_DEFAULT: The default operating system or kernel to boot.GRUB_TIMEOUT: The duration the boot menu displays before booting the default entry.GRUB_CMDLINE_LINUX_DEFAULT: Kernel parameters passed to the Linux kernel at boot time (such asquiet splash).- Visual preferences, including display resolutions, terminal output modes, and console themes.
2. Processing Modular
Scripts in /etc/grub.d/
Once the general preferences are loaded, the system executes the
scripts located in /etc/grub.d/ in numerical order. These
executable shell scripts output GRUB script commands that construct the
final /boot/grub/grub.cfg:
00_header: Establishes the GRUB environment, imports graphical modules, applies timeout settings, and loads basic variables.05_debian_theme: Configures colors, fonts, and background images for the boot interface.10_linux: Scans the/bootdirectory for installed Linux kernels (vmlinuz-*) and corresponding Initial RAM Disks (initrd.img-*). For each kernel found, it creates standard and recovery boot menu entries using the kernel parameters specified in/etc/default/grub.20_memtest86+: Detects memory-testing utilities in/bootand adds them to the utility options if present.30_os-prober: Utilizes theos-probertool to scan other partitions and drives for foreign installations, such as Microsoft Windows or other Linux distributions, generating boot options for multi-boot configurations.40_custom: Appends any user-written entries or configuration fragments that should remain persistent across regenerations.
3. Assembling and Writing the Configuration
As each script in /etc/grub.d/ runs, its standard output
is captured and concatenated. The combined output forms the syntax of
the GRUB scripting engine.
To prevent corruption during writes or interrupted executions, the
output is typically constructed in a temporary stream before replacing
/boot/grub/grub.cfg. Once written, GRUB reads this
finalized file during the next system boot cycle without needing to
re-scan the disks.