How rhboot/grub2 works
Main components
• Boot firmware/Platform layer – the system’s firmware (BIOS, UEFI, coreboot, etc.) that initiates the boot process.
• GRUB Stage(s):
• Early boot and initial loader (often the “boot” code included in the boot block and small assembly stubs).
• The GRUB core (grub-core) that handles modular loading, command interpretation, and file system and device drivers.
• Modules and Drivers:
• Filesystem support: the “fs” directory contains drivers for various filesystems (ext2, fat, ntfs, etc.).
• Device drivers: support for disk I/O, USB, PCI bus, network boot (net), etc.
• Command and Scripting Engine:
• The “commands” directory and associated scripts provide the CLI and boot menu functionality.
• Utilities and Installation Tools:
• The “util/” directory, which includes tools such as grub-install, grub-mkimage, grub-mkconfig, and others for image creation and deployment.
• Architecture-specific and Platform Abstraction Layers:
• Directories under “grub-core/boot”, “grub-core/kern”, “include/grub/i386”, “include/grub/arm”, etc., that encapsulate support for numerous hardware architectures.
• Documentation and Theme Components:
• The “docs”, “themes”, and “unicode” directories that provide user-visible documentation and UI elements.
Relationships and interactions
• That the boot block loads the minimal GRUB code (typically very low-level assembly and platform-specific initialization contained under “grub-core/boot” and “loader” directories).
• The GRUB core then mounts filesystems (using modules from “fs/”), discovers configuration files (often in text form, as well as the “util” tools to generate them), and eventually presents a menu to the user and takes commands.
• Underneath, the GRUB core interacts with numerous hardware abstraction layers which are implemented in architecture-specific directories (i386, arm, etc.) and linked via common interfaces defined in the “include” directories.
• The utilities (in “util”) are used to generate boot images, configure modules, and handle installation, interacting with both configuration files and the GRUB core.
• Test and validation components (in “tests”) and language abstractions (in “lib”, “po”, etc.) support robustness and localization.
Significant architectural patterns and design principles
• Modularity: GRUB 2 is highly modular; core functionality is separated from drivers, filesystem modules, commands, and architecture-specific code.
• Layered architecture: The design clearly separates low-level hardware initializations and platform-specific code (boot and loader stages) from higher-level command processing, configuration parsing, and device interactions.
• Portability and abstraction: Numerous directories are dedicated to different hardware platforms (e.g., “grub-core/kern/i386”, “grub-core/kern/arm”, etc.), using defined interfaces in “include/grub” to abstract platform details.
• Extensibility: The plugin model for commands and modules (as seen in “commands”, “fs”, “net”, etc.) allows GRUB to be extended for additional filesystems, device drivers, or boot protocols.
Technologies, frameworks, or libraries
• Cryptographic libraries and modules within “lib/libgcrypt” are used for securely handling boot-time cryptography (for encrypted boot, module signature verification, etc.).
• Various compression libraries (e.g., LZMA, LZO, XZ, ZSTD) are integrated under both “lib” and “grub-core/boot/decompressor” to support image decompression.
• Extensive use of assembly language in architecture-specific directories (e.g., in “grub-core/boot/i386/pc”) shows low-level hardware initialization.
• The build system (Makefile.am, configure.ac, autogen.sh, etc.) indicates integration with GNU autotools for configuration and building.