<!doctype linuxdoc system>
<article>
<title> Minimal partition table specification
<author> Andries Brouwer, <tt/aeb@cwi.nl/
<date> 1999-09-16
<sect>
Introduction
<p>
The various versions of DOS and Windows use what I shall call here
`DOS-type partition tables' to describe the division of a hard disk
into partitions that each function as a logical disk.
Other operating systems like OS/2 and Linux (when used on
Intel or Alpha architecture) also use DOS-type partition tables.
<p>
So far, the precise specification of DOS-type partition tables
has not been made public, and one finds that the various operating
systems, disk managers, boot loaders and other programs that need
to handle DOS-type partition tables have slightly different ideas
about the details. Also different Microsoft operating systems,
like Windows 95 and Windows NT, disagree.
<p>
Thus, one needs a minimal and a maximal description of DOS-type partition tables.
A minimal one, which describes what should hold for all variants, and is used
by systems that need to interpret DOS-type partition tables.
And a maximal one, which describes how to construct partition tables
that are correctly interpreted by all systems, and is used by programs
that need to create DOS-type partition tables.
<p>
The present text gives the minimal specification of DOS-type partition tables.
[The parts between square brackets are comments.]
<p>
Copyright (C) Andries E. Brouwer 1999.
Comments and corrections are welcome.
Mail to <htmlurl url="mailto:aeb@cwi.nl" name="aeb@cwi.nl">.
<sect>
Specification
<p>
<sect1>
Sectorsize
<p>
DOS-type partition tables describe partitions in units of one sector.
Thus, in order to interpret a DOS-type partition table, one needs to
know the hardware sector size.
[Usually a sector has a length of 512 bytes,
and many programs blindly assume this sector size.]
<p>
<sect1>
Partition descriptor
<p>
A partition descriptor is a 16-byte structure with the following
fields:
<p>
<descrip>
<p><tag/0  Boot Indicator/ <p>
[This byte is used by some boot loaders to indicate which
of the primary partitions should be booted.]
<p><tag/1-3  Begin CHS/ <p>
[Cylinder/Head/Sector address of the partition start.
For the format, see below.]
<p><tag/4  Partition Type/ <p>
[This type generally indicates what operating system or file system
can be found on the partition, or what the partition is used for.
For a list, see <htmlurl name="the list of known partition types"
url="http://www.win.tue.nl/~aeb/partitions/partition_types-1.html">.]
Here we shall always give types in two hexadecimal digits.
Types 05, 0F and 85 (hex) indicate an extended partition.
[DOS only knows about 05, Windows 95 introduced 0F, Linux introduced 85.]
<p><tag/5-7  End CHS/ <p>
[Cylinder/Head/Sector address of the partition end.]
<p><tag/8-11  Partition Start/ <p>
The 4-byte little-endian value of the starting sector number
(counting from 0) of the partition.
<p><tag/12-15  Partition Size/ <p>
The 4-byte little-endian value of the size in sectors
of the partition. If this value is zero, the partition
descriptor should be ignored [and all other values in
the descriptor should be zero as well]; in this case
the partition descriptor is called unused.
<p></descrip>
The 3-byte CHS adresses are encoded as follows:
The first byte contains h, the head number, a value in the range 0-255.
The second byte contains in its last six bits s, the sector number,
a value in the range 1-63. The high order two bits of the second byte,
followed by the eight bits of the third byte form c, the cylinder number,
a value in the range 0-1023.
In C-like code:
<tscreen><verb>
h = byte1;
s = byte2 & 0x3f;
c = ((byte2 & 0xc0) << 2) + byte3;
</verb></tscreen>
For a disk with C cylinders, H heads, and S sectors per track,
the linear address corresponding to a CHS address (c,h,s) is found as
c*H*S + h*S + s - 1.
[Since CHS addresses have 24 bits only, they cannot address more
than 2^24 sectors, which is insufficient for modern disks.
Moreover, it is often unclear what values should be used for C, H, S.
Thus, these CHS addresses should be ignored.]
<sect1>
Partition table sector
<p>
A partition table sector is a on-disk sector that holds
four partition descriptors with (decimal) offset 446, 462, 478, 494,
respectively, followed by a signature in the two bytes
with offset 510 and 511. The signature has the hexadecimal value
0x55 in byte 510 and 0xAA in byte 511.
<sect1>
Partition table structure
<p>
Sector 0 of a disk, known as the Master Boot Record (MBR),
is a partition table sector, and thus contains four partition descriptors.
The partitions described in the MBR are known as primary partitions.
If a primary partition has a type indicating an extended partition,
then the first sector of this partition is again a partition table sector.
The partitions described in partition table sectors other than the MBR
with a type not indicating an extended partition are known as logical
partitions. The partitions described in partition table sectors other
than the MBR with a type indicating an extended partition are known as
inner extended partitions and start again with a partition table sector.
All partition table sectors other than the MBR contain at most
two used partition descriptors, namely at most one partition descriptor
with a type not indicating an extended partition and at most one
partition descriptor with a type indicating an extended partition.
In this way the first sector of each primary extended partition
becomes the head of a linked list of partition table sectors
which ends with an partition table sector without partition descriptor
with a type indicating an extended partition.
[Usually there is only one primary extended partition, and hence
only a single such linked list.]
<sect1>
Location of non-extended partitions
<p>
A partition with a type not indicating an extended partition
covers a single interval of disk area consisting of full sectors.
The Partition Size field of its descriptor gives the number of
sectors in the partition.
The Partition Start field of its descriptor gives the sector
offset of the start of the partition with respect to the
partition table sector containing the descriptor.
Thus, if a partition table sector at sector A contains a
partition descriptor with a type not indicating an extended partition
with Partition Size field N and Partition Start field S,
then this partition descriptor describes a partition
containing sectors A+S up to and including A+S+N-1.
<sect1>
Location of extended partitions
<p>
[A partition with a type indicating an extended partition
is only the carrier of partition table information
but is not used as a data partition. Its size is irrelevant
(as long as it is nonzero), only the address of the first
sector matters.]
The Partition Start field of a primary extended partition
gives the sector number (counting from 0) of its first sector.
The Partition Start field of an inner extended partition
gives the sector offset of the first sector of the partition
with respect to the first sector of the primary extended partition
that is the head of the linked list containing its descriptor.
Thus, if a partition table sector at sector A is a member of the
linked list of partition table sectors starting with the first
sector of a primary extended partition at sector E, and it contains
a partition descriptor with a type indicating an extended partition
with Partition Size field N and Partition Start field S, then
this partition descriptor describes an inner extended partition
with first sector E+S.
<sect1>
Validity check
<p>
All partition table sectors must have the 55, AA signature.
No partition ends past the end of the disk.
No two non-extended partitions overlap.
No two partition table sectors are at the same sector
(and in particular, there is no loop in the linked lists).
No partition table sector is inside a non-extended partition.
<sect>
Elements of a maximal specification
<p>
Software or firmware that implements the above minimal
specification will be able to handle all DOS-type partition tables
written by a single version of the fdisk-type software
of the common operating systems.
(Using fdisk-type software from several operating systems
on the same disk may create a terrible mess.)
<p>
Conversely, partition tables that satisfy the above requirements
will probably work under DOS and Linux. (For DOS with the
proviso that CHS addresses must agree with linear addresses,
and in particular that all partitions stay below the 1024 cylinder
limit. Also, that 05 is the only type indicating an extended
partition.)
Other operating systems, boot loaders and utilities however
make more assumptions about the structure of a DOS-type partition table.
<p>
Some examples follow.
<sect1>
Unused partition table entries
<p>
A partition descriptor is unused if either the Partition Type
or the Partition Size is zero. In this case all its entries
must be zero.
<sect1>
Size of the outer extended partition
<p>
Many systems assume that there is at most one primary partition
with a type indicating an extended partition. Moreover, that
its descriptor should describe a disk segment that contains
all logical partitions and is disjoint from all other primary partitions.
<sect1>
Order of the partition descriptors
<p>
OS/2 Boot Manager assumes that of the two partition descriptors
in an extended partition table sector, the first descriptor should
describe the logical and the second should describe the next
partition table sector in the list.
However, deleting a logical partition under DRDOS leads to the
situation of an extended partition table sector with only one nonzero
descriptor, the first, pointing at the next partition table sector
in the list.
<sect1>
Order of inner extended partitions
<p>
Some utilities assume that logical partitions occur in disk order.
Some utilities assume that the first sector of an inner extended
partition must be past the partition table sector containing its
descriptor.
<sect1>
Spare room
<p>
Some viruses and disk managers assume that some sectors after
the MBR are unused so that they can put interesting code there.
<sect1>
Cylinder boundary
<p>
Some utilities assume that partitions will be aligned on cylinder
boundaries. That a logical partition will start on the first
cylinder after the partition table sector containing its descriptor.
<sect1>
DOS partitions in an extended partition
<p>
Some utilities (e.g. scandisk) are unhappy if an extended partition
of type 05 does not contain at least one DOS partition
(of type 01 or 04 or 06).

</article>