Monday, April 13, 2009

The elusive MBR

Welcome back to Disk Tech! I get many, many questions about the Master Boot Record (MBR), so I thought I would spend a few minutes detailing the history, purpose, and layout of this elusive section of a hard disk. This isn't the most exciting topic, so try to bear through the technical details while looking for the parts you may find interesting.

In a nutshell, the MBR is nothing more than the data stored in the first sector (512 bytes) of your hard disk. While small, these 512 bytes contain enough information to define the size and location of the partitions, store the disk signature, and hand over the boot process to the operating system. This sure seems like a lot of information for such a small space, let's break it down.

It is difficult to identify one section of the MBR as more important than others, but my personal favorite is the partition table. As you may know, a disk partition is simply a logical division of the disk into smaller chunks, frequently used to separate operating systems and/or data. The partition table simply identifies the location and size of each partition, as well as additional information such as the type of filesystem and whether the partition is bootable. While a single partition may provide access to the entire disk, and is sufficient for normal operation, many folks prefer to create multiple, smaller partitions in order to test various operating systems such as Linux or new versions of Microsoft Windows. This methodology enables each partition to operate independently of each other, preventing corruption in one partition from extending to others. The MBR standard allows for a maximum of four primary partitions.

Each MBR requires the last two bytes of the sector to contain AA55, which officially determines a valid MBR. While seemingly insignificant, the MBR will be considered corrupt, or even nonexistent without this indicator. You will frequently find these two bytes referred to as the Magic Number.

The disk signature is simply a unique identifier for the disk, and was added to the MBR a few years ago by Microsoft. It was originally introduced so Windows could remember information about the disk between reboots, but is also frequently used by other operating systems as well. Each time a new partition is recognized by Windows, it records the partition location and disk signature in the registry, along with the assigned drive letter. The next time Windows is booted, it makes certain that both the disk signature and partition details match, enabling the correct drive letter to be reassigned. The disk signature is located at byte 440 in the MBR.

Last but not least we are left with the first 446 bytes of the MBR, commonly referred to as the boot loader section. The boot loader is actually a small computer program, and consists of instructions that tell the computer what to do as it starts. Once the boot process turns control over to the boot loader, the partition table is scanned in order to identify the active (bootable) partition, and control is turned over to the correct partition boot record in order to start the operating system.

Although small, the MBR may be the most important sector on the entire disk. If the MBR becomes damaged or destroyed all partition information will be lost, meaning... all files/folder/data on the disk will be inaccessible (gone!) In order to prevent data loss, please, please, please make sure you take a few minutes to backup the MBR. There are several utilities available to backup/restore/repair the MBR, but I find MBRWizard the easiest to use. Check out http://mbrwizard.com.

Like I mentioned at the beginning, this isn't the most exciting topic, but it does provide a good overview of the purpose and structure of the MBR. Hopefully you have learned something new, and feel impelled to backup your MBR right now, before anything terrible happens to it!