Master Boot Record

From Gentoo Wiki
Jump to:navigation Jump to:search

The Master Boot Record (MBR) is the boot sector of an IBM PC compatible with BIOS firmware running UEFI firmware in BIOS compatibility mode. The Master Boot Record was first introduced to IBM PC's circa 1983. It is a 512-byte data structure containing system boostrap code and a partition table.

Virtually all partition management tools from fdisk to parted fully support an MBR-style partition scheme. Master Boot Records have a number of limitations:

  • Partitions are limited to 32-bit entries, thus the maximum partition size is 2TB.
  • The maximum number of partitions is fixed at 4.
  • Thus the maximum disk size that can be supported by MBR is 8TB with 4× 2TB partitions.

The Structure of the Master Boot Record

There are several variations of the Master Boot Record, all sharing a similar structure. Unfortunately, not all MBR schemas are compatible with all OS implementations.

An early example might look like this:

Typical Early IBM-DOS Master Boot Record
Start Stop Bytes Description
0x00007c00 0x00007dbd 446 System Bootstrap code area.
0x00007dbe 0x00007dcd 16 Partition 1.
0x00007dce 0x00007ddd 16 Partition 2.
0x00007dde 0x00007ded 16 Partition 3.
0x00007dee 0x00007ded 16 Partition 4.
0x00007dde 0x00007ddf 02 Boot signature 0x55aa.

A more modern Master Boot Record implementation has several more entries at the cost of a significantly reduced bootstrap code area. This adds support for a disk formatting time-stamp, and a 32-bit disk signature for use by the OS or UEFI if a Protective MBR is required for backwards compatibility.

Typical Modern Master Boot Record
Start Stop Bytes Description
0x00007c00 0x00007cd9 218 Bootstrap code area.
0x00007cda 0x00007cdb 02 Padding 0x0000.
0x00007cdc 0x00007cdc 01 Original first physical drive (0x800xff)
0x00007cdd 0x00007cdd 01 Seconds 0–59
0x00007cde 0x00007cde 01 Minutes 0–59
0x00007cdf 0x00007cdf 01 Hours 0–23
0x00007ce0 0x00007db7 216 Extended bootstrap code
0x00007db8 0x00007dbb 04 Optional disk signature.
0x00007dbc 0x00007dbd 02 Copy protection flag (True: 0x5a5a/False: 0x0000)
0x00007dbe 0x00007dcd 16 Partition 1.
0x00007dce 0x00007ddd 16 Partition 2.
0x00007dde 0x00007ded 16 Partition 3.
0x00007dee 0x00007ded 16 Partition 4.
0x00007dde 0x00007ddf 02 Boot signature 0x55aa.

Master Boot Record Partitions

Partition Table Layout
Start Stop Bytes Description
0x00 0x00 1 byte Partition boot flag. High bit set when bootable, 0x00 when not; anything else is an error.
0x01 0x03 3 bytes Absolute location of first sector, in Cylinder-Head-Sector format.
0x04 0x04 1 byte Partition type indicator
0x05 0x07 3 bytes Absolute location of last sector, in Cylinder-Head-Sector format.
0x08 0x0b 4 bytes Absolute location of first sector, in Logical Block Addressing format.
0x0c 0x0f 4 bytes Partition sector count.

The structure of individual partition entries is fixed at 16 bytes. This has a number of implications which ultimately limit the MBR format. The first byte indicates whether or not the partition is bootable, but only the 7th bit is significant. No other flags exist. Directions to the first sector of the partition follow, in the antiquated C-H-S format. The partition indicator is only one byte wide, so only 256 unique values are possible. Unfortunately, over the decades many file systems have reserved the same byte value to mean different file systems.

Master Boot Records Nested Within GPT Partitions

It is possible to nest a Master Boot Record — complete with partition table — within an outer GPT partition table. This is nearly always done for backwards compatibility by BIOS-based firmware that happen to directly support GPT partition tables or by BIOS loaded as a UEFI application.

In this case, the GPT table's MBR entry will contain a single partition which will be of the maximum possible partition size. The partition type at offset 0x00007dc1 will of the type 0xee. This is called a Protective Master Boot Record.

An MBR record within a GPT partition table always have the following GUID: 024DEE41-33E7-11D3-9D69-0008C781F39F.

MBR Backup and Recovery

It is possible to backup a Master Boot Record for later recovery with a simple Bash one-liner:

root #dd if=/dev/<disk> of=~/backup.mbr bs=512 count=1

Later recovery is possible with the following command:

root #dd if=backup.mbr of=/dev/<disk>

See Also

  • BIOS — the standard firmware of IBM-PC-compatible computers until it was phased out in 2020.
  • CMOS BIOS Memory — a few bytes of battery-backed SRAM used to preserve BIOS settings and Real Time Clock data when a PC is off.
  • UEFI — a firmware standard for boot ROM designed to provide a stable API for interacting with system hardware. On x86 it replaced the legacy BIOS.
  • GPT — a partitioning scheme widely adopted in contemporary computers to organize and manage data on storage devices.
  • System Initialization of Intel x86 with BIOS Firmware — the process of bringing an Intel x86 system up from a cold start.