IBM PC-AT‎ > ‎Windows‎ > ‎Boot Process (detailed)‎ > ‎

Phase 3 - MBR from Hard Disk

At this point, BIOS has loaded the first 512 bytes (at least) from the start of the (emulated) hard drive (called the Master Boot Record, or MBR) into segment 0x7c0 (unless emulation specified a specific address).  The BIOS should verify the bytes at offset 510 are the magic value 0x55, 0xAA and halt with an error if not (or perhaps return to Phase 1 to try other devices).  Next the BIOS does a far call to offset zero of the memory segment.  Generally, all (16-bit) segment registers are set to the same value (usually 0x7c0), the DX register contains the device number (128 typical), and all other registers are undefined.
At this point, anything can happen!  It depends on what code is stored in the Master Boot Record (the first sector of the [emulated] drive).  This code is generally written by a rare (in terms of use) utility like FDISK.  Similar code is written to the start of a partition or floppy whenever the disk is formatted.  However the typical format program does not usually write the MBR.  If you suspect the MBR is corrupt, the typical format program will not fix the problem.  FIXMBR might help, but don't bet on it.
If the drive was purchased as a second drive for a computer, the MBR is usually written when the drive is installed FDISK is run.  For a brand new system, the MBR is usually written by the setup program for whatever operating system you install.  If you install a second operating system (so called dual-boot) or if you replace your operating system with another one, the original code in the MBR is often left intact and only the partition table (at the end of the sector) is updated.  Because the code in the MBR is fairly generic, this normal doesn't matter unless it was written by a real old operating system like DOS or Windows NT 3/4.  In such cases, the code may only understand CHS addressing (Cylinder, Head, Sector) which means only the first 8 GiByte or so of the hard disk may be accessed by the boot program.  Ironicaly, the MBR data gets updated more often than any other boot sector (like Phase 4), although the MBR code is almost never changed.
Anyway, this code just examines the partition table, stored mainly in 4 entries of 16 bytes near the end of the sector (offset 416 [0x1be]).  In each entry it checks the first byte to see if it is bootable (value = 128).  Each entry corresponds to a partition.  If none are marked bootable, the MBR code usually halts with an error (like NO OPERATING SYSTEM).  If more than one is marked bootable, the behavior is undefined.  Usually each partition has one file system; these are called primary partitions.  The exception is a type called the extended partition; this contains one or more "secondary" partitions but information about them is not stored in the MBR.  Usually the code in the MBR can only boot from a primary partition, but there is nothing from stopping you or another programmer from writing code that will boot from a "secondary" partition.  As far as I know, Windows will not let you mark a secondary (non-primary) partition as bootable.
Once the bootable partition is found (the so-called active partition), the MBR code must determine the first sector of the file system in that partition.  This is stored as a Logical Block Address (LBA) sector number, or Cylnder/Head/Sector (CHS) number, or both.  If the LBA number is zero (or the MBR code is so old it doesn't know about LBA), then the CHS value is used.  If both CHS and LBA are present, CHS is generally used unless it equals "max value" which is something like Cylinder 1023 / Head 254 / Sector 63 ... I hate CHS.  Otherwise LBA is used.  LBA must be used if the starting sector is beyond (approximately) the 8 GiByte boundry.  I said approximate because CHS numbers don't make for nice binary values ... I hate CHS.
Bytes 1 to 3 of the partition entry specify the starting CHS value.  Byte 4 specifies the partition type (this is for the operating system, the MBR code does not care).  Bytes 5 to 6 specify the ending sector of the partition as a CHS value.  This may be invalid (equal "max value") if the partition begins or extends beyond the 8 GiByte boundry.  Bytes 7 to 11 specify the starting sector as an LBA value (simple 4-byte DWORD).  Bytes 12 to 15 (also a DWORD) specify the number of sectors in the partition (which should be greater or equal to the number of sectors used by the file system inside it).  The MBR code does not need the ending CHS value nor the number of sectors; this information is for disk partitioning software like DiskPart (newer Windows) or FDISK (older Windows / DOS). 
Once it has the starting sector, the MBR code loads that sector into memory. If an error occurs, a message like MISSING OPERATING SYSTEM, INSERT DISK may appear.  Because the MBR code and partition table must all fit in a 512 byte sector, it can't be very sophisticated.  If all went well, proceed to Phase 4.

© H2Obsession, 2014