This is the GRUB 2 bootloader (v2.14), maintained by the Free Software Foundation.
The boot sequence for finding grub.cfg:
grub_main()(grub-core/kern/main.c:304) — kernel entrygrub_machine_init()— platform init (console, memory, disks)grub_load_modules()— load modules embedded in the core imagegrub_set_prefix_and_root()(grub-core/kern/main.c:118) — determine boot device:- Reads embedded
OBJ_TYPE_PREFIXfrom core image (set bygrub-install) - Falls back to
grub_machine_get_bootlocation()(platform-specific):- EFI:
grub-core/kern/efi/init.c:130— fromimage->device_handle/image->file_path - BIOS:
grub-core/kern/i386/pc/init.c:68— from boot drive + partition encoded at install time
- EFI:
- Sets env vars
prefix(e.g.(hd0,1)/boot/grub) androot
- Reads embedded
- Embedded config executed (if any, set via
grub-mkimage -c) grub_load_normal_mode()(grub-core/kern/main.c:232) — loadsnormalmodule, runsnormalcommandgrub_cmd_normal()(grub-core/normal/main.c:320) — constructs$prefix/grub.cfg- For PXE/netboot:
grub_net_search_config_file()(grub-core/net/net.c:1976) tries these in order:grub.cfg-<UUID>(client UUID from DHCP)grub.cfg-01-<MAC>(MAC address with hyphens)grub.cfg-<IP>(hex IP, shrinking suffix)grub.cfg- Disable via
feature_net_search_cfg=nin embedded config
grub_normal_execute(config)→read_config_file(config)opens and parses the file, setsconfig_file/config_directoryenv vars, then shows the menu
| File | Purpose |
|---|---|
grub-core/kern/main.c |
Kernel grub_main(), prefix/root setup, normal mode loading |
grub-core/normal/main.c |
normal module: grub_cmd_normal(), read_config_file(), menu display |
grub-core/kern/efi/init.c |
EFI boot location (device path → grub_efidisk_get_device_name()) |
grub-core/kern/i386/pc/init.c |
BIOS boot location (boot drive / partition) |
grub-core/net/net.c |
grub_net_search_config_file(): PXE config file discovery |
grub-core/commands/configfile.c |
configfile, source commands |
grub-core/commands/search.c |
search.file, search.fs_uuid, search.label commands |
grub-core/kern/rescue_reader.c |
Rescue shell (grub rescue>) |
grub-core/kern/rescue_parser.c |
Rescue mode parser |
grub-core/kern/corecmd.c |
Core built-in commands (set, unset, ls, insmod) |
grub-core/kern/fs.c |
Filesystem probing + auto-load |
grub-core/kern/disk.c |
Disk I/O with caching |
grub-core/kern/file.c |
grub_file_open(): parses (device)/path syntax |
util/grub-install.c |
Writes core image with embedded prefix and optional load.cfg |
Primary docs: docs/grub.texi (build into info grub).
Key sections for config discovery:
- "Embedded configuration" (
docs/grub.texi:2000) — howgrub-mkimage -candload.cfgwork - "Network" (
docs/grub.texi:2570) — PXE config file search order - "GRUB only offers a rescue shell" (
docs/grub.texi:10570) — troubleshooting prefix issues
./autogen.sh
./configure --target=i386 --with-platform=pc
makeTests: make check (many require root or specific hardware; check-native / check-nonnative split available).
- Device naming:
(hd0,msdos1)or(hd0,gpt2), path is(device)/path/to/file - Most functionality is in loadable modules under
grub-core/, not in the kernel - Modules are auto-loaded on demand via
grub_dl_load()when a command is first used - Env vars:
root,prefix,cmdpath,config_file,config_directory - Platform identifiers:
grub_cpu(e.g.x86_64) andgrub_platform(e.g.efi,pc) - Ubuntu/Debian patches in
debian/patches/(74 patches, including secure boot, ZFS, resilient boot)