GNU GRUB

GNU GRUB

GRUB in text mode
Original author(s) Erich Boleyn
Developer(s) GNU Project
Initial release 1995
Stable release 2.00 (GRUB 2) / June 27, 2012[1]
Preview release 2.02~beta2 (GRUB 2)[2] / December 24, 2013
Development status Active
Written in Assembly, C[3]
Operating system Linux, Mac OS, BSD, Solaris (x86 port) and (through chainloading) Windows
Platform IA-32, x86-64, PowerPC, SPARC, MIPS Leemote Yeelong
Available in English and others
Type Bootloader
License GNU GPLv3[4]
Website www.gnu.org/software/grub/

GNU GRUB (short for GNU GRand Unified Bootloader) 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 (a play on Grand Unified Theory[5]). It is predominantly used for Unix-like systems. The GNU operating system uses GNU GRUB as its boot loader, as do most Linux distributions. The Solaris operating system has used GRUB as its boot loader on x86 systems, starting with the Solaris 10 1/06 release.

Features

Users can dynamically configure the GRUB subsystem. GRUB loads its configuration at startup, allowing boot-time changes, such as selecting different kernels or initial RAM disks. To this end, GRUB provides a simple, bash-like, command line interface, which lets users write new boot sequences on the fly, in addition to the normal menu lists.

GRUB is highly portable. It supports multiple executable formats and is geometry-translation independent. It supports all commonly used Unix file systems, the Windows file systems FAT and NTFS, and logical block addressing (LBA). GRUB allows users to view the contents of files on any supported file system.

GRUB can download operating system boot images from network, thus supporting diskless systems. It also supports automatic decompression of the boot images before booting them. GRUB supports operating systems that do not multi-boot, by using chain loading. It uses the same two or three lines of command sequences to boot any DOS, Windows, Linux, BSD or Solaris system, making it very easy to work with it. The chain loaders for the supported Unix-like OSes are built into GRUB.

GRUB can be used with a variety of user interfaces. Most Linux distributions take advantage of GRUB's support for a graphical interface to provide a customized boot menu with a background image. A modification of GRUB's text interface can use a serial link so that a remote terminal can have access to the boot loader.

GRUB uses a scrollable screen for operating system boot selection. This means 150 or more boot choices can be easily controlled by GRUB by adding them to the grub.cfg configuration file. The arrow keys are used to select which operating system to boot. In addition to the normal menu interface, GRUB also provides a bash-like terminal command-prompt that provides a rich set of commands to allow a user to view or alter any part of the boot process. With these tools one can, without prior knowledge of what is installed on a computer, use GRUB from an external device such as a floppy disk, USB device or a CD-ROM to boot up an installed operating system.

Operation

GNU GRUB on a MBR-partitioned hard drive; stage 1 (boot.img) can alternatively be written into one of the VBRs.
GNU GRUB on a GPT-partitioned hard drive

Booting

When a computer is turned on, the computer's BIOS finds the configured primary bootable device (usually the computer's hard disk) and loads and executes the initial bootstrap program from the master boot record (MBR). The MBR is the first sector of the hard disk, with zero as its offset (sectors counting starts at zero). 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. As of October 2013, such hard disks are still accessed in 512-byte sectors, by utilizing the 512e emulation.[6]

The legacy MBR partition table supports a maximum of four partitions and occupies 64 bytes. Together with the optional disk signature (four bytes) and disk timestamp (six bytes), this leaves between 434 and 446 bytes available for the machine code of a boot loader. Although such a small space can be totally sufficient for very simple boot loaders,[7] 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(s) are stored in other locations (for example, into empty sectors between the MBR and the first partition) 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 content of those files, so it can be read from the hard disk, loaded into the RAM and executed.

One of the possible approaches for boot loaders is to load the kernel images by directly accessing hard disk sectors occupied by the actual kernel image, without understanding the underlying file system. Usually, 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, thus providing information to the boot loader about where to find the kernel image's underlying sectors. 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.[8]

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 file system 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.[8]

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 2, called GRUB 2, was written from scratch and intended to replace its predecessor GRUB version 1, and it is now used by a majority of Linux distributions. GRUB version 1, called GRUB legacy, is only prevalent in older releases of Linux distributions, among which some are still in use and supported, for example in Ubuntu 10.04 or CentOS 5.

