Master boot record

This article is about a PC-specific type of boot sector on partitioned media. For the first sector on non-partitioned media, see volume boot record.

A master boot record (MBR) is a special type of boot sector at the very beginning of partitioned computer mass storage devices like fixed disks or removable drives intended for use with IBM PC-compatible systems and beyond. The concept of MBRs was publicly introduced in 1983 with PC DOS 2.0.

The MBR holds the information on how the logical partitions, containing file systems, are organized on that medium. The MBR also contains executable code to function as a loader for the installed operating system—usually by passing control over to the loader's second stage, or in conjunction with each partition's volume boot record (VBR). This MBR code is usually referred to as a boot loader.[1]

The organization of the partition table in the MBR limits the maximum addressable storage space of a disk to 2 TiB (232 × 512 bytes).[2] Therefore, the MBR-based partitioning scheme is in the process of being superseded by the GUID Partition Table (GPT) scheme in new computers. A GPT can coexist with an MBR in order to provide some limited form of backward compatibility for older systems.

MBRs are not present on non-partitioned media such as floppies, superfloppies or other storage devices configured to behave as such.

Overview

Support for partitioned media, and thereby the master boot record (MBR), was introduced with IBM PC DOS 2.0 in March 1983 in order to support the 10 MB hard disk of the then-new IBM Personal Computer XT, still using the FAT12 file system. The original version of the MBR was written by David Litton of IBM in June 1982. The partition table supported up to four primary partitions, of which DOS could only use one. This did not change when FAT16 was introduced as a new file system with DOS 3.0. Support for an extended partition, a special primary partition type used as a container to hold other partitions, was added with DOS 3.2, and nested logical drives inside an extended partition came with DOS 3.30. Since MS-DOS, PC DOS, OS/2 and Windows were never enabled to boot off them, the MBR format and boot code remained almost unchanged in functionality, except for in some third-party implementations, throughout the eras of DOS and OS/2 up to 1996.

In 1996, support for logical block addressing (LBA) was introduced in Windows 95B and DOS 7.10 in order to support disks larger than 8 GB. Disk timestamps were also introduced, though the description of their actual purpose is not available.[3] This also reflected the idea that the MBR is meant to be operating system and file system independent. However, this design rule was partially compromised in more recent Microsoft implementations of the MBR, which enforce CHS access for FAT16B and FAT32 partition types 06hex/0Bhex, whereas LBA is used for 0Ehex/0Chex.

Despite sometimes poor documentation of certain intrinsic details of the MBR format (which occasionally caused compatibility problems), it has been widely adopted as a de facto industry standard, due to the broad popularity of PC-compatible computers and its semi-static nature over decades. This was even to the extent of being supported by computer operating systems for other platforms. Sometimes this was in addition to other pre-existing or cross-platform standards for bootstrapping and partitioning.[4]

MBR partition entries and the MBR boot code used in commercial operating systems, however, are limited to 32 bits. Therefore, the maximum disk size supported on disks using 512-byte sectors (whether real or emulated) by the MBR partitioning scheme (without using non-standard methods) is limited to 2 TiB. Consequently, a different partitioning scheme must be used for larger disks, as they have become widely available since 2010. The MBR partitioning scheme is therefore in the process of being superseded by the GUID Partition Table (GPT). The official approach does little more than ensuring data integrity by employing a protective MBR. Specifically, it does not provide backward compatibility with operating systems that do not support the GPT scheme as well. In the meanwhile, multiple forms of hybrid MBRs have been designed and implemented by third parties in order to maintain partitions located in the first physical 2 TiB of a disk in both partitioning schemes "in parallel" and/or to allow older operating systems to boot off GPT partitions as well. The present non-standard nature of these solutions causes various compatibility problems in certain scenarios.

The MBR consists of 512 or more bytes located in the first sector of the drive.

It may contain one or more of:

Disk partitioning

IBM PC DOS 2.0 introduced the FDISK utility to set up and maintain MBR partitions. When a storage device has been partitioned according to this scheme, its MBR contains a partition table describing the locations, sizes, and other attributes of linear regions referred to as partitions.

The partitions themselves may also contain data to describe more complex partitioning schemes, such as extended boot records (EBRs), BSD disklabels, or Logical Disk Manager metadata partitions.[10]

The MBR is not located in a partition; it is located at a first sector of the device (physical offset 0), preceding the first partition. (The boot sector present on a non-partitioned device or within an individual partition is called a volume boot record instead.) In cases where the computer is running a DDO BIOS overlay or boot manager, the partition table may be moved to some other physical location on the device; e.g., Ontrack Disk Manager often placed a copy of the original MBR contents in the second sector, then hid itself from any subsequently booted OS or application, so the MBR copy was treated as if it were still residing in the first sector.

Sector layout

By convention, there are exactly four primary partition table entries in the MBR partition table scheme, although some operating systems and system tools extended this to five (Advanced Active Partitions (AAP) with PTS-DOS 6.60[11] and DR-DOS 7.07), eight (AST and NEC MS-DOS 3.x[12][13] as well as Storage Dimensions SpeedStor), or even sixteen entries (with Ontrack Disk Manager).

Structure of a classical generic MBR
Address Description Size
(bytes)
Hex Dec
+000hex +0 Bootstrap code area 446
+1BEhex +446 Partition entry №1 Partition table
(for primary partitions)
16
+1CEhex +462 Partition entry №2 16
+1DEhex +478 Partition entry №3 16
+1EEhex +494 Partition entry №4 16
+1FEhex +510 55hex Boot signature[lower-alpha 1] 2
+1FFhex +511 AAhex
Total size: 446 + 4×16 + 2 512

