# Master Boot Record Standards



## Maelstorm (May 17, 2015)

I've been looking on the internet and I can't seem to locate the information that I need.  What I am looking for is the following:

What does the CHS entries in a MBR look like when the LBA exceeds the max CHS values?
Are all the bits set to 1 or 0?
Also, when the start of the partition is in the CHS range but ends beyond the CHS range, how does that look?

Some definitions if you don't know...
MBR: Master Boot Record
CHS: Cylinder, Head, Sector
LBA: Logical Block Address

EDIT:

I did some additional research on how FreeBSD handles this, and this is what I have found:

My system has two physical HDDs, the primary is 40GB and the secondary is 120GB.  So I used the commands `dd if=/dev/ad0 of=./ad0_mbr bs=512 count=1` and `dd if=/dev/ad1 of=./ad1_mbr bs=512 count=1` to record the MBRs of both harddisks.  Then I used bvi (Found here: https://svnweb.freebsd.org/ports/head/editors/bvi/) to view the files.  It seems that FreeBSD likes to use the last entry in the partition table.  Here's the relevant data and the break down:

```
80 00 01 00 A5 FE FF FF 00 00 00 00 50 C3 00 00

So breaking it down, we have the following:

80: Partition Status Byte: Indicates active partition.
00 01 00: Starting CHS of partition: 0/0/1.  !?
A5: Partition Type: 0xA5 = 165 which is FreeBSD partition type.
FE FF FF: Ending CHS of partition: 1023/254/63.  !?
00 00 00 00: Starting LBA of partition: LBA 0  !?
50 C3 00 00: LBA count: LBA 0x0000C350 = LBA 50,000 !?
```
There's a few things about this that bother me.  This is on FreeBSD 9.3 and was a clean install from FreeBSD 9.1 using the installation DVD and sysinstall.  I did find some comments that if the ending LBA exceeds the maximum CHS value, then it should be 1023/255/63.  Note that its 255 heads instead of 254 as shown above.  Additionally, shouldn't the partitions start at LBA 1 (0/0/2) instead of LBA 0 (0/0/1) because the MBR is in LBA 0?  The identify of the first harddisk shows the following:

```
camcontrol: sending ATA READ_NATIVE_MAX_ADDRESS48 with timeout of 1000 msecs
pass0: Raw native max data:
  0: 5000 6f00 a8b5 0404 0000 0000
error = 0x00, sector_count = 0x0000, device = 0x04, status = 0x50
pass0: <ST3402111A 3.AAJ> ATA-7 device
pass0: 100.000MB/s transfers (UDMA5, PIO 8192bytes)

protocol  ATA/ATAPI-7
device model  ST3402111A
firmware revision  3.AAJ
serial number  9PF0JSZY
cylinders  16383
heads  16
sectors/track  63
sector size  logical 512, physical 512, offset 0
LBA supported  78165360 sectors
LBA48 supported  78165360 sectors
PIO supported  PIO4
DMA supported  WDMA2 UDMA5
```
Note that the LBA is 78165360 which is equal to 0x04A8B570 which should be a LBA count of 6E B5 8B 04.  I used LBA - 2 because I think the partition numbers should be from LBA 1 to LBA 78165359.

Does anyone have any thoughts on this as it seems pretty strange to me.

EDIT Again:

I figured out how to read the MBR off my Windows machine, and here's what it shows as the windows partition (The only partition actually):


```
80 01 01 00 07 FE FF FF 3F 00 00 00 41 6E EE 22

So breaking it down, we have the following:

80: Active Partition
01 01 00: CHS Start: 0/1/1.
07: Partition Type: 0x07 is Windows NTFS
FE FF FF: Ending CHS (Matches FreeBSD)
3F 00 00 00: Starting LBA of 0x0000003F which is 63 (figures).
41 6E EE 22: LBA Count of 0x22EE6E41 which is 586,051,137.
```

Running the calculation on the number of sectors:

63 + 1 + 586051137 = 586,051,202
586,051,202 / 2 * 1024 = 300GB

300GB is the size of the C: drive, so these numbers work out.  It looks as though 254 heads is the standard to indicate that we need to use LBA instead of CHS to access anything beyond LBA 16,515,071.

Once again, any thoughts?


----------