GRUB version 1 (GRUB legacy)

The master boot record (MBR) usually contains GRUB stage 1, but can contain another bootloader which can chain boot GRUB stage 1 from another boot sector such as a partition's volume boot record. Given the small size of a boot sector (512 Bytes), 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 (within its first 1024 cylinders).

Stage 1 can load the stage 2 directly, but it is normally set up to load the stage 1.5. GRUB stage 1.5 is 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 (unusual partition table, special disk drivers, GPT or LVM disk) the install of stage 1.5 will fail. The stage 1.5 image contains file system drivers. This enables the stage 1.5 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.

GRUB version 2 (GRUB)

boot.img has the exact size of 446 bytes and is written to the MBR (sector 0). core.img is written to the empty sectors between the MBR and the first partition, if available (for legacy reasons the first partition starts at sector 63 instead of sector 1, but this is not mandatory). The /boot/grub directory can be located on an distinct partition, or on the root partition.

Once GRUB stage 2 has loaded, it presents a TUI-based operating system selection (kernel selection) menu, where the user can select which operating system to boot. GRUB can be configured to automatically load a specified kernel after a user-defined timeout; but in any case, if timeout is zero, using "Shift" while the computer is booting, one can acess to the menu.[9]

If files or the partition become unavailable, or if the user wishes to take direct control, stage 2 will drop the user to the GRUB command prompt, where the user can then manually specify the boot parameters.

In the operating system selection menu GRUB accepts a couple of commands:

Once boot options have been selected, GRUB loads the selected kernel into memory and passes control to the kernel. Alternatively, GRUB can pass control of the boot process to another boot loader, using chain loading. This is the method used to load operating systems such as Microsoft Windows, that do not support the Multiboot Specification or are not supported directly by GRUB.

If the usage of dm-crypt is intended, the contents of /boot, i.e. /boot/grub, the Linux kernel and initramfs respectively initrd need to be on a distinct non-encrypted partition, because the logic to handle encrypted partitions resides inside the Linux kernel.

Installation

The GNU GRUB (version 2) software package contains several executable files:

  1. create the directory /boot/grub if it does not exist
  2. generate the file core.img or respectively grub*.efi
  3. write boot.img to either the MBR or a volume boot record (VBR), as specified in a command-line option
  4. write core.img into space between the MBR and first partition or respectively copy grub*.efi to the EFI System partition

GRUB can be installed on removable media, such as an optical drive (BIOS access, and El Torito), floppy disk or USB flash drive, in order to bring up a system that may not have or cannot boot from a hard disk.

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.[13] 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.[13] As of 2014, the majority of Linux distributions have adopted GNU GRUB 2. Sony's PlayStation 4 also uses GNU GRUB version 2.00.[14]

Development

GRUB version 1 (also known as "GRUB Legacy") is no longer under development and is being phased out.[15] The GNU GRUB developers have switched their focus to GRUB 2,[16] 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 (IPA) 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/localization, non-ASCII characters, dynamic modules, memory management, a scripting mini-language, migrating platform specific (x86) code to platform specific modules, and an object-oriented framework. GNU GRUB version 2.00 was officially released on June 26, 2012.[1][17]

Three of the most widely used[18][19][20] Linux distributions use GRUB 2 as their mainstream boot loader. Ubuntu adopted GRUB 2 as the default boot loader in its 9.10 version of October 2009.[21] Fedora has been using GRUB 2 as its default boot loader since Fedora 16 released in November 2011.[22] openSUSE adopted GRUB 2 as the default boot loader with its 12.2 release of September 2012.[23]

Solaris also adopted GRUB2 on the x86 platform in the Solaris 11.1 release.[24]

Variants

GNU GRUB is free and open-source software, so several variants have been created. Some notables one, which have not been merged into GRUB mainline:

Utilities

GRUB configuration tools

StartUp-Manager, a program used to configure GRUB
GRUB Customizer, another tool to configure GRUB

The setup tools in use by various distributions often include modules to set up GRUB: for example, YaST2 on SUSE/openSUSE distributions and Anaconda on Fedora/RHEL distributions. StartUp-Manager and GRUB Customizer are graphical configuration editor for Debian based distributions of GRUB.

For GRUB 2 there are KDE Control Modules.[29][30]

