Английская Википедия:GNU GRUB

Материал из Онлайн справочника
Перейти к навигацииПерейти к поиску

Шаблон:Short description Шаблон:Redirect2 Шаблон:Use mdy dates

Шаблон:Infobox software

GNU GRUB (short for GNU GRand Unified Bootloader, commonly referred to as 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 (a play on Grand Unified Theory[1]). It is predominantly used for Unix-like systems.

Operation

Шаблон:Technical

Файл:GNU GRUB on MBR partitioned hard disk drives.svg
GRUB2 on MBR-partitioned hard drive; stage 1 (boot.img) can alternatively be written into one of the partition boot sectors.
Файл:GNU GRUB on GPT partitioned hard disk drives.svg
GRUB2 on a GPT-partitioned hard drive, booting on BIOS firmware, or UEFI compatibility mode (CSM)

Шаблон:AnchorBooting

Шаблон:See also

When a computer is turned on, its BIOS finds the primary bootable device (usually the computer's hard disk) and runs the initial bootstrap program from the master boot record (MBR). The MBR is the first sector of the hard disk. This bootstrap program must be small because it has to fit in a single sector. For a long time, the size of a sector has been 512 bytes. Since 2009 there are hard disks available with a sector size of 4096 bytes, called Advanced Format disks, but Шаблон:As of, such hard disks are still accessed in 512-byte sectors, using the 512e emulation.[2] The legacy MBR partition table supports a maximum of four partitions and occupies 64 bytes, combined. 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 sufficient for very simple boot loaders,[3] 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 therefore split into pieces, where the smallest piece fits in the MBR, while one or more larger pieces are stored in other locations such as empty sectors between the MBR and the first partition. The code in the MBR then does little more than starting the second part.

The purpose of the remaining part(s) of the boot loader is to actually boot an operating system by configuring it and starting the kernel. Kernels are in most cases stored as 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 is to load kernel images 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Шаблон:Snd 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.[4]

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 kernel images are added or moved around. The 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. Thus, fewer things can go wrong during system updates. As a downside, such boot loaders are larger and more complex.[4]

GNU GRUB uses the second approach, by understanding the underlying file systems. The boot loader itself is split into multiple stages so that it fits in 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. 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 screenshot.png
GRUB v1 menu (running as part of Ubuntu 8.04 installation)

GRUB 0.x follows a two-stage approach. The master boot record (MBR) 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 (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 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 (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, 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.

Шаблон:AnchorVersion 2 (GRUB 2)

Файл:GNU GRUB components.svg
GRUB 2 – MBR vs. GPT partitioning and boot sequence visualized (systems using BIOS firmware).

Startup on systems using BIOS firmware

  • See illustration in last image on the right.[5]
  • boot.img (stage 1) is written to the first 440 bytes of the Master Boot Record (MBR boot code in sector 0), or optionally in a partition boot sector (PBR). It addresses diskboot.img by a 64-bit LBA address. The actual sector number is written by grub-install. diskboot.img is the first sector of core.img with the sole purpose to load the rest of core.img identified by LBA sector numbers also written by grub-install.
    • On MBR partitioned disks, core.img (stage 1.5) is stored in the empty sectors (if available) between the MBR and the first partition. Recent operating systems suggest a 1 MiB gap here for alignment (2047 512-byte, or 255 4KiB, sectors). This gap used to be 62 sectors (31 KiB) as a reminder of the sector number limit of Cylinder-Head-Sector (C/H/S) addressing used by BIOS before 1996, therefore core.img is designed to be smaller than 32 KiB.
    • On GPT partitioned disks core.img is written to its own partition. It must be flagged "BIOS_grub", must not be formatted and can be as tiny as 1 MiB.
  • stage 2: core.img loads /boot/grub/i386-pc/normal.mod from the partition configured by grub-install. If the partition index has changed, GRUB will be unable to find the normal.mod, and presents the user with the GRUB Rescue prompt.
  • Depending on how GRUB2 was installed, the /boot/grub/ is either in the root partition of the Linux distribution, or in the separate /boot partition.
  • after normal.mod loaded: normal.mod parses /boot/grub/grub.cfg, optionally loads modules (eg. for graphical UI and file system support) and shows the menu.

Startup on systems using UEFI firmware

  • /efi/<distro>/grubx64.efi (for x64 UEFI systems) is installed as a file in the EFI System Partition, and booted by the firmware directly, without a boot.img in MBR sector 0. This file is like stage1 and stage1.5.
  • /boot/grub/ can be installed on the EFI System Partition or the separate /boot partition.
  • For x64 UEFI systems, stage2 are the /boot/grub/x86_64-efi/normal.mod file and other /boot/grub/ files.

After startup

GRUB presents a menu where the user can choose from operating systems (OS) found by grub-install. GRUB can be configured to automatically load a specified OS after a user-defined timeout. If the timeout is set to zero seconds, pressing and holding Шаблон:Keypress while the computer is booting makes it possible to access the boot menu.[6]

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

  • By pressing Шаблон:Key press, 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 (i.e. not editing the parameters in an already booted system) 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 (blacklisted) 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 append modprobe.blacklist=nvidia-current at the end of the kernel parameters.
  • By pressing Шаблон:Key press, 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.[7]

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 that do not support the Multiboot Specification or are not supported directly by GRUB.

Identifying partitions (UUID workaround)

A computer can have multiple hard disks connected to it. These could be identified via their SATA port. Each time the computer POSTs, the hard disk connected to port 1 (of the motherboard), could be assigned the same identifier, e.g. Шаблон:Code. But what if such consistency cannot be guaranteed? What if the constellation of connected hard disks changed from one start up to another? What if a hard disk shall be connected to another computer?

By entering Шаблон:Code into either the in GRUB rescue console (available after loading core.img ) or the GRUB console (available after loading normal.mod) a list of all available hard disks and partitions can be obtained. Either by guessing or by further investigation (e.g. Шаблон:Code) can these numbers be assigned to actual hard disks and partitions.

As it cannot be guaranteed that the numbering of hard disks via dumb numbers Шаблон:Code is consistent, GNU GRUB can use the UUID to identify partitions (actually file system instances) – that have this feature – instead.

The file systems ext2, ext3, ext4 and xfs use an Universally Unique Identifier (UUID) to uniquely identify an instance. The UUID is created when a partition is formatted. The UUID is part of the file system and written to the superblock. All operations but a formatting should leave the UUID unaltered, but it is possible to change it or duplicate it (by using dd to clone an entire partition).

The file Шаблон:Code is used to configure GRUB. It is the file where the commands which shall be executed during each start up are stored. Without an existing and valid Шаблон:Code, GRUB will present a prompt.

An absolute minimal Шаблон:Code might contain only the following two commands (cf. initial ramdisk):

linux (hd0,1)/kernel/vmlinuz-3.20.1-4 ro  # use the file name "vmlinuz-…" located in the directory /kernel on the first partition of the first hard disk as linux kernel image
initrd (hd0,1)/boot/initrd.img-3.20.1-4   # use the file named "initrd.img–…" located in the directory /boot on the first partition of the first hard disk as initial ramdisk

More fancy Шаблон:Code will describe a menu to be presented, will use multiple colors, and maybe a background picture.

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.[8] 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.[8] Шаблон:As of, the majority of Linux distributions have adopted GNU GRUB 2, as well as other systems such as Sony's PlayStation 4.[9]

Development

GRUB version 1 (also known as "GRUB Legacy") is no longer under development and is being phased out.[10] The GNU GRUB developers have switched their focus to GRUB 2,[11] 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 and 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.[12][13]

Three of the most widely used Linux distributions use GRUB 2 as their mainstream boot loader.[14][15][16] Ubuntu adopted it as the default boot loader in its 9.10 version of October 2009.[17] Fedora followed suit with Fedora 16 released in November 2011.[18] OpenSUSE adopted GRUB 2 as the default boot loader with its 12.2 release of September 2012.[19] Solaris also adopted GRUB 2 on the x86 platform in the Solaris 11.1 release.[20] Buildroot also uses GNU GRUB for x86 and x86_64 targets.

In late 2015, the exploit of pressing backspace 28 times to bypass the login password was found and quickly fixed.[21][22]

Шаблон:AnchorVariants

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 Solaris VTOC slices, automatic 64-bit kernel selection, and booting from ZFS (with compression and multiple boot environments).[23][24]
  • Google Summer of Code 2008 had a project to support GRUB legacy to boot from ext4 formatted partitions.[25]
  • The Syllable project made a modified version of GRUB to load the system from its AtheOS File System.[26]
  • TrustedGRUB extends GRUB by implementing verification of the system integrity and boot process security, using the Trusted Platform Module (TPM).[27]
  • The Intel BIOS Implementation Test Suite (BITS) 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.[28]
  • GRUB4DOS is a 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 directly from DOS, or by NTLDR or Windows Boot Manager.[29][30] GRUB4DOS is under active development and as of 2021 supports UEFI.[31]

Utilities

GRUB configuration tools

Файл:StartUp-Manager.png
StartUp-Manager, a program used to configure GRUB

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.[32] GRUB Customizer is also available for Arch-based distributions.

For GRUB 2 there are KDE Control Modules.[33][34]

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

Boot repair utilities

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.

Файл:GRUB customizer.png
GRUB Customizer

Installer for Windows

Grub2Win 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.06 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 SourceForge.

Alternative boot managers

Шаблон:See also

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 give more friendly user experience, graphical OS selector and simpler configuration:

  • rEFInd – Macintosh-style graphical boot manager, only for UEFI-based computers (BIOS not supported).
  • CloverEFI – Macintosh-style graphical boot manager for BIOS and UEFI-based computers. It emulates UEFI with a heavily modified DUET from the TianoCore project and 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 a second or third stage and the infamous GRUB Rescue prompt. The user interface looks similar to rEFInd: both inherit from the abandoned boot manager rEFIt.

Non-graphical alternatives:

  • systemd-boot – Light, UEFI-only boot manager with text-based OS selector menu.

External links

Шаблон:Commons categoryШаблон:Wikibooks

How-Tos and troubleshooting

Distribution wikis have many solutions for common issues and custom setups that might help you:

Documentation

Introductory articles

Technicalities

See also

Шаблон:Portal

Notes

Шаблон:Notelist

References

Шаблон:ReflistШаблон:GNU

  1. EnterpriseLinux.com Definitions Шаблон:Webarchive Definition of GRand Unified Bootloader
  2. Шаблон:Cite web
  3. Шаблон:Cite web
  4. 4,0 4,1 Шаблон:Cite web
  5. Шаблон:Cite web
  6. Шаблон:Cite web
  7. Шаблон:Cite web
  8. 8,0 8,1 GRUB Manual – 1.2 Grub History Шаблон:Webarchive. Gnu.org (2012-06-23). Retrieved on 2012-12-01.
  9. Шаблон:Cite web
  10. GNU GRUB – GRUB Legacy Шаблон:Webarchive. Gnu.org. Retrieved on 2012-12-01.
  11. Шаблон:Cite web.
  12. Шаблон:Cite mailing list
  13. Шаблон:Cite web
  14. Шаблон:Cite web
  15. Шаблон:Cite web
  16. Шаблон:Cite web
  17. Шаблон:Cite web
  18. GRUB 2 Шаблон:Webarchive. FedoraProject. Retrieved on 2012-12-01.
  19. openSUSE:Upcoming features – openSUSE Шаблон:Webarchive. En.opensuse.org. Retrieved on 2012-12-01.
  20. Solaris 11.1 Шаблон:Webarchive. Oracle Retrieved 2015-03-19.
  21. Шаблон:Cite web
  22. Шаблон:Cite web
  23. x86: Modifying Boot Behavior by Editing the GRUB Menu at Boot Time Шаблон:Webarchive, Modifying Solaris Boot Behavior on x86 Based Systems (Task Map) – System Administration Guide: Basic Administration
  24. x86: Supported GRUB Implementations Шаблон:Webarchive, (System Administration Guide: Basic Administration) – Sun Microsystems
  25. Шаблон:Cite web
  26. 2.3 Why does Syllable have its own version of GRUB? Шаблон:Webarchive, Syllable Documentation
  27. Шаблон:Cite web
  28. BIOS Implementation Test Suite Шаблон:Webarchive, Official BITS website
  29. Шаблон:Cite web
  30. Шаблон:Cite web
  31. Шаблон:GitHub
  32. Шаблон:Cite web
  33. GRUB2 Bootloader Editor Шаблон:Webarchive. Kde-apps.org (2012-06-18). Retrieved on 2012-12-01.
  34. Шаблон:Cite web
  35. Шаблон:Cite web