Structure of a modern standard MBR
Address Description Size
(bytes)
Hex Dec
+000hex +0 Bootstrap code area (part 1) 218
+0DAhex +218 0000hex Disk timestamp[5][lower-alpha 2] (optional, MS-DOS 7.1–8.0 and Windows 95B/98/98SE/ME. Alternatively, can serve as OEM loader signature with NEWLDR) 2
+0DChex +220 Original physical drive (80hexFFhex) 1
+0DDhex +221 Seconds (0–59) 1
+0DEhex +222 Minutes (0–59) 1
+0DFhex +223 Hours (0–23) 1
+0E0hex +224 Bootstrap code area (part 2, code entry at +000hex) 216
(or 222)
+1B8hex +440 32-bit disk signature Disk signature (optional, UEFI, Windows NT/2000/Vista/7 and other OSes) 4
+1BChex +444 0000hex
(5A5Ahex if copy-protected)
2
+1BEhex +446 Partition entry №1 Partition table
(for primary partitions)
16
+1CEhex +462 Partition entry №2 16
+1DEhex +478 Partition entry №3 16
+1EEhex +494 Partition entry №4 16
+1FEhex +510 55hex Boot signature[lower-alpha 1] 2
+1FFhex +511 AAhex
Total size: 218 + 6 + 216 + 6 + 4×16 + 2 512