GRLDR ICE is a tiny tool for modifying the default configuration of grldr file for GRUB4DOS.[31]

Other utilities

GRUB Utilities is a collection of multi-platform utilities for GRUB Legacy, GRUB 2 and GRUB for DOS.[32]

Boot-Repair 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[33] and will be included in the future versions of Ubuntu.[34]

See also

References

  1. 1.0 1.1 Vladimir 'φ-coder/phcoder' Serbinenko (28 Jun 2012). "GRUB 2.00 released". grub-devel (Mailing list). Retrieved 1 December 2012.
  2. ftp://alpha.gnu.org/gnu/grub/
  3. "Ohloh Analysis Summary – GNU GRUB". Ohloh. Retrieved 2010-05-12.
  4. "GNU GRUB license".
  5. EnterpriseLinux.com Definitions Definition of GRand Unified Bootloader
  6. Smith, Ryan (December 18, 2009). "Western Digital’s Advanced Format: The 4K Sector Transition Begins". AnandTech. Retrieved 2013-10-10.
  7. "mbldr (Master Boot LoaDeR)". sourceforge.net. 2009. Retrieved 2013-10-10.
  8. 8.0 8.1 "Booting and Boot Managers". SuSE. Retrieved 2013-10-10.
  9. http://www.howtogeek.com/196655/how-to-configure-the-grub2-boot-loaders-settings/
  10. "ArchWiki: Blacklist Kernel modules from GNU GRUB". 2012-11-11. Retrieved 2012-12-01.
  11. "GNU GRUB documentation".
  12. http://www.howtogeek.com/196655/how-to-configure-the-grub2-boot-loaders-settings/
  13. 13.0 13.1 GRUB Manual – 1.2 Grub History. Gnu.org (2012-06-23). Retrieved on 2012-12-01.
  14. "PS4 runs Orbis OS, a modified version of FreeBSD that's similar to Linux". extremetech.com. 2013-06-24. Retrieved 2013-10-23.
  15. GNU GRUB – GRUB Legacy. Gnu.org. Retrieved on 2012-12-01.
  16. GNU GRUB – GRUB 2 at the Wayback Machine (archived June 7, 2008).
  17. Larabel, Michael. "GRUB 2.00 Boot-Loader Officially Released". Phoronix.com. Retrieved 28 June 2012.
  18. Haddon, Tom (26 January 2012). "An Introduction to Ubuntu". WebJunction. Retrieved 21 September 2012.
  19. Janssen, Cory. "What is Red Hat Enterprise Linux (RHEL)?". Technopedia. Retrieved 21 September 2012.
  20. Varghese, Sam (2012-09-20). "SUSE chief lists progress since privatisation". Retrieved 21 September 2012.
  21. "9.10 Karmic GRUB version". Distrowatch.com. Retrieved 8 July 2012.
  22. GRUB 2. FedoraProject. Retrieved on 2012-12-01.
  23. openSUSE:Upcoming features – openSUSE. En.opensuse.org. Retrieved on 2012-12-01.
  24. Solaris 11.1. Oracle Retrieved 2015-03-19.
  25. x86: Modifying Boot Behavior by Editing the GRUB Menu at Boot Time, Modifying Solaris Boot Behavior on x86 Based Systems (Task Map) – System Administration Guide: Basic Administration
  26. x86: Supported GRUB Implementations, (System Administration Guide: Basic Administration) – Sun Microsystems
  27. 2.3 Why does Syllable have its own version of GRUB?, Syllable Documentation
  28. "TrustedGRUB project". sourceforge.net. Retrieved November 18, 2014.
  29. GRUB2 Bootloader Editor. Kde-apps.org (2012-06-18). Retrieved on 2012-12-01.
  30. Grub2 KCM Retrieved 2011-01-27
  31. Grub4Dos
  32. GRUB Utilities – Summary. Gna.org. Retrieved on 2012-12-01.
  33. Official Boot-Repair website. Sourceforge.net (2011-08-11). Retrieved on 2012-12-01.
  34. .Boot-Repair on Ubuntu Community Help Wiki. Help.ubuntu.com (2012-11-15). Retrieved on 2012-12-01.

External links

Wikimedia Commons has media related to GNU GRUB.
Wikibooks has a book on the topic of: GRUB Installation After Windows Installation