GNU GRUB
GNU GRUB is a boot loader package from the GNU Project. GRUB is the reference implementation of the Free Software Foundation's Multiboot Specification, which provides a user the choice to boot one of multiple operating systems installed on a computer or select a specific kernel configuration available on a particular operating system's partitions.
GNU GRUB was developed from a package called the Grand Unified Bootloader. It is predominantly used for Unix-like systems. The GNU operating system uses GNU GRUB as its boot loader, as do most Linux distributions and the Solaris operating system on x86 systems, starting with the Solaris 10 1/06 release.
Operation
Booting
When a computer is turned on, BIOS finds the configured primary bootable device and loads and executes the initial bootstrap program from the master boot record. The MBR is the first sector of the hard disk, with zero as its offset. For a long time, the size of a sector has been 512 bytes, but since 2009 there are hard disks available with a sector size of 4096 bytes, called Advanced Format disks., such hard disks are still accessed in 512-byte sectors, by utilizing the 512e emulation.The legacy MBR partition table supports a maximum of four partitions and occupies 64 bytes, combined. Together with the optional disk signature and disk timestamp, this leaves between 434 and 446 bytes available for the machine code of a boot loader. Although such a small space can be sufficient for very simple boot loaders, it is not big enough to contain a boot loader supporting complex and multiple file systems, menu-driven selection of boot choices, etc. Boot loaders with bigger footprints are thus split into pieces, where the smallest piece fits into and resides within the MBR, while larger piece are stored in other locations and invoked by the boot loader's MBR code.
Operating system kernel images are in most cases files residing on appropriate file systems, but the concept of a file system is unknown to the BIOS. Thus, in BIOS-based systems, the duty of a boot loader is to access the content of those files, so it can be loaded into the RAM and executed.
One possible approach for boot loaders to load kernel images is by directly accessing hard disk sectors without understanding the underlying file system. Usually, an additional level of indirection is required, in form of maps or map files auxiliary files that contain a list of physical sectors occupied by kernel images. Such maps need to be updated each time a kernel image changes its physical location on disk, due to installing new kernel images, file system defragmentation etc. Also, in case of the maps changing their physical location, their locations need to be updated within the boot loader's MBR code, so the sectors indirection mechanism continues to work. This is not only cumbersome, but it also leaves the system in need of manual repairs in case something goes wrong during system updates.
Another approach is to make a boot loader aware of the underlying file systems, so kernel images are configured and accessed using their actual file paths. That requires a boot loader to contain a driver for each of the supported file systems, so they can be understood and accessed by the boot loader itself. This approach eliminates the need for hardcoded locations of hard disk sectors and existence of map files, and does not require MBR updates after the kernel images are added or moved around. Configuration of a boot loader is stored in a regular file, which is also accessed in a file system-aware way to obtain boot configurations before the actual booting of any kernel images. As a result, the possibility for things to go wrong during various system updates is significantly reduced. As a downside, such boot loaders have increased internal complexity and even bigger footprints.
GNU GRUB uses the second approach, by understanding the underlying file systems. The boot loader itself is split into multiple stages, allowing for itself to fit within the MBR boot scheme.
Two major versions of GRUB are in common use: GRUB version 1, called GRUB legacy, is only prevalent in older releases of Linux distributions, some of which are still in use and supported, for example CentOS 5. GRUB 2 was written from scratch and intended to replace its predecessor, and is now used by a majority of Linux distributions.
Version 0 (GRUB Legacy)
GRUB 0.x follows a two-stage approach. The master boot record usually contains GRUB stage 1, or can contain a standard MBR implementation which chainloads GRUB stage 1 from the active partition's boot sector. Given the small size of a boot sector, stage 1 can do little more than load the next stage of GRUB by loading a few disk sectors from a fixed location near the start of the disk.Stage 1 can load stage 2 directly, but it is normally set up to load the stage 1.5., located in the first 30 KiB of hard disk immediately following the MBR and before the first partition. In case this space is not available the install of stage 1.5 will fail. The stage 1.5 image contains file system drivers, enabling it to directly load stage 2 from any known location in the filesystem, for example from
/boot/grub
. Stage 2 will then load the default configuration file and any other modules needed.Version 2 (GRUB 2)
Startup on systems using BIOS firmware">BIOS">BIOS firmware
- See illustration in last image on the right.
- 1st stage:
boot.img
is written to the first 440 bytes of the Master Boot Record, or optionally in a partition's boot sector. It addressesdiskboot.img
by a 64-bit LBA address, thus it can load from above the 2 GiB limit of the MBR. The actual sector number is written bygrub-install
. - 2nd stage:
diskboot.img
is the first sector ofcore.img
with the sole purpose to load the rest ofcore.img
identified by LBA sector numbers also written bygrub-install
. - On MBR partitioned disks:
core.img
is stored in the empty sectors between the MBR and the first partition. Recent operating systems suggest a 1 MiB gap here for alignment. This gap used to be 62 sectors as a reminder of the sector number limit of C/H/S addressing used by Bios before 1998, thereforecore.img
is designed to be smaller than 32 KiB. - On GPT partitioned disks: partitions are not limited to 4, thus
core.img
is written to its own tiny, filesystem-less BIOS boot partition. - 3rd stage:
core.img
enters 32-bit protected mode, uncompresses itself, then loads/boot/grub/
from the partition configured by/normal.mod grub-install
. If the partition index has changed, GRUB will be unable to find thenormal.mod
, and presents the user with the GRUB Rescue prompt, where the user “can” find and loadnormal.mod
, or the linux kernel. - The
/boot/grub
directory can be located on any partition. Depending on how it was installed it's either in the root partition of the distribution, or a separate /boot partition. - 4th stage:
normal.mod
parses/boot/grub/grub.cfg
, optionally loads modules and shows the menu.Startup on systems using UEFI firmware">Unified Extensible Firmware Interface">UEFI firmware
- Common on motherboards since ca. 2012.
-
/efi/
is installed as a file in the EFI System Partition, and booted by the firmware directly, without a/grubx64.efi boot.img
in sector 0. -
/boot/grub/
can be installed on the EFI System Partition as well.After startup
In the operating system selection menu GRUB accepts a couple of commands:
- By pressing, it is possible to edit kernel parameters of the selected menu item before the operating system is started. The reason for doing this in GRUB can be an emergency case: the system has failed to boot. Using the kernel parameters line it is possible, among other things, to specify a module to be disabled for the kernel. This could be required if the specific kernel module is broken and thus prevents boot-up. For example, to blacklist the kernel module
nvidia-current
, one could appendmodprobe.blacklist=nvidia-current
at the end of the kernel parameters. - By pressing, the user enters the GRUB command line. The GRUB command line is not a regular Linux shell, like e.g. bash, and accepts only certain GRUB-specific commands, documented by various Linux distributions.
History
GRUB was initially developed by Erich Boleyn as part of work on booting the operating system GNU/Hurd, developed by the Free Software Foundation. In 1999, Gordon Matzigkeit and Yoshinori K. Okuji made GRUB an official software package of the GNU Project and opened the development process to the public., the majority of Linux distributions have adopted GNU GRUB 2, as well as other systems such as Sony's PlayStation 4.Development
GRUB version 1 is no longer under development and is being phased out. The GNU GRUB developers have switched their focus to GRUB 2, a complete rewrite with goals including making GNU GRUB cleaner, more robust, more portable and more powerful. GRUB 2 started under the name PUPA. PUPA was supported by the Information-technology Promotion Agency in Japan. PUPA was integrated into GRUB 2 development around 2002, when GRUB version 0.9x was renamed GRUB Legacy.Some of the goals of the GRUB 2 project include support for non-x86 platforms, internationalization and localization, non-ASCII characters, dynamic modules, memory management, a scripting mini-language, migrating platform specific code to platform specific modules, and an object-oriented framework. GNU GRUB version 2.00 was officially released on June 26, 2012.
Three of the most widely used Linux distributions use GRUB 2 as their mainstream boot loader. Ubuntu adopted it as the default boot loader in its 9.10 version of October 2009. Fedora followed suit with Fedora 16 released in November 2011. OpenSUSE adopted GRUB 2 as the default boot loader with its 12.2 release of September 2012. Solaris also adopted GRUB 2 on the x86 platform in the Solaris 11.1 release.
In late 2015, the exploit of pressing backspace 28 times to bypass the login password was found and quickly fixed.
Variants
GNU GRUB is free and open-source software, so several variants have been created. Some notable ones, which have not been merged into GRUB mainline:- OpenSolaris includes a modified GRUB Legacy that supports BSD disklabels, automatic 64-bit kernel selection, and booting from ZFS.
- Google Summer of Code 2008 had a project to support GRUB legacy to boot from ext4 formatted partitions.
- The Syllable project made a modified version of GRUB to load the system from its AtheOS File System.
- TrustedGRUB extends GRUB by implementing verification of the system integrity and boot process security, using the Trusted Platform Module.
- The Intel BIOS Implementation Test Suite provides a GRUB environment for testing BIOSes and in particular their initialization of Intel processors, hardware, and technologies. BITS supports scripting via Python, and includes Python APIs to access various low-level functionality of the hardware platform, including ACPI, CPU and chipset registers, PCI, and PCI Express.
- GRUB4DOS was a now-defunct GRUB legacy fork that improves the installation experience on DOS and Microsoft Windows by putting everything besides the GRLDR config in one image file. It can be loaded by the Windows Boot Manager.
Utilities
GRUB configuration tools
The setup tools in use by various distributions often include modules to set up GRUB. For example, YaST2 on SUSE Linux and openSUSE distributions and Anaconda on Fedora/RHEL distributions. StartUp-Manager and GRUB Customizer are graphical configuration editors for Debian-based distributions. The development of StartUp-Manager stopped on 6 May 2011 after the lead developer cited personal reasons for not actively developing the program. GRUB Customizer is also available for Arch-based distributions.For GRUB 2 there are KDE Control Modules.
GRLDR ICE is a tiny tool for modifying the default configuration of grldr file for GRUB4DOS.
Boot repair utilities
is a simple graphical tool for recovering from frequent boot-related problems with GRUB and Microsoft Windows bootloader. This application is available under GNU GPL license. Boot-Repair can repair GRUB on multiple Linux distributions including, but not limited to, Debian, Ubuntu, Mint, Fedora, openSUSE, and Arch Linux.Installer for Windows
is a Windows open-source software package. It allows GNU GRUB to boot from a Windows directory. The setup program installs GNU GRUB version 2.04 to an NTFS partition. A Windows GUI application is then used to customize the GRUB boot menu, themes, UEFI boot order, scripts etc. All GNU GRUB scripts and commands are supported for both UEFI and legacy systems. Grub2Win can configure GRUB for multiboot of Windows, Ubuntu, openSuse, Fedora and many other Linux distributions. It is freely available under GNU GPL License at.Alternative boot-managers
The strength of GRUB is the wide range of supported platforms, file-systems, and operating systems, making it the default choice for distributions and embedded systems.However, there are boot-managers targeted at the end user that gives more friendly user experience, graphical OS selector and simpler configuration:
- rEFInd – Macintosh-style graphical boot-manager, only for UEFI-based computers.
- – Macintosh-style graphical boot-manager for BIOS and UEFI-based computers. Emulates UEFI with a heavily modified from the TianoCore project. Requires a FAT formatted partition even on BIOS systems. As a benefit, it has a basic filesystem driver in the partition boot sector, avoiding the brittleness of GRUB 2nd, 3rd stage and the infamous GRUB Rescue prompt. The user interface looks similar to rEFInd: both inherit from the abandoned boot-manager .
- systemd-boot – Light, UEFI-only boot-manager with text-based OS selector menu.
How-Tos and troubleshooting
-
Documentation
- – most detailed documentation, including all commands
-
Introductory articles
- , an April 2001 article in Linux Journal
Technicalities
- – in-depth article
- Unified Extensible Firmware Interface
- GUID Partition Table – handles hard drives bigger than 2 TiB and more than 4 partitions
- Master boot record used with BIOS firmware
- – hard to find