Structure of AAP MBR
Address Description Size
(bytes)
Hex Dec
+000hex +0 Bootstrap code area 428
+1AChex +428 78hex AAP signature (optional) 2
+1ADhex +429 56hex
+1AEhex +430 AAP physical drive (80hex-FEhex; 00hex: not used; 01hex-7Fhex, FFhex: reserved) AAP record (optional) (AAP partition entry #0 with special semantics) 1
+1AFhex +431 CHS (start) address of AAP partition/image file or VBR/EBR 3
+1B2hex +434 Reserved for AAP partition type (00hex if not used) (optional) 1
+1B3hex +435 Reserved for CHS end address in AAP (optional; byte at offset +1B5hex is also used for MBR checksum (PTS DE, BootWizard); 000000hex if not used) 3
+1B6hex +438 Start LBA of AAP image file or VBR/EBR or relative sectors of AAP partition (copied to offset +01Chex in the loaded sector over the "hidden sectors" entry of a DOS 3.31 BPB (or emulation thereof) to also support EBR booting) 4
+1BAhex +442 Reserved for sectors in AAP (optional; 00000000hex if not used) 4
+1BEhex +446 Partition entry №1 Partition table
(for primary partitions)
16
+1CEhex +462 Partition entry №2 16
+1DEhex +478 Partition entry №3 16
+1EEhex +494 Partition entry №4 16
+1FEhex +510 55hex Boot signature[lower-alpha 1] 2
+1FFhex +511 AAhex
Total size: 428 + 2 + 16 + 4×16 + 2 512

Structure of NEWLDR MBR
Address Description Size
(bytes)
Hex Dec
+000hex +0 JMPS (EBhex) / NEWLDR record size (often 0Ahex/16hex/1Chex for code start at +00Chex/+018hex/+01Ehex) NEWLDR record (optional) 2
+002hex +2 "NEWLDR" signature 6
+008hex +8 LOADER physical drive and boot flag (80hex-FEhex, 00hex-7Ehex, FFhex, 7Fhex) (if not used, this and following 3 bytes must be all 0) 1
+009hex +9 CHS address of LOADER boot sector or image file (f.e. IBMBIO.LDR) (000000hex if not used) 3
+00Chex +12 Allowed DL minimum, else take from partition table (80hex: default; 00hex: always use DL; FFhex: always use table entry) 1
+00Dhex +13 Reserved (default: 000000hex) 3
+010hex +16 LBA of LOADER boot sector or image file (optional, 00000000hex if not used) 4
+014hex +20 Patch offset of VBR boot unit (default 0000hex if not used, else 0024hex or 01FDhex) 2
+016hex +22 Checksum (0000hex if not used) 2
+018hex +24 OEM loader signature ("MSWIN4" for REAL/32, see also offset +0DAhex, corresponds with OEM label at offset +003hex in VBRs (optional) 6
Varies Varies Bootstrap code area (code entry at +000hex) Varies
+1AChex +428 78hex AAP signature (optional) 2
+1ADhex +429 56hex
+1AEhex +430 AAP partition entry №0 with special semantics AAP record (optional) 16
+1BEhex +446 Partition entry №1 Partition table
(for primary partitions)
16
+1CEhex +462 Partition entry №2 16
+01DEhex +478 Partition entry №3 16
+1EEhex +494 Partition entry №4 16
+1FEhex +510 55hex Boot signature[lower-alpha 1] 2
+1FFhex +511 AAhex
Total size: 30 + 398 + 2 + 16 + 4×16 + 2 512

Structure of AST/NEC MS-DOS and SpeedStor MBR
Address Description Size
(bytes)
Hex Dec
+000hex +0 Bootstrap code area 380
+17Chex +380 5Ahex AST/NEC signature (optional, not for SpeedStor) 2
+17Dhex +381 A5hex
+17Ehex +382 Partition entry №8 AST/NEC expanded partition table
(optional, also for SpeedStor)
16
+18Ehex +398 Partition entry №7 16
+19Ehex +414 Partition entry №6 16
+1AEhex +430 Partition entry №5 16
+1BEhex +446 Partition entry №4 Partition table
(for primary partitions)
16
+1CEhex +462 Partition entry №3 16
+1DEhex +478 Partition entry №2 16
+1EEhex +494 Partition entry №1 16
+1FEhex +510 55hex Boot signature[lower-alpha 1] 2
+1FFhex +511 AAhex
Total size: 380 + 2 + 4×16 + 4×16 + 2 512

Structure of Disk Manager MBR
Address Description Size
(bytes)
Hex Dec
+000hex +0 Bootstrap code area 252
+0FChex +252 AAhex DM signature (optional) 2
+0FDhex +253 55hex
+0FEhex +254 Partition entry DM expanded partition table
(optional)
16
+10Ehex +270 Partition entry 16
+11Ehex +286 Partition entry 16
+12Ehex +302 Partition entry 16
+13Ehex +318 Partition entry 16
+14Ehex +334 Partition entry 16
+15Ehex +350 Partition entry 16
+16Ehex +366 Partition entry 16
+17Ehex +382 Partition entry 16
+18Ehex +398 Partition entry 16
+19Ehex +414 Partition entry 16
+1AEhex +430 Partition entry 16
+1BEhex +446 Partition entry №1 Partition table
(for primary partitions)
16
+1CEhex +462 Partition entry №2 16
+1DEhex +478 Partition entry №3 16
+1EEhex +494 Partition entry №4 16
+1FEhex +510 55hex Boot signature[lower-alpha 1] 2
+1FFhex +511 AAhex
Total size: 252 + 2 + 12×16 + 4×16 + 2 512

Partition table entries

Layout of one 16-byte partition entry[14] (all multi-byte fields are little-endian)
Offset
(bytes)
Field
length
Description
+0hex 1 byte Status or physical drive (bit 7 set is for active or bootable, old MBRs only accept 80hex, 00hex means inactive, and 01hex7Fhex stand for invalid)[lower-alpha 3]
+1hex 3 bytes CHS address of first absolute sector in partition.[lower-alpha 4] The format is described by three bytes, see the next three rows.
+1hex 1 byte
h70 head[lower-alpha 5]
x x x x x x x x
+2hex 1 byte
c98 s50 sector in bits 50; bits 76 are high bits of cylinder[lower-alpha 5]
x x x x x x x x
+3hex 1 byte
c70 bits 70 of cylinder[lower-alpha 5]
x x x x x x x x
+4hex 1 byte Partition type[16]
+5hex 3 bytes CHS address of last absolute sector in partition.[lower-alpha 4] The format is described by 3 bytes, see the next 3 rows.
+5hex 1 byte
h70 head[lower-alpha 5]
x x x x x x x x
+6hex 1 byte
c98 s50 sector in bits 50; bits 76 are high bits of cylinder[lower-alpha 5]
x x x x x x x x
+7hex 1 byte
c70 bits 70 of cylinder
x x x x x x x x
+8hex 4 bytes LBA of first absolute sector in the partition[lower-alpha 6]
+Chex 4 bytes Number of sectors in partition[lower-alpha 6]

An artifact of hard disk technology from the era of the PC XT, the partition table subdivides a storage medium using units of cylinders, heads, and sectors (CHS addressing). These values no longer correspond to their namesakes in modern disk drives, as well as being irrelevant in other devices such as solid-state drives which do not physically have cylinders or heads.

In the CHS scheme, sector indices have (almost) always begun with sector 1 rather than sector 0 by convention, and due to an error in all versions of MS-DOS/PC DOS up to including 7.10, the number of heads is generally limited to 255 instead of 256. When a CHS address is too large to fit into these fields, the tuple (1023, 254, 63) is typically used today, although on older systems, and with older disk tools, the cylinder value often wrapped around modulo the CHS barrier near 8 GB, causing ambiguity and risks of data corruption. (If the situation involves a "protective" MBR on a disk with a GPT, Intel's Extensible Firmware Interface specification requires that the tuple (1023, 255, 63) be used.) The 10-bit cylinder value is recorded within two bytes in order to facilitate making calls to the original/legacy INT 13h BIOS disk access routines, where 16 bits were divided into sector and cylinder parts, and not on byte boundaries.[15]

Due to the limits of CHS addressing,[18][19] a transition was made to using LBA or logical block addressing. Both the partition length and partition start address are sector values stored in the partition table entries as 32-bit quantities. The sector size used to be considered fixed at 512 (29) bytes, and a broad range of important components including chipsets, boot sectors, operating systems, database engines, partitioning tools, backup and file system utilities and other software had this value hard-coded. Since the end of 2009, disk drives using a new technology known as Advanced Format and employing 4,096-byte sectors (4Kn) have been available, although the size of the sector for some of these drives was still reported as 512 bytes to the host system through conversion in the hard drive firmware and referred to as 512 emulation drives (512e).

Since block addresses and sizes are stored in the partition table of an MBR using 32 bits, the maximum size as well as the highest start address of a partition using drives that have 512-byte sectors (actual or emulated) cannot exceed 2 TiB−512 bytes (2,199,023,255,040 bytes or 4,294,967,295 (232−1) sectors × 512 (29) bytes per sector). Alleviating this capacity limitation was one of the prime motivations for the development of the GPT.

Since partitioning information is stored in the MBR partition table using a beginning block address and a length, it may in theory be possible to define partitions in such a way that the allocated space for a disk with 512-byte sectors gives a total size approaching 4 TiB, if all but one partition are located below the 2 TiB limit and the last one is assigned as starting at or close to block 232−1 and specify the size as up to 232−1, thereby defining a partition which requires 33 rather than 32 bits for the sector address to be accessed. However, in practice, only certain LBA-48 enabled operating systems, including GNU/Linux, FreeBSD and Windows 7[20] that use 64-bit sector addresses internally actually support this. Due to code space constraints and the nature of the MBR partition table to only support 32 bits, boot sectors, even if enabled to support LBA-48 rather than LBA-28, often use 32-bit calculations, unless they are specifically designed to support the full address range of LBA-48 or are intended to run on 64-bit platforms only. Any boot code or operating system using 32-bit sector addresses internally would cause addresses to wrap around accessing this partition and thereby result in serious data corruption over all partitions.

For disks that present a sector size other than 512 bytes, such as USB external drives, there are limitations as well. A sector size of 4,096 results in an eight-fold increase in the size of a partition that can be defined using MBR, allowing partitions up to 16 TiB (232 × 4096 bytes) in size.[21] Versions of Windows more recent than Windows XP support the larger sector sizes as well as Mac OS X, and Linux has supported larger sector sizes since 2.6.31[22] or 2.6.32,[23] but issues with boot loaders, partitioning tools and computer BIOS implementations present certain limitations,[24] since they are often hard-wired to reserve only 512 bytes for sector buffers, causing memory to become overwritten for larger sector sizes. This may cause unpredictable behaviour as well, and therefore should be avoided when compatibility and standard conformity is an issue.

Where a data storage device has been partitioned with the GPT scheme, the master boot record will still contain a partition table, but its only purpose is to indicate the existence of the GPT and to prevent utility programs which understand only the MBR partition table scheme from creating any partitions in what they would otherwise see as free space on the disk, thereby accidentally erasing the GPT.

System bootstrapping

On IBM PC-compatible computers, the bootstrapping firmware contained within the ROM BIOS loads and executes the master boot record.[25] The PC/XT (type 5160) used an Intel 8088 microprocessor. In order to remain compatible, all x86 architecture systems start with the microprocessor in an operating mode referred to as real mode. The BIOS reads the MBR from the storage device into physical memory, and then it directs the microprocessor to the start of the boot code. Since the BIOS runs in real mode, the processor is in real mode when the MBR program begins to execute, and so the beginning of the MBR is expected to contain real mode machine language instructions.[25]

Due to the restricted size of the MBR's code section, it typically contains only a small program that copies additional code (such as a boot loader) from the storage device into memory. Control is then passed to this code, which is responsible for loading the actual operating system. This process is known as chain loading.

Popular MBR code programs were created for booting PC DOS and MS-DOS, and similar boot code remains in wide use. These boot sectors expect the fdisk partition table scheme to be in use, and scans the list of partitions in the MBR's embedded partition table to find the only one that is marked with the active flag.[26] It then loads and runs the volume boot record (VBR) of the active partition.

There are alternative boot code implementations, some of which are installed by boot managers, which operate in a variety of ways. Some MBR code loads additional code for a boot manager from the first track of the disk, which it assumes to be "free" space that is not allocated to any disk partition, and executes it. A MBR program may interact with the user to determine which partition on which drive should boot, and may transfer control to the MBR of a different drive. Other MBR code contains a list of disk locations (often corresponding to the contents of files in a filesystem) of the remainder of the boot manager code to load and to execute. (The first relies on behavior that is not universal across all disk partitioning utilities, most notably those which read and write GPTs. The last requires that the embedded list of disk locations be updated when changes are made that would relocate the remainder of the code.)

On machines that do not use x86 processors, or on x86 machines with non-BIOS firmware such as Open Firmware or Extensible Firmware Interface (EFI) firmware, this design is unsuitable, and the MBR is not used as part of the system bootstrap.[27] EFI firmware is instead capable of directly understanding the GPT partitioning scheme and the FAT filesystem format, and loads and runs programs held as files in the EFI System partition.[28] The MBR will be involved only insofar as it might contain a partition table for compatibility purposes if the GPT partition table scheme has been used.

There is some MBR replacement code that emulates EFI firmware's bootstrap, which makes non-EFI machines capable of booting from disks using the GPT partitioning scheme. It detects a GPT, places the processor in the correct operating mode, and loads the EFI compatible code from disk to complete this task.

Disk identity

Information contained in the Partition Table of an external hard drive as it appears in the utility program QtParted, running under GNU/Linux

In addition to the bootstrap code and a partition table, master boot records may contain a disk signature. This is a 32-bit value that is intended to identify uniquely the disk medium (as opposed to the disk unit—the two not necessarily being the same for removable hard disks).

The disk signature was introduced by Windows NT version 3.5, but it is now used by several operating systems, including the GNU/Linux kernel version 2.6 and later. GNU/Linux tools can use the NT disk signature to determine which disk the machine booted from.[29]

Windows NT (and later Microsoft operating systems) uses the disk signature as an index to all the partitions on any disk ever connected to the computer under that OS; these signatures are kept in Windows Registry keys, primarily for storing the persistent mappings between disk partitions and drive letters. It may also be used in BOOT.INI files (though most do not), to describe the location of bootable Windows NT (or later) partitions.[30] One key (among many) where NT disk signatures appear in a Windows 2000/XP registry is:

HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices\

If a disk's signature stored in the MBR was A8hex E1hex B9hex D2hex (in that order) and its first partition corresponded with logical drive C: under Windows, then the REG_BINARY data under the key value \DosDevices\C: would be:

A8 E1 B9 D2 00 7E 00 00 00 00 00 00hex

The first four bytes are said disk signature. (Note: In other keys, these bytes may appear in reverse order from that found in the MBR sector.) These are followed by eight more bytes, forming a 64-bit integer, in little endian notation, which are used to locate the byte offset of this partition. In this case, 00hex 7Ehex corresponds to the hexadecimal value 7E00hex (32,256). If we assume the drive in question reports a sector size of 512 bytes, then dividing this byte offset by 512 results in 63, which is the physical sector number (or LBA) containing the first sector of the partition (unlike the sector count used in the sectors value of CHS tuples, which counts from one, the absolute or LBA sector value starts counting from zero).

If this disk had another partition with the values 00 F8 93 71 02hex following the disk signature (under, e.g., the key value \DosDevices\D:), it would begin at byte offset 00027193F800hex (10,495,457,280), which is also the first byte of physical sector 20,498,940.

Starting with Windows Vista, the disk signature is also stored in the Boot Configuration Data (BCD) store and the boot process depends on it.[31] If the disk signature changes, cannot be found or has a conflict, Windows is unable to boot.[32] Unless Windows is forced to use the overlapping part of the LBA address of the Advanced Active Partition entry as pseudo-disk signature, Windows' usage is conflictive with the Advanced Active Partition feature of PTS-DOS 7 and DR-DOS 7.07, in particular if their boot code is located outside the first 8 GB of the disk, so that LBA addressing must be used.

Programming considerations

The MBR originated in the PC XT.[33] IBM PC-compatible computers are little-endian, which means the processor stores numeric values spanning two or more bytes in memory least significant byte first. The format of the MBR on media reflects this convention. Thus, the MBR signature will appear in a disk editor as the sequence 55hex AAhex.[lower-alpha 1]

The bootstrap sequence in the BIOS will load the first valid MBR that it finds into the computer's physical memory at address 0000hex:7C00hex.[33] The last instruction executed in the BIOS code will be a "jump" to that address, to direct execution to the beginning of the MBR copy. The primary validation for most BIOSes is the signature at offset +1FEhex, although a BIOS implementer may choose to include other checks, such as verifying that the MBR contains a valid partition table without entries referring to sectors beyond the reported capacity of the disk.

While the MBR boot sector code expects to be loaded at physical address 0000hex:7C00hex,[lower-alpha 7] all the memory from physical address 0000hex:0501hex (address 0000hex:0500hex is the last one used by a Phoenix BIOS)[15] to 0000hex:7FFFhex,[33] later relaxed to 0000hex:FFFFhex[34] (and sometimes[lower-alpha 8] up to 9000hex:FFFFhex)the end of the first 640 KBis available in real mode.[lower-alpha 9] The INT 12h BIOS interrupt call may help in determining how much memory can be allocated safely (by default, it simply reads the base memory size in KB from segment:offset location 0040hex:0013hex, but it may be hooked by other resident pre-boot software like BIOS overlays, RPL code or viruses to reduce the reported amount of available memory in order to keep other boot stage software like boot sectors from overwriting them).

The last 66 bytes of the 512-byte MBR are reserved for the partition table and other information, so the MBR boot sector program must be small enough to fit within 446 bytes of memory or less. The MBR code may communicate with the user, examine the partition table. Eventually, the MBR will need to perform its main task, and load the program that will perform the next stage of the boot process, usually by making use of INT 13h BIOS calls. While it may be convenient to think of the MBR and the program that it loads as separate and discrete, a clear distinction between the MBR and the loaded OS is not technically required—the MBR, or parts of it,[lower-alpha 10] could stay resident in RAM and be used as part of the loaded program, after the MBR transfers control to that program. The same is true of a volume boot record, whether that volume is a floppy disk or a fixed disk partition. However, in practice, it is typical for the program loaded by a boot record program to discard and overwrite the RAM image of the latter, so that its only function is as the first link of the boot loader chain.

From a technical standpoint, it is important to note that the distinction between an MBR and a volume boot record exists only at the user software level, above the BIOS firmware. (Here, the term "user software" refers to both operating system software and application software.) To the BIOS, removable (e.g. floppy) and fixed disks are essentially the same. For either, the BIOS reads the first physical sector of the media into RAM at absolute address 7C00hex, checks the signature in the last two bytes of the loaded sector, and then, if the correct signature is found, transfers control to the first byte of the sector with a jump (JMP) instruction. The only real distinction that the BIOS makes is that (by default, or if the boot order is not configurable) it attempts to boot from the first removable disk before trying to boot from the first fixed disk. From the perspective of the BIOS, the action of the MBR loading a volume boot record into RAM is exactly the same as the action of a floppy disk volume boot record loading the object code of an operating system loader into RAM. In either case, the program that BIOS loaded is going about the work of chain loading an operating system. The distinction between an MBR and a volume boot record is an OS software-level abstraction, designed to help people to understand the operational organization and structure of the system. That distinction doesn't exist for the BIOS. Whatever the BIOS directly loads, be it an MBR or a volume boot record, is given total control of the system, and the BIOS from that point is solely at the service of that program. The loaded program owns the machine (until the next reboot, at least). With its total control, this program is not required to ever call the BIOS again and may even shut BIOS down completely, by removing the BIOS ISR vectors from the processor interrupt vector table, and then overwrite the BIOS data area. This is mentioned to emphasize that the boot program that the BIOS loads and runs from the first sector of a disk can truly do anything, so long as the program does not call for BIOS services or allow BIOS ISRs to be invoked after it has disrupted the BIOS state necessary for those services and ISRs to function properly.

As stated above, the conventional MBR bootstrap code loads and runs (boot loader- or operating system-dependent) volume boot record code that is located at the beginning of the "active" partition. A conventional volume boot record will fit within a 512-byte sector, but it is safe for MBR code to load additional sectors to accommodate boot loaders longer than one sector, provided they do not make any assumptions on what the sector size is. In fact, at least 1 KB of RAM is available at address 7C00hex in every IBM XT- and AT-class machine, so a 1 KB sector could be used with no problem. Like the MBR, a volume boot record normally expects to be loaded at address 0000hex:7C00hex. This derives from the fact that the volume boot record design originated on unpartitioned media, where a volume boot record would be directly loaded by the BIOS boot procedure; as mentioned above, the BIOS treats MBRs and volume boot records (VBRs)[lower-alpha 11] exactly alike. Since this is the same location where the MBR is loaded, one of the first tasks of an MBR is to relocate itself somewhere else in memory. The relocation address is determined by the MBR, but it is most often 0000hex:0600hex (for MS-DOS/PC DOS, OS/2 and Windows MBR code) or 0060hex:0000hex (most DR-DOS MBRs). (Even though both of these segmented addresses resolve to the same physical memory address in real mode, for Apple Darwin to boot, the MBR must be relocated to 0000hex:0600hex instead of 0060hex:0000hex, since the code depends on the DS:SI pointer to the partition entry provided by the MBR, but it erroneously refers to it via 0000hex:SI only.[35]) While the MBR code relocates itself it is still important not to relocate to other addresses in memory because many VBRs will assume a certain standard memory layout when loading their boot file.

The Status field in a partition table record is used to indicate an active partition. Standard-conformant MBRs will allow only one partition marked active and use this as part of a sanity-check to determine the existence of a valid partition table. They will display an error message, if more than one partition has been marked active. Some non-standard MBRs will not treat this as an error condition and just use the first marked partition in the row.

Traditionally, values other than 00hex (not active) and 80hex (active) were invalid and the bootstrap program would display an error message upon encountering them. However, the Plug and Play BIOS Specification and BIOS Boot Specification (BBS) allowed other devices to become bootable as well since 1994.[34][36] Consequently, with the introduction of MS-DOS 7.10 (Windows 95B) and higher, the MBR started to treat a set bit 7 as active flag and showed an error message for values 01hex..7Fhex only. It continued to treat the entry as physical drive unit to be used when loading the corresponding partition's VBR later on, thereby now also accepting other boot drives than 80hex as valid, however, MS-DOS did not make use of this extension by itself. Storing the actual physical drive number in the partition table does not normally cause backward compatibility problems, since the value will differ from 80hex only on drives other than the first one (which have not been bootable before, anyway). However, even with systems enabled to boot off other drives, the extension may still not work universally, for example, after the BIOS assignment of physical drives has changed, for example when drives are removed, added or swapped. Therefore, per the BIOS Boot Specification (BBS),[34] it is best practice for a modern MBR accepting bit 7 as active flag to pass on the DL value originally provided by the BIOS instead of using the entry in the partition table.

BIOS to MBR interface

The MBR is loaded at memory location 0000hex:7C00hex and with the following CPU registers set up when the prior bootstrap loader (normally the IPL in the BIOS) passes execution to it by jumping to 0000hex:7C00hex in the CPU's real mode.

Some Compaq BIOSes erroneously use 07C0hex:0000hex instead. While this resolves to the same location in real mode memory, it is non-standard and should be avoided, since MBR code assuming certain register values or not written to be relocatable may not work otherwise.
DL is supported by IBM BIOSes as well as most other BIOSes. The Toshiba T1000 BIOS is known to not support this properly, and some old Wyse 286 BIOSes use DL values greater or equal to 2 for fixed disks (thereby reflecting the logical drive numbers under DOS rather than the physical drive numbers of the BIOS). USB sticks configured as removable drives typically get an assignment of DL = 80hex, 81hex, etc. However, some rare BIOSes erroneously presented them under DL = 01hex, just as if they were configured as superfloppies.
A standard conformant BIOS assigns numbers greater or equal to 80hex exclusively to fixed disk / removable drives, and traditionally only values 80hex and 00hex were passed on as physical drive units during boot. By convention, only fixed disks / removable drives are partitioned, therefore, the only DL value a MBR could see traditionally was 80hex. Many MBRs were coded to ignore the DL value and work with a hard-wired value (normally 80hex), anyway.
The Plug and Play BIOS Specification and BIOS Boot Specification (BBS) allow other devices to become bootable as well since 1994.[34][36] The later recommends that MBR and VBR code should use DL rather than internally hardwired defaults.[34] This will also ensure compatibility with various non-standard assignments (see examples above), as far as the MBR code is concerned.
Bootable CD-ROMs following the El Torito specification may contain disk images mounted by the BIOS to occur as floppy or superfloppies on this interface. DL values of 00hex and 01hex may also be used by Protected Area Run Time Interface Extension Services (PARTIES) and Trusted Computing Group (TCG) BIOS extensions in Trusted mode to access otherwise invisible PARTIES partitions, disk image files located via the Boot Engineering Extension Record (BEER) in the last physical sector of a hard disk's Host Protected Area (HPA). While designed to emulate floppies or superfloppies, MBR code accepting these non-standard DL values allows to use images of partitioned media at least in the boot stage of operating systems.

Systems with Plug-and-Play BIOS or BBS support will provide a pointer to PnP data in addition to DL:[34][36]

This information allows the boot loader in the MBR (or VBR, if passed on) to actively interact with the BIOS or a resident PnP / BBS BIOS overlay in memory in order to configure the boot order, etc., however, this information is ignored by most standard MBRs and VBRs. Ideally, ES:DI is passed on to the VBR for later use by the loaded operating system, but PnP-enabled operating systems typically also have fallback methods to retrieve the PnP BIOS entry point later on so that most operating systems do not rely on this.

MBR to VBR interface

By convention, a standard conformant MBR passes execution to a successfully loaded VBR, loaded at memory location 0000hex:7C00hex, by jumping to 0000hex:7C00hex in the CPU's real mode with the following registers maintained or specifically set up:

MS-DOS 2.0-7.0 / PC DOS 2.0-6.3 MBRs do not pass on the DL value received on entry, but they rather use the boot status entry in the partition table entry of the selected primary partition as physical boot drive unit. Since this is, by convention, 80hex in most MBR partition tables, it won't change things unless the BIOS attempted to boot off a physical device other than the first fixed disk / removable drive in the row. This is also the reason why these operating systems cannot boot off a second hard disk, etc. Some FDISK tools allow to mark partitions on secondary disks as "active" as well. In this situation, knowing that these operating systems cannot boot off other drives anyway, some of them continue to use the traditionally fixed value of 80hex as active marker, whereas others use values corresponding with the currently assigned physical drive unit (81hex, 82hex), thereby allowing to boot off other drives at least in theory. In fact, this will work with many MBR codes, which take a set bit 7 of the boot status entry as active flag rather than insisting on 80hex, however, MS-DOS/PC DOS MBRs are hard-wired to accept the fixed value of 80hex only. Storing the actual physical drive number in the partition table will also cause problems, when the BIOS assignment of physical drives changes, for example when drives are removed, added or swapped. Therefore, for a normal MBR accepting bit 7 as active flag and otherwise just using and passing on to the VBR the DL value originally provided by the BIOS allows for maximum flexibility. MS-DOS 7.1 - 8.0 MBRs have changed to treat bit 7 as active flag and any values 01hex..7Fhex as invalid, but they still take the physical drive unit from the partition table rather than using the DL value provided by the BIOS. DR-DOS 7.07 extended MBRs treat bit 7 as active flag and use and pass on the BIOS DL value by default (including non-standard values 00hex..01hex used by some BIOSes also for partitioned media), but they also provide a special NEWLDR configuration block in order to support alternative boot methods in conjunction with LOADER and REAL/32 as well as to change the detail behaviour of the MBR, so that it can also work with drive values retrieved from the partition table (important in conjunction with LOADER and AAPs, see NEWLDR offset +00Chex), translate Wyse non-standard drive units 02hex..7Fhex to 80hex..FDhex, and optionally fix up the drive value (stored at offset +19hex in the Extended BIOS Parameter Block (EBPB) or at sector offset +1FDhex ) in loaded VBRs before passing execution to them (see NEWLDR offset +014hex)—this also allows other boot loaders to use NEWLDR as a chain-loader, configure its in-memory image on the fly and "tunnel" the loading of VBRs, EBRs, or AAPs through NEWLDR.

The MBR code passes additional information to the VBR in many implementations:

Under DR-DOS 7.07 an extended interface may be optionally provided by the extended MBR and in conjunction with LOADER:

In conjunction with GPT, an Enhanced Disk Drive Specification (EDD) 4 Hybrid MBR proposal recommends another extension to the interface:[37]

Since older operating systems (including their VBRs) do no support this extension nor are they able to address sectors beyond the 2 TiB barrier, a GPT-enabled hybrid boot loader should still emulate the 16-byte dummy MBR partition table entry if the boot partition is located within the first 2 TiB.[lower-alpha 13]

Editing/replacing MBR contents

Though it is possible to manipulate the bytes in the MBR sector directly using various disk editors, there are tools to write fixed sets of functioning code to the MBR. Since MS-DOS 5.0, the program FDISK has included the switch /MBR, which will rewrite the MBR code.[38] Under Windows 2000 and Windows XP, the Recovery Console can be used to write new MBR code to a storage device using its fixmbr command. Under Windows Vista and Windows 7, the Recovery Environment can be used to write new MBR code using the BOOTREC /FIXMBR command. Some third-party utilities may also be used for directly editing the contents of partition tables (without requiring any knowledge of hexadecimal or disk/sector editors), such as MBRWizard.[lower-alpha 14]

dd is also a commonly used POSIX command to read or write to any location on a storage device, MBR included. In Linux, ms-sys may be used to install a Windows MBR. The GRUB and LILO projects have tools for writing code to the MBR sector, namely grub-install and lilo -mbr. The GRUB Legacy interactive console can write to the MBR, using the setup and embed commands, but GRUB2 currently requires grub-install to be run from within an operating system.

Various programs are able to create a "backup" of both the primary partition table and the logical partitions in the extended partition.

Linux sfdisk (on a SystemRescueCD) is able to save a backup of the primary and extended partition table. It creates a file that can be read in a text editor, or this file can be used by sfdisk to restore the primary/extended partition table. An example command to back up the partition table is sfdisk -d /dev/hda > hda.out and to restore is sfdisk /dev/hda < hda.out. It is possible to copy the partition table from one disk to another this way, useful for setting up mirroring, but it should be noted that sfdisk executes the command without prompting/warnings using sfdisk -d /dev/sda | sfdisk /dev/sdb.[39]

See also

Notes

  1. 1 2 3 4 5 6 7 The signature at offset +1FEhex in boot sectors is 55hex AAhex, that is 55hex at offset +1FEhex and AAhex at offset +1FFhex. Since little-endian representation must be assumed in the context of IBM PC compatible machines, this can be written as 16-bit word AA55hex in programs for x86 processors (note the swapped order), whereas it would have to be written as 55AAhex in programs for other CPU architectures using a big-endian representation. Since this has been mixed up numerous times in books and even in original Microsoft reference documents, this article uses the offset-based byte-wise on-disk representation to avoid any possible misinterpretation.
  2. In order to ensure the integrity of the MBR boot loader code, it is important that the bytes at +0DAhex to +0DFhex are never changed, unless either all six bytes represent a value of 0 or the whole MBR bootstrap loader code (except for the (extended) partition table) is replaced at the same time as well. This includes resetting these values to 00 00 00 00 00 00hex unless the code stored in the MBR is known. Windows adheres to this rule.
  3. Originally, status values other than 00hex and 80hex were invalid, but modern MBRs treat the bit 7 as active flag and use this entry to store the physical boot unit.
  4. 1 2 The starting sector fields are limited to 1023+1 cylinders, 255+1 heads, and 63 sectors; ending sector fields have the same limitations.
  5. 1 2 3 4 5 The range for sector is 1 through 63; the range for cylinder is 0 through 1023; the range for head is 0 through 255 inclusive.[15]
  6. 1 2 The number of sectors is an index field; thus, the zero value is invalid, reserved and must not be used in normal partition entries. The entry is used by operating systems in certain circumstances; in such cases the CHS addresses are ignored.[17]
  7. The address 0000hex:7C00hex is the first byte of the 32nd KB of RAM. As a historical note, the loading of the boot program at this address was the obvious reason why, while the minimum RAM size of an original IBM PC (type 5150) was 16 KB, 32 KB were required for the disk option in the IBM XT.
  8. If there is an EBDA, the available memory ends below it.
  9. Very old machines may have less than 640 KB (A0000hex or 655,360 bytes) of memory. In theory, only 32 KB (up to 0000hex:7FFFhex) or 64 KB (up to 0000hex:FFFFhex) are guaranteed to exist; this would be the case on an IBM XT-class machine equipped with only the required minimum amount of memory for a disk system.
  10. such as a routine to do a primitive block move, user I/O, or parse a file system directory
  11. This applies when BIOS handles a VBR, which is when it is in the first physical sector of unpartitioned media. Otherwise, BIOS has nothing to do with the VBR. The design of VBRs is such as it is because VBRs originated solely on unpartitioned floppy disk media—the type 5150 IBM PC originally had no hard disk option—and the partitioning system using an MBR was later developed as an adaptation to put more than one volume, each beginning with its own VBR as-already-defined, onto a single fixed disk. By this design, essentially the MBR emulates the BIOS boot routine, doing the same things the BIOS would do to process that VBR and set up the initial operating environment for it if the BIOS found that VBR on an unpartitioned medium.
  12. IP is set as a result of the jump. CS may be set to 0 either by making a far jump or by loading it explicitly before making a near jump. (It is impossible for jumped-to x86 code to detect whether a near or far jump was used to reach it [unless the code that made the jump separately passes this information in some way].)
  13. This is not part of the above mentioned proposal, but a natural consequence of pre-existing conditions.
  14. For example, PowerQuest's Partition Table Editor (PTEDIT32.EXE), which runs under Windows operating systems, is still available here: Symantec's FTP site.

References

  1. Denis Howe (May 19, 2009). "master boot record". FOLDOC. Retrieved 2 May 2015.
  2. "Windows support for hard disks that are larger than 2 TB". Microsoft. 2013-06-26. Retrieved 2013-08-28.
  3. "Mystery Bytes of the Win95B/98/SE/Me MBR". Thestarman.pcministry.com. 2004-09-04. Retrieved 2014-04-17.
  4. Lucas, Michael (2003). Absolute OpenBSD: Unix for the practical paranoid. p. 73. ISBN 9781886411999. Retrieved 2011-04-09. Every operating system includes tools to manage MBR partitions. Unfortunately, every operating system handles MBR partitions in a slightly different manner.
  5. 1 2 Sedory, Daniel B. (2004). "The Mystery Bytes (or the Drive/Timestamp Bytes) of the MS-Windows 95B, 98, 98SE and Me Master Boot Record (MBR)". Master Boot Records. thestarman.pcministry.com. Retrieved 2012-08-25.
  6. Norton, Peter; Clark, Scott (2002). Peter Norton's New Inside the PC. Sams Publishing. pp. 360–361. ISBN 0-672-32289-7.
  7. Graves, Michael W. (2004). A+ Guide To PC Hardware Maintenance and Repair. Thomson Delmar. p. 276. ISBN 1-4018-5230-0.
  8. Andrews, Jean (2003). Upgrade and Repair with Jean Andrews. Thomson Course Technology. p. 646. ISBN 1-59200-112-2.
  9. Boswell, William (2003). Inside Windows Server 2003. Addison-Wesley Professional. p. 13. ISBN 0-7357-1158-5.
  10. Smith, Roderick W. (2000). The Multi-Boot Configuration Handbook. Que Publishing. pp. 260–261. ISBN 0-7897-2283-6.
  11. Brouwer, Andries Evert. "Properties of partition tables". Partition types. Matthias Paul: "PTS-DOS [uses] a special fifth partition entry in front of the other four entries in the MBR and corresponding AAP-aware MBR bootstrap code."
  12. Brouwer, Andries Evert. "Properties of partition tables". Partition types. Some OEM systems, such as AST DOS (type 14hex) and NEC DOS (type 24hex) had 8 instead of 4 partition entries in their MBR sectors. (Matthias Paul). (NB. NEC MS-DOS 3.30 and AST MS-DOS partition tables with eight entries are preceded with a signature A55Ahex at offset +17Chex.)
  13. Sedory, Daniel B. "Notes on the Differences in one OEM version of the DOS 3.30 MBR". Master Boot Records. When we added partitions to this NEC table, the first one was placed at offsets +1EEhex through +1FDhex and the next entry was added just above it. So, the entries are inserted and listed backwards from that of a normal Table. Thus, looking at such a Table with a disk editor or partition listing utility, it would show the first entry in a NEC eight-entry table as being the last one (fourth entry) in a normal Partition Table. Shows an 8-entry partition table and where its boot code differs from MS-DOS 3.30.
  14. "Partition Table". osdev.org. Retrieved 2013-11-15.
  15. 1 2 3 System BIOS for IBM PC/XT/AT Computers and Compatibles. Phoenix technical reference. Addison-Wesley. 1989. ISBN 0-201-51806-6.
  16. Brouwer, Andries Evert. "List of partition identifiers for PCs". Partition types.
  17. Wood, Sybil (2002). Microsoft Windows 2000 Server Operations Guide. Microsoft Press. p. 18. ISBN 9780735617964.
  18. "An Introduction to Hard Disk Geometry". Tech Juice. 2011-08-08. Retrieved 2013-04-19.
  19. Kozierok, Charles M. (2001-04-17). "BIOS and the Hard Disk". The PC Guide. Retrieved 2013-04-19.
  20. Smith, Robert (2011-06-26). "Working Around MBR's Limitations". GPT fdisk Tutorial. Retrieved 2013-04-20.
  21. "More than 2 TiB on a MBR disk". superuser.com. 2013-03-07. Retrieved 2013-10-22.
  22. "Transition to Advanced Format 4K Sector Hard Drives". Tech Insight. Seagate Technology. Retrieved 2013-04-19.
  23. Calvert, Kelvin (2011-03-16). "WD AV‐GP Large Capacity Hard Drives" (PDF). Western Digital. Retrieved 2013-04-20.
  24. Smith, Roderick W. (2010-04-27). "Linux on 4KB-sector disks: Practical advice". DeveloperWorks. IBM. Retrieved 2013-04-19.
  25. 1 2 "MBR (x86)". OSDev Wiki. OSDev.org. 2012-03-05. Retrieved 2013-04-20.
  26. Sedory, Daniel B. (2003-07-30). "IBM DOS 2.00 Master Boot Record". The Starman's Realm. Retrieved 2011-07-22.
  27. Singh, Amit (2009-12-25). "Booting Mac OS X". Mac OS X Internals: The Book. Retrieved 2011-07-22.
  28. de Boyne Pollard, Jonathan (2011-07-10). "FGA: The EFI boot process". Frequently Given Answers. Jonathan de Boyne Pollard. Retrieved 2011-07-22.
  29. Domsch, Matt. "Re: RFC 2.6.0 EDD enhancements". Linux Kernel Mailing List.
  30. "Windows may use Signature() syntax in the BOOT.INI file". KnowledgeBase. Microsoft.
  31. "Vista's MBR Disk Signature". Multibooters: Dual and Multibooting with Vista. January 2007. Retrieved 2013-04-19.
  32. Russinovich, Mark (2011-11-08). "Fixing Disk Signature Collisions". Mark Russinovich's Blog. Microsoft. Retrieved 2013-04-19.
  33. 1 2 3 Sakamoto, Masahiko (2010-05-13). "Why BIOS loads MBR into 0x7C00 in x86?". Glamenv-Septzen.net. Retrieved 2011-05-04.
  34. 1 2 3 4 5 6 Compaq; Phoenix Technologies; Intel (1996-01-11). "BIOS Boot Specification 1.01" (PDF). ACPICA. Retrieved 2013-04-20.
  35. 1 2 Elliott, David (2009-10-12). "Why does the "standard" MBR set SI?". tgwbd.org. Retrieved 2013-04-20.
  36. 1 2 3 Compaq; Phoenix Technologies; Intel (1994-05-05). "Plug and Play BIOS Specification 1.0A" (PDF). Intel. Retrieved 2013-04-20.
  37. Elliott, Robert (2010-01-04). "e09127r3 EDD-4 Hybrid MBR boot code annex" (PDF). T13 Technical Committee. Retrieved 2013-04-20.
  38. "FDISK /MBR rewrites the Master Boot Record". Support. Microsoft. 2011-09-23. Retrieved 2013-04-19.
  39. "sfdisk(8) – Linux man page". die.net. Retrieved 2013-04-20.

Further reading

External links

This article is issued from Wikipedia - version of the Wednesday, May 04, 2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.