BIOS boot partition
View on WikipediaThis article needs additional citations for verification. (June 2014) |
The BIOS boot partition is a partition on a data storage device that GNU GRUB uses on legacy BIOS-based personal computers in order to boot an operating system, when the actual boot device contains a GUID Partition Table (GPT). Such a layout is sometimes referred to as BIOS/GPT boot.[1]
A BIOS boot partition is needed on GPT-partitioned storage devices to hold the second stages of GRUB. On traditional MBR-partitioned devices, the disk sectors immediately following the first are usually unused, as the partitioning scheme does not designate them for any special purpose and partitioning tools avoid them for alignment purposes. On GPT-based devices, the sectors hold the actual partition table, necessitating the use of an extra partition. On MBR-partitioned disks, boot loaders are usually implemented so the portion of their code stored within the MBR, which cannot hold more than 512 bytes, operates as a first stage that serves primarily to load a more sophisticated second stage, which is, for example, capable of reading and loading an operating system kernel from a file system.
Overview
[edit]
When used, the BIOS boot partition contains the second stage of the boot loader program, such as the GRUB 2; the first stage is the code that is contained within the Master Boot Record (MBR). Use of this partition is not the only way BIOS-based boot can be performed while using GPT-partitioned hard drives; however, complex boot loaders such as GRUB 2 cannot fit entirely within the confines of the MBR's 398 to 446 bytes of space, thus they need an ancillary storage space. On MBR disks, such boot loaders typically use the sectors immediately following the MBR for this storage; that space is usually known as the "MBR gap". No equivalent unused space exists on GPT disks, and the BIOS boot partition is a way to officially allocate such space for use by the boot loader.
The globally unique identifier (GUID) for the BIOS boot partition in the GPT scheme is 21686148-6449-6E6F-744E-65656445464916[2]
[3] (which, when written to a GPT in the required little endian fields, forms the ASCII string "Hah!IdontNeedEFI"). In the context of GPT on a BIOS-based computer, a BIOS boot partition is similar in some respects to the EFI system partition, which is used by systems based on EFI. The EFI System partition holds a filesystem and files used by the UEFI, while the BIOS boot partition is used in BIOS-based systems and accessed without a filesystem by holding raw binary code.
The size requirements for a BIOS boot partition are quite low so it can be as small as about 30 KiB; however, as future boot loaders might require more space, 1 MiB might be a reasonable BIOS boot partition size. Due to the 1 MiB partition alignment policies used by most modern disk partitioning tools to provide optimum performance with Advanced Format disks, SSD devices and certain RAID configurations, some room is left allowing the placement of a BIOS boot partition between the GPT and the first partition aligned that way (34–2047 for 512-byte sectors; 6–255 for 4096-byte sectors). If created by utilizing that free space, the BIOS boot partition would be out of the GPT alignment specification,[4] but that is not very important since: (a) the alignment rule is "should" and not "must" (b) the rule is based on a performance consideration, which for a very small partition used only at system boot bears no real consequence.
Creation
[edit]The following utilities are known to support BIOS boot partitions:
See also
[edit]References
[edit]- ^ "GUID Partition Table". archlinux.org. 2015-03-19. Retrieved 2015-03-05.
- ^ "GNU GRUB Installation, Section 3.4: BIOS installation". gnu.org. Retrieved 2014-06-26.
- ^ "parttypes.cc in the gptfdisk source code". gptfdisk project on sourceforge.net. Retrieved 2023-05-03.
- ^ See https://uefi.org/specs/UEFI/2.10/05_GUID_Partition_Table_Format.html, "GPT partitions should be aligned to the larger of: GPT partitions should be aligned to the larger of: a – The physical block boundary, if any; b – The optimal transfer length granularity, if any."
External links
[edit]- BIOS installation, part of the GRUB2 documentation
- The Funtoo Linux GUID Booting Guide
- Booting from GPT, part of the GPT fdisk documentation
- Legacy BIOS issues with GPT, February 22, 2014, by Rod Smith
BIOS boot partition
View on Grokipediagrub-install command, the tool automatically detects and overwrites a portion of this partition with the bootloader code, provided it is marked with the appropriate type.[1]
The partition must be created before installing GRUB and should contain no other data to avoid loss during embedding.[1] Its recommended size is 1 MiB, though the absolute minimum is 31 KiB to accommodate the core image and allow for future expansions; it remains unformatted with no filesystem and is never mounted.[1] Identification uses the GPT partition type GUID 21686148-6449-6E6F-744E-656564454649 (or hexadecimal code EF02 in tools like gdisk), which signals to GRUB and partitioning utilities its dedicated purpose.[1] Tools such as GNU Parted can set the bios_grub flag during creation, ensuring seamless integration in BIOS/GPT configurations.[1]
Background and Purpose
Definition and Role
The BIOS boot partition is a small, unformatted partition on disks employing the GUID Partition Table (GPT) partitioning scheme, specifically designated to store the second-stage bootloader—typically the core image of the GRUB bootloader—in legacy BIOS boot environments.[1] This partition plays a crucial role in enabling the booting of operating systems from GPT-formatted disks on systems using legacy BIOS firmware, which does not natively support GPT and thus requires a dedicated space for bootloader code that exceeds the constraints of the GPT protective Master Boot Record (MBR).[1] In contrast to the MBR partitioning scheme, where the bootloader can be embedded in the post-MBR gap preceding the first partition, GPT lacks such an unallocated area, necessitating this separate partition to accommodate the bootloader without risking overwrites or relocation by filesystem tools.[1] The GPT scheme itself represents a modern evolution in disk partitioning, supporting drives larger than 2 terabytes—addressing MBR's 2.2 terabyte limit—and allowing up to 128 primary partitions with enhanced data integrity through cyclic redundancy checks (CRC) and a backup partition table header.[2][3] Despite these advantages, legacy BIOS systems cannot directly access GPT structures for booting, making the BIOS boot partition essential to bridge this compatibility gap.[1] As raw storage without a mountable filesystem, the BIOS boot partition ensures the bootloader remains isolated from routine disk operations, such as defragmentation or resizing, thereby maintaining boot reliability; GRUB embeds its core image directly into this space during installation.[1]Historical Development
The BIOS boot partition emerged in the mid-2000s during the development of GNU GRUB 2, a major rewrite of the original GRUB bootloader initiated around 2005 to enhance support for modern disk partitioning schemes, including the GUID Partition Table (GPT). This feature addressed the challenges of booting from GPT-formatted disks on legacy BIOS systems, where traditional Master Boot Record (MBR) boot sectors were absent, preventing direct compatibility with GRUB's multi-stage loading process.[1] A key milestone occurred with the release of GRUB 2.00 in June 2012, which stabilized GPT support for BIOS environments and aligned with the increasing use of GPT in Linux distributions to handle disks exceeding 2 TB in capacity, a limitation of the MBR scheme.[4] Prior beta versions, such as GRUB 1.97 in 2009, had already incorporated early GPT booting capabilities, enabling experimental use in distributions like Ubuntu 9.10.[5] The primary motivations for creating the BIOS boot partition stemmed from GPT's structural differences: unlike MBR, GPT reserves the initial sectors (typically 1-33) for protective headers and partition tables, leaving no post-MBR gap for embedding GRUB's core image without risking overwrites by filesystems or alignment tools.[1] This solution was particularly vital during the transition to UEFI firmware in the late 2000s, as it facilitated hybrid setups allowing legacy BIOS compatibility with GPT disks, avoiding the need to revert to MBR for older hardware.[1] Adoption accelerated in the 2010s as partitioning tools gained dedicated support; GNU Parted, which added GPT handling in version 1.8 (2006), and gdisk (part of the GPT fdisk suite, released in 2009), introduced flags and types like EF02 for BIOS boot partitions. By 2012, major Linux installers, including those for Ubuntu and Fedora, routinely prompted for or created BIOS boot partitions in BIOS-GPT configurations, solidifying its role as a standard for large-disk setups.[6] This timeline reflected broader GPT proliferation, driven by affordable multi-terabyte drives and the push for robust, scalable partitioning beyond MBR's constraints. This trend continued, with Fedora adopting GPT as the default partitioning scheme even for BIOS systems starting with Fedora 37 in 2022.[6]Technical Specifications
Partition GUID and Structure
The BIOS boot partition is identified in GPT disk layouts by the unique partition type GUID 21686148-6449-6E6F-744E-656564454649, which corresponds to the hexadecimal code EF02 used by partitioning tools such as gdisk.[1][7] This GUID designates the partition specifically for storing GRUB's second-stage boot loader on BIOS-based systems with GPT partitioning, distinguishing it from other partition types like the EFI System Partition.[8] In terms of structure, the BIOS boot partition contains no filesystem, such as ext2 or FAT, and is formatted as raw disk space to directly hold embedded boot code without the overhead or risks associated with filesystem management.[1] The partition must be located within the first 2 TiB of the disk to ensure accessibility by legacy BIOS firmware.[8] It typically occupies unallocated sectors immediately after the GPT header, starting from sector 34 (the first usable sector post-header) and extending to around sector 2047, ensuring compatibility with the protective MBR at the disk's beginning and leaving room for the first aligned data partition.[9] GRUB embeds its core image (core.img) directly into this raw space during installation, overwriting the partition contents as needed for boot sector functionality.[1] To maintain integrity, the partition must remain unmounted and excluded from any filesystem operations, scans, or mounts to prevent accidental corruption of the embedded GRUB code.[1] Partitioning tools like GNU Parted apply the "bios_grub" flag to mark it appropriately, signaling its dedicated role without altering its raw nature.[10] For optimal performance on modern drives, including those with Advanced Format sectors, the partition is recommended to align on 1 MiB boundaries, avoiding overlap with GPT protective elements and ensuring efficient access patterns.[7]Size and Contents
The BIOS boot partition has a minimum size requirement of 31 KiB to accommodate the basic GRUB core image on GPT-partitioned disks.[1] This minimal allocation ensures sufficient space for the essential bootloader components without a filesystem, as the partition is unformatted and dedicated solely to GRUB's embedding needs.[1] However, a recommended size of 1 MiB is advised to allow for growth in GRUB modules and future updates, providing ample room while minimizing waste on smaller storage devices.[1] The actual size required depends on the specific GRUB configuration, but it rarely exceeds 32 MiB even in complex setups with additional embedded drivers.[11] The primary content of the BIOS boot partition is thecore.img file, which serves as GRUB's core image and embeds critical booting functionality.[11] This image is dynamically generated using grub-mkimage and combines the GRUB kernel—providing basic runtime facilities such as device and file handling, environment variables, and rescue mode—with a selection of modules necessary for accessing the /boot/grub directory.[11] It incorporates stage 1.5-like capabilities from GRUB Legacy, including code for loading additional modules at runtime via the insmod command and pointers to the /boot filesystem for locating configuration files and kernels.[11] Embedded filesystem drivers within core.img enable support for advanced disk layouts, such as LVM or RAID, allowing GRUB to read from the root partition without relying on an external filesystem in the boot partition itself.[11]
Larger partition sizes permit the inclusion of extra GRUB components, such as trusted boot modules for digital signature verification, enhancing security in environments requiring enforced boot integrity.[12] Nonetheless, excessive sizing beyond 2 MiB is generally unnecessary and can inefficiently consume space, particularly on compact disks where every sector counts.[1]
After installation, the partition's contents can be verified using tools like dd to extract the raw data and hexdump to inspect it for the presence of the GRUB binary, confirming the core.img embedding without mounting or formatting.[13] This method reveals identifiable strings, such as "GRUB," in the binary data, validating the bootloader's placement.[13]
Creation and Management
Partitioning Tools and Methods
Creating a BIOS boot partition requires partitioning tools that support GPT disk labels, as the partition is specifically designed for GPT-based setups in BIOS mode. Common command-line tools includegdisk, fdisk (with GPT support), and parted, each offering ways to allocate space, set the appropriate partition type, and apply necessary flags without formatting the partition. These tools ensure the partition is unformatted and usually created as the first partition, aligned to 1 MiB boundaries (starting at sector 2048), with a recommended size of 1 MiB to accommodate GRUB's second-stage code.[14][15]
With gdisk, a GPT-specific utility, users start by launching it on the target disk (e.g., gdisk /dev/sda), then use the n command to create a new partition, accepting the default first sector, and specifying the last sector as +1M; afterward, the t command sets the type to EF02 (BIOS boot partition). Verification is done via the p command to print the partition table and confirm the type.[15][16]
The fdisk tool allows creation of a GPT label by running fdisk /dev/sda, then using g inside the prompt, followed by n for a new partition of 1 MiB (default first sector, last sector +1M), and t with type EF02 to designate it as BIOS boot; the p command prints details for confirmation.[17][18]
For parted, users select the disk (e.g., parted /dev/sda), create the partition with mkpart primary 1MiB 2MiB (unformatted, no filesystem), and set the bios_grub flag using set 1 bios_grub on; the print command verifies the flag and structure. This flag signals GRUB that the partition holds boot code.[10][19]
In Linux distribution installers, the process is often automated when GPT partitioning and BIOS boot mode are selected. For Ubuntu's Ubiquity installer, it detects the GPT setup in legacy BIOS mode and creates the unformatted BIOS boot partition (typically 1 MiB) before the /boot partition during guided or manual partitioning. Similarly, Fedora's Anaconda installer automatically provisions a BIOS boot partition of about 1 MiB when installing on a GPT disk in BIOS mode, ensuring compatibility without user intervention in standard setups.[20][21][22]
Best practices include backing up all data on the disk prior to partitioning to prevent loss, as operations are destructive; always verify the partition table after creation using the respective tool's print function to confirm the type (EF02) or flag (bios_grub) and position before the /boot partition; and for custom setups, ensure the partition remains unmounted and unformatted to avoid interference with GRUB installation.[14][23]
GRUB Installation Process
The installation of the GRUB bootloader into a BIOS boot partition requires specific prerequisites to ensure proper embedding and functionality on BIOS systems using a GUID Partition Table (GPT). The BIOS boot partition must already exist with the correct type GUID of 21686148-6449-6e6f-744e-656564454649 (EF02) and the bios_grub flag set, typically using tools like parted or gdisk, and it should be unformatted and empty as GRUB will overwrite its contents.[1] Additionally, the root filesystem must be mounted, with the /boot directory accessible and containing necessary GRUB configuration files such as grub.cfg, which is generated via grub-mkconfig.[8] If performing the installation post-operating system setup from a live environment, a chroot into the target system is required to access the mounted filesystems.[24] The core installation process begins with the grub-install command, executed as root:grub-install --target=i386-pc /dev/sdX, where /dev/sdX represents the target disk (not a specific partition) and i386-pc specifies the BIOS platform.[8] This command prompts GRUB to scan the disk for the BIOS boot partition identified by its EF02 GUID, locate the /boot/grub directory for modules, and embed the core.img file directly into the partition.[1] The core.img includes embedded paths to essential modules like normal.mod, enabling GRUB to load the full bootloader without relying on a filesystem in the post-MBR gap, which is unavailable in GPT layouts.[8] If BIOS drive mapping is required for legacy hardware compatibility, GRUB may generate or update a device.map file during configuration generation with grub-mkconfig -o /boot/grub/grub.cfg.
In a chrooted live environment scenario, the process involves first mounting the root partition (e.g., mount /dev/sdXY /mnt), binding essential virtual filesystems (e.g., /dev, /proc, /sys), entering chroot (chroot /mnt), and then running grub-install followed by update-grub (or grub-mkconfig) to finalize the configuration.[24] This ensures GRUB's stage 1.5 (core.img) is correctly placed for BIOS chainloading to the /boot/grub stages.[1]
Verification of the installation can be performed without committing changes by using the --dry-run option: grub-install --target=i386-pc /dev/sdX --dry-run, which simulates the embedding process and reports any issues like missing partitions.[8] Additionally, grub-probe can confirm device recognition: grub-probe --target=device /boot, ensuring GRUB correctly identifies the boot filesystem and partition layout. Successful installation results in GRUB being ready to boot the system upon BIOS initialization.[24]