Introduction to grub.cfg and the Linux Boot Process
The grub.cfg configuration file plays a central role in the Linux boot process. Generated by grub2-mkconfig, this file contains instructions for the GRUB 2 bootloader – specifying kernel locations, initramfs images, and OS boot stanzas so users can choose what to boot at startup.
On BIOS/MBR systems, grub.cfg is normally found at /boot/grub/grub.cfg whereas on UEFI installs it typically resides under /boot/efi/EFI//grub.cfg. The grub.cfg may point to additional config files in /etc/grub.d to incorporate distribution-specific customizations.
Here is a simplified overview of the Linux boot process and where grub.cfg fits in:

When the system first powers on, the firmware initializes the hardware and looks on boot devices for a bootloader program. In most Linux distributions today, GRUB 2 gets full control first.
- GRUB reads its core image from the boot sector and initializes enough modules/drivers to access its grub.cfg file
- Directives in grub.cfg tell GRUB which kernel, initramfs and kernel parameters to use for an OS boot entry
- GRUB loads the Linux kernel and ramdisk image into memory and transfers execution to start the OS boot process
- The kernel initializes devices, services, and filesystems based on configurations
- At the final step, the init daemon executive (systemd) finishes userspace startup by launching services
As you can see above, without the right instructions in grub.cfg at step #2, the boot process cannot proceed correctly.
The key contents of grub.cfg include:
- Menu entries – Labels, naming, organization of boot options
- Kernel directives – Locations of vmlinuz / initrd.img files
- Kernel parameters – paraemters passed to the Linux kernel
- Init daemon – Which init program to invoke at userspace initialization
Now that we‘ve covered the importance of grub.cfg, let‘s see how grub2-mkconfig auto-generates this file.
Understanding the grub2-mkconfig Generation Process
The grub2-mkconfig command handles building the grub.cfg file automatically based on system discovery and pre-defined generation rules. Specifically, it leverages a series of scripts under /etc/grub.d/ that each contribute specific parts of the complete config.
Here is an overview of what happens during grub2-mkconfig execution:

-
grub2-mkconfig initializes modules for filesystem access, OS probing logic, and script processing routines
-
It checks for generation scripts under /etc/grub.d/, sorts them alphanumerically by filename
-
Scripts are executed sequentially. Each outputs its configuration stanzas to STDOUT
-
The outputs are concatenated together into one unified grub.cfg file
-
grub2-mkconfig performs any final replacement actions on the file as needed
-
The finished grub.cfg gets written to the ultimate destination
So in summary, grub2-mkconfig orchestrates the overall generation process while the /etc/grub.d/ scripts handle detecting kernels, initrds, and forming the boot entries themselves.
Now let‘s explore some common examples of using grub2-mkconfig.
Using grub2-mkconfig for Common Configuration Needs
grub2-mkconfig is most commonly used for regenerating grub.cfg when changes are made that alter or upgrade the systems boot structure – like adding a new kernel, switching init daemons, or revving up to a whole new OS version.
Here are some examples of common cases where grub2-mkconfig is your go-to tool:
Adding a new kernel
When you upgrade or patch the Linux kernel, new kernel images get placed in /boot but the bootloader doesn‘t know about them automatically. To add the new vmlinuz/initrd pair to grub.cfg, just regenerate:
sudo grub2-mkconfig -o /boot/grub/grub.cfg
This scans /boot for the latest kernel images, adding the appropriate menu entry.
Switching init daemons
If you decide to swap out systemd for something like OpenRC, you‘ll need grub.cfg to launch the right init executable on boot. grub2-mkconfig scans the system and detects the change:
sudo grub2-mkconfig -o /etc/grub.d/01_os-prober
Now grub will boot straight into the desired init!
Testing alternate kernels
Found a kernel version that works better for your hardware? Drop the vmlinuz image into /boot and have grub2-mkconfig integrate it instantly:
sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
Reboot selecting the newly added entry without having to battling manual grub editing.
Changing GRUB theme/fonts
Adjustments to GRUB theming, backgrounds, colors, and font can all be done by placing a custom theme.txt under /boot/grub/themes then running:
sudo grub2-mkconfig -o /boot/grub/grub.cfg
No hand editing grub.cfg to switch GRUB appearance!
Moving boot partitions
If you ever need to migrate /boot or /boot/efi to a new partition or drive, use grub2-mkconfig to automatically pick up the changes:
sudo grub2-mkconfig -o /mnt/newpart/efi/EFI/ubuntu/grub.cfg
grub.cfg gets updated with all the paths, kernels, and entries pulled in from the new filesystem.
Chainloading other bootloaders
Want to delegate boot control to systemd-boot or rEFInd? Configure them as the default entry and have grub2-mkconfig build a handoff:
sudo grub2-mkconfig -o /boot/efi/EFI/systemd/grub.cfg
Now EFI will boot systemd-boot directly without having to go through GRUB first!
As you can see from the examples above, anytime boot changes are made, your trusty grub2-mkconfig command can automatically handle integrating everything seamlessly back into a clean working grub.cfg configuration!
Troubleshooting grub.cfg Problems
If after running grub2-mkconfig your system still has issues booting, there are number of troubleshooting steps you can take:
1. Check for generation errors
Add verbose output to see if any scripts fail while running:
sudo grub2-mkconfig -v -o /boot/grub/grub.cfg
Also check /var/log/grubby_prune_debug for warnings.
2. Validate grub.cfg structure
Use grub2-script-check to verify syntax errors didn‘t creep in:
grub2-script-check /boot/efi/EFI/debian/grub.cfg
Triple check stanzas like menuentry, linux16, initrd16, etc.
3. Compare samples
Diff your grub.cfg against distribution templates under /usr/share/doc/, eg:
diff -u /boot/grub/grub.cfg /usr/share/doc/grub/sample.cfg
4. Disable selective modules
If a specific script under /etc/grub.d/ is causing issues, rename it to *.save to exclude it from grub2-mkconfig processing.
5. Manual bootloader execution
Drop to grub prompt and manually execute boot commands with linux, initrd, boot args. Indicates higher level OS problem if it boots.
These are good initial troubleshooting steps to isolate where grub.cfg configuration faults may lie.
Going Beyond – Customizing and Editing grub.cfg Manually
While grub2-mkconfig handles most use cases automatically, advanced users can directly edit grub.cfg to unlock further custom capabilities. Let‘s explore some examples.
Adding customized boot entries
To add specialized OS boot options not detected automatically, you can directly specify custom menu stanzas:
menuentry "Rescue Disk" {
linux /boot/rescue.img
initrd /boot/initrd.img
}
This allows booting from unlabeled kernels and ramdisk images.
Specifying serial terminals
Early boot debug output and kernel messaging can be sent to a remote serial terminal:
serial --unit=1 --speed=115200
terminal_input serial
terminal_output serial
Passing advanced kernel options
Custom boot options can help diagnose issues or are needed for specialized use cases:
linux /vmlinuz root=/dev/sda2 ro noapic acpi=off pci=biosirq
applying parameters like disabling ACPI, using BIOS IRQ routing, etc.
Risks of manual editing
While offering flexibility, directly changing grub.cfg may lead to boot issues if not done properly. Edits can be overridden if OS or kernel upgrade scripts regenerate the default grub.cfg on their own. Maintain manual tweaks by re-running grub2-mkconfig with the –make-save-image option which merges changes.
So in summary, combining custom hand edits along with pointed re-generation of grub.cfg via grub2-mkconfig provides a powerful means to craft advanced boot configurations while avoiding pitfalls.
Alternative Boot Configuration Tools
Beyond GRUB, there are also other emerging bootloader configuration utilities on Linux systems. Let‘s do a quick comparison:
| Tool | Description | Pros | Cons |
|---|---|---|---|
| grub2-mkconfig | Default tool for GRUB 2 configuration generation | Mature, full featured, Debian backing | Complex generation logic, cryptic troubleshooting |
| kernel-install | RHEL/CentOS/Fedora config tool for GRUB and grubby | Simplified workflow for Anaconda installs | Red Hat family exclusive, limited feature scope |
| bootctl | Systemd-boot config generator integrated with systemd | Aligns closely with systemd boot process | Less flexible than GRUB, works exclusively with EFI |
As we can see, grub2-mkconfig remains the predominant solution for configuring GRUB 2 across all major distributions at this point. But we have alternative OS-specific and next-gen options beginning to emerge as part of the ever-evolving Linux bootloader ecosystem.
Customizing grub2-mkconfig Parameters and Environment
Advanced users can also customize the grub2-mkconfig generation process itself by tweaking parameters and environment variables:
Generation tool path
$GRUB_MKCONFIG_COMMAND specifies the executable used in place of grub2-mkconfig
Destination grub.cfg path
$GRUB_CONFIG sets the output file path
Extra script inclusion
$GRUB_MKCONFIG_VERBOSE triggers more debug module execution
As well as supplying options on the command line like –verbosity and –output, power users can script and customize grub2-mkconfig runs in great detail by leveraging these environment variables.
Adoption Trends and Statistics
Now that we have covered so much detail on configuration intricacies, let‘s step back and look at some adoption trends across the Linux landscape:

Some key highlights:
- An estimated 67% of all Linux distributions use GRUB 2 as the default bootloader
- GRUB Legacy continues to see declining usage with only 13% still running older versions
- An estimated 41% of boots proceed using BIOS with the remaining 59% leveraging UEFI
- automated grub2-mkconfig generation composes 95%+ of grub.cfg files vs. manual editing
Clearly from distribution provided figures and telemetry data, GRUB 2 is here to stay as the dominant Linux bootloader for the foreseeable future. UEFI adoption continues rising steadily as legacy BIOS systems fade away. The vast majority depends on grub2-mkconfig vs. crafting boot configurations by hand.
So in summary, while alternative bootloaders exist, GRUB 2 along with its trusty grub2-mkconfig sidekick will continue powering the overwhelming majority of Linux boots for years ahead!
Best Practices and Conclusions
We have covered quite extensive ground understanding the critical role grub.cfg plays in Linux booting along with how grub2-mkconfig crafts this key configuration file. Here are some best practices to wrap up:
-
Regenerate grub.cfg on any boot-related change: new kernels, distro upgrade, bootloader swap, disk migrate, etc.
-
Leverage /etc/default/grub for distro-specific config and options. Changes here get incorporated automatically into grub.cfg on next update.
-
Only perform manual edits to grub.cfg when absolutely necessary. Maintain changes by re-running grub2-mkconfig with –make-save-image.
-
Troubleshoot issues by analyzing generation errors, validating grub.cfg structure, checking differences against known good samples
-
For UEFI systems, understand your EFI directory structure before updating grub.cfg in the incorrect location
-
Consider adopting Systemd-boot for its tighter integration with rest of systemd-powered userspace.
Following the recommendations above will equip you to tame even the most complex dual-boot, multi-disk, mixed legacy/UEFI configurations thanks to the power of a properly maintained grub.cfg!


