GRUB Bootloader Explained: How GRUB2 Finds and Loads the Linux Kernel
How GRUB 2 works on BIOS and UEFI: core image, modules, grub.cfg, menu entries, the GRUB shell and why you edit /etc/default/grub instead of grub.cfg.
Published November 27, 2026
GRUB (GRand Unified Bootloader) is the program between your firmware and your kernel. It is surprisingly capable: it reads ext4, XFS, Btrfs, LVM and even encrypted partitions, it has its own scripting language and shell, and it can boot Linux, Windows, ISO files and other bootloaders. This article explains how its pieces fit together.
The concept
GRUB is split into a small core image and loadable modules. On BIOS systems, a tiny boot.img in the MBR loads core.img from the gap after the MBR (or a BIOS boot partition on GPT disks). On UEFI systems, the firmware loads grubx64.efi directly from the EFI System Partition, often via shim for Secure Boot. Either way, the core then loads modules (filesystem drivers, LVM, crypto) from /boot/grub to read the full configuration.
The configuration file, grub.cfg, is generated, not hand-written. The tool grub-mkconfig (update-grub on Debian/Ubuntu, grub2-mkconfig on RHEL) runs the scripts in /etc/grub.d/, which detect installed kernels and other operating systems and combine them with settings from /etc/default/grub. Edit the inputs, then regenerate; any direct edit to grub.cfg is overwritten at the next kernel update.
How grub.cfg is generated
The GRUB chain
Anatomy of a menu entry
Each menuentry in grub.cfg is a small script. It loads the modules it needs, finds the partition holding the kernel (by UUID), then issues three key commands: linux (load kernel with command line), initrd (load initramfs) and an implicit boot at the end.
menuentry 'Ubuntu' --class ubuntu --class gnu-linux {
insmod gzio
insmod part_gpt
insmod ext2
search --no-floppy --fs-uuid --set=root 3f1c9a2e-...
linux /boot/vmlinuz-6.8.0-49-generic root=UUID=3f1c9a2e-... ro quiet splash
initrd /boot/initrd.img-6.8.0-49-generic
}GRUB files
| File | Edit it? | Purpose |
|---|---|---|
| /etc/default/grub | Yes | Timeout, default entry, kernel command line |
| /etc/grub.d/40_custom | Yes | Your own custom menu entries |
| /etc/grub.d/10_linux etc. | Rarely | Scripts that generate entries |
| /boot/grub/grub.cfg | No | Generated output, overwritten on updates |
| /boot/efi/EFI/*/grub.cfg | No | Small UEFI stub pointing at the real config (some distros) |
Practical examples
Regenerate the config
Run after changing /etc/default/grub or adding custom entries.
sudo update-grub # Debian/Ubuntu
sudo grub2-mkconfig -o /boot/grub2/grub.cfg # RHEL/Fedora (BIOS and UEFI on RHEL 9+)Reinstall GRUB to the disk
Needed after a Windows install overwrites the boot sector or the ESP entry is lost.
sudo grub-install /dev/sda # BIOS
sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu # UEFIUse the GRUB shell interactively
Press c at the menu to get a grub> prompt and explore.
grub> ls
(hd0) (hd0,gpt1) (hd0,gpt2)
grub> ls (hd0,gpt2)/boot
grub> cat (hd0,gpt2)/etc/os-releaseCommon mistakes
- Editing grub.cfg directly and losing changes at the next kernel update.
- Running grub-install against a partition (/dev/sda1) instead of the disk (/dev/sda) on BIOS systems.
- Mixing up BIOS and UEFI: installing the i386-pc target on a machine booting in UEFI mode.
- Deleting old kernels from /boot without regenerating grub.cfg, leaving broken menu entries.
Key takeaways
- GRUB has a small core plus modules that understand filesystems, LVM and encryption.
- grub.cfg is generated from /etc/default/grub and /etc/grub.d by grub-mkconfig.
- On UEFI, shim and grubx64.efi live on the EFI System Partition.
- The GRUB shell (press c) lets you explore disks and boot manually.
FAQ
What is the difference between GRUB Legacy and GRUB 2?
GRUB Legacy (0.97) used a hand-written menu.lst. GRUB 2 is a rewrite with modules, scripting, UEFI support and a generated grub.cfg. Every current distribution uses GRUB 2.
Is systemd-boot a replacement for GRUB?
On UEFI-only systems, yes. systemd-boot is a simpler boot manager that reads entries from the ESP, but it cannot read ext4 or LVM and does not support BIOS.
Why does my GRUB menu not appear?
GRUB_TIMEOUT_STYLE=hidden or a zero timeout hides it. Hold Shift (BIOS) or tap Esc (UEFI) during boot, or change the settings in /etc/default/grub.