Disk Partition Table

The partition table information is usually written in the first sector (512 bytes) of the device, which is therefore called master boot sector (MBS). The MS-DOS master boot sector begins with a JUMP instruction (three bytes). The disk parameters follow (offset 0x003), and then there is the DOS kernel loader (at offset 0x03E). The master boot sector is terminated by the magic number, 0xAA55, for the bios in the final two bytes (offset 0x1FE).

A hard disk is more complicated than a floppy, because it has partitions. However the BIOS boots from a hard disk as if it were a floppy. Therefore the first sector (master boot record) must have the structure of a MBS, ie, the first instruction that is executed is at offset 0x000, and there must be the magic number 0xAA55 at offset 0x1FE. The master boot record contains the information about the dist partition. More precisely each partition is described by 16 bytes,

  • 0x00: boof-flag (0 = inactive, 0x80 = active)
  • 0x01: start cyl / head / sect: starting cylinder, head, sector of the partition
  • 0x04: system code (0x80 linux, ...)
  • 0x05: end cyl / head / sect
  • 0x08: relative sector number of start sector
  • 0x0c: number of sectors in the partition
The first partition descriptor is at offset 0x1BE. The second at 0x1CE, the third at 0x1DE, and the fourth at 0x1EE.

Hard disks used to have a geometry, described by "cylinders", read/write "heads" and "sectors" (see figure). Now the disk geometry is more a logical concept than a physical one. Nevertheless it is still used. The units of disk are the sectors. Each cylinder contains "head" * "sect" sectors. The C/H/S triples are stored in three bytes in the format 10+8+6. This is ok if there are at most 1024 cylinders, whihc nowadays is mostly not the case. Therefore the triples are not used by Linux.

Exercise
Write a C program that reads the partition table from your hard disk(s), and check the result with fdisk -lu.

diskpartitiontable.c

Quick Links:
Have a Linux Issue?
Do you have a Linux Question?

Linux Home: Linux System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.