Grand Unified Boot Loader (GRUB) 2.0

(NOTE: This page was updated in January, 2021 to incorporate the latest details of the current version of GRUB. Additional editorial changes were made in March, 2021. In June 2022, further additions were made to document the GRUB interface from UEFI.)

GRUB 2.0 is an open-source bootloader that can directly or indirectly load a variety of operating systems. (See Legacy Grub for information on the earlier version of GRUB.)

When GRUB is being loaded by BIOS, it consists of two parts:

When GRUB is being loaded by UEFI, then the file is named grub64.efi and is stored in a directory accessable by UEFI. In that case grub64.efi is a PE/COFF format object file.

core.img or grub64.efi contains the basic functionality of GRUB, including file-system code for whichever type of file system is used by GRUB for the /boot/grub directory. This may reside in the root file system partition or maybe be a mount point for a separate partition. In the case of UEFI, then grub64.efi must reside in a FAT file system and is therefore almost always a separate partition.) Using this file-system code, GRUB locates and loads dynamic modules for the remaining GRUB functionality. These dynamic modules have a filename extension of ".mod" and are in standard ELF object-file format. They contain 32-bit code (even for a 64-bit OS).

GRUB plus dynamic modules consist of a number of components:

  1. A command processor which can execute a set of commands associated with loading OS components.
  2. A script execution engine that reads commands (including "if" and "while" commands to allow program logic) from the configuration file.
  3. A display system that can display menus, and other information on the screen and get input from the keyboard.
  4. File-system code for reading from the type of file system in which the /boot directory resides. This allows for finding all additional components using normal file-system operations, instead of relying on hard-coded disk addresses. (Unlike the other components in this list, this file-system code is staticly linked to core.img so that it can read the dynamic components from the file system.
  5. A menu processor. This processor reads a menu description from the file /boot/grub/grub.cfg. Each menu entry consists of a title whose contents are displayed in the menu, and a series of commands enclosed in braces ({}) that are to be executed if the menu item is selected.

The command language used by GRUB is very similar to the language read by shells such as BASH. It differs in two primary ways:

  1. Although both support interactive use as well as scripting, the shell is frequently used interactively, whereas the GRUB command language is almost exclusively used in scripts. (GRUB can read commands interactively, but this is very seldom used.)
  2. Most shell commands are separate programs. All GRUB commands are "built in" to the GRUB program. (Some commands may have been loaded from dynamic modules, but that happens prior to their being invoked; there is no 1:1 correspondence between commands and modules as there generally is in the shell.)

To summarize the process of loading GRUB:

Once the main body of GRUB is loaded into memory and given control, it reads /boot/grub/grub.cfg. This file contains a number of functions and parameters to specify

Thus grub.cfg can configure GRUB to run in one of two ways:

When/if the initial menu is shown the user can select a menu item, can edit the commands associated with a menu entry, or can enter a command mode where commands can be typed directly by the keyboard. The most common choice is to let the default menu entry be selected.

in a UEFI system the GRUB usually includes a menu option to run the UEFI shell. If this menu option is selected, GRUB calls a UEFI function to run the shell. If the user enters the shell "exit" command, the the shell exits and control returns to GRUB. (Don't confuse the UEFI shell with the GRUB command processor.)

GRUB can load the following types of systems:

  • Multiboot-compliant systems: GRUB can directly load other systems such as FreeBSD, ESX, NetBSD, etc. in a fashion similar to that for Linux as described above.

  • Other (Including Microsoft Windows): GRUB can load any other kind of operating system by "chaining" to the Partition Boot Record for that system by using the "chainloader" GRUB command.

    Next: The Kernel

    Return to main PC Boot Sequence page

    Return to my writing page

    Return to my home page