Terminology used
First and foremost I have attempted to not use the term partition table as it is confusing what exactly is being referred to. At least when I've used it in the past I have either been refering to the group of 4 partition records in sector 0 (for example) or I have been refering to the whole chain of partition records spread across the disk. For this reason I have decided to use the term primary partition table when refering to the group of 4 partition records in sector 0, and use secondary partition table when refering to a group of partition records that are inside a primary extended partition. See the glossary for further details.
All references to a “byte” as in a kilobyte (kb) a megabyte (Mb) are replaced by the term octet hence ko and Mo, since the term byte is ambiguous.1 It is unclear the number of bits being described, admittedly this is not an issue for x86 architectures but hey if I'm going to bother putting this down it might as well be complete.
Numbering always starts from the number 1 and not 0,2 counting from 0 makes about as much sense as specifying a kilooctet / kilobyte is 1,024 (which thank goodness a kilooctet is now officially defined as 1,000), so yes you guess correctly that I use ko to refer to 1,000 octets and Mo to refer to 1,000,000 octets.
You may have noticed when I was using the units above of kilooctet and megaoctet I am not capitalising the k in ko but I am for the m in Mo, this is due to the detail spelt out in the International System for Units (SI). However no letters are capitalised when the full form of the name is used ie. gigaoctet. And the reason the o for octet (and the same goes for the b of byte) is never capitalised is simply that octet is not someone's name. If you disagree with any of the detail here feel free to contact me and I'll see about correcting any details that are incorrect.3
| Multiple | Prefix | Symbol |
|---|---|---|
| 10 | deka | da |
| 102 | hecto | h |
| 103 | kilo | k |
| 106 | mega | M |
| 109 | giga | G |
| 1012 | tera | T |
| 1015 | peta | P |
| 1018 | exa | E |
| 1021 | zetta | Z |
| 1024 | yotta | Y |
Following details are only necessary for people unfamiliar with common computing terms and notation.
- Hexadecimal numbers are always postfixed with the the letter h.
- Octal numbers are always prefixed with the digit 0.
Structure of a partition record
| Field Name | Boot | Starts @ Head | Starts @ Sector | Starts @ Cylinder | Type | Ends @ Head | Ends @ Sector | Ends @ Cylinder | Starts @ Sector | Length in Sectors |
|---|---|---|---|---|---|---|---|---|---|---|
| Length in bits | 8 | 8 | 6 | 10 | 8 | 8 | 6 | 10 | 32 | 32 |
Note: The bits in this structure are in the order of octets in increasing address from left to right and the individual bits within each octet are from least significant to most significant (again left to right). Problem is IBM compatible hardware plays a little game which makes it seem as if the bits are most significant to least (hence right to left).
The only reason this is of any concern is that some of the fields do not span a whole number of octets. Following details are provided for handling with these situations.
- The two most significant bits (bits corresponding to the values 26 and 27) of the 3rd octet are to be used as the most significant (bits corresponding to values 28 and 29) of the field Starts @ Cylinder (which is predominately in the 4th octet).
- The shifting of bits is also necessary for the field Ends @ Cylinder ie. two most significant bits of the 7th octet are to be used as the two most significant bits of the field Ends @ Cylinder (which is predominately in the 8th octet).
More detail on bit ordering
As previously mentioned IBM compatibles are designed to make octets appear as if the bits are ordered from high to low whereas in actual fact they are ordered from low to high.
The following two tables display an octet of value cah.
It can initially appear that the order of the bits in an octet is as detailed in the following table ie. from left to right.
| Bit No. | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Bits | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 |
In actual fact they are ordered from right to left in the octet, otherwise the bits of the field Starts @ Cylinder would be separated into two groups with the 6 bits of Starts @ Sector inbetween.
| Bit No. | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Bits | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 |
Location of partition records
The location of the four partition records whether they be part of a primary or secondary partition table begins at octet 447 and ends at octet 510 (note countig from 1). The last two octets are set aside for the Master Boot Record signature which have been applied to secondary partition tables, this appears to be informal as code doesn't appear to check it.
So the four partition records each at 16 octets makes a 64 octet block, and with the signature it means the last 66 octets of a partitioning sector is used up to detail the partition.
Partitioning scheme for multiboot systems
For a partition table that is compatible between as many possible operating systems structure your partition table in the following way. Subsequently many of the details are not hard and fast rules for partitioning your disk but are instead guidelines for ensuring your partitioning will be handled perfectly fine by all your operating systems.
Note: cylinder and head counts in partition records start at 0 whereas sector counts start at 1, subsequently cylinder and head details in partition records need to be increased by 1 when comparing to geometry details. A disks geometry details can be found in BIOS or by using a partitioning tool such as fdisk.
Also common extended partitions are partitions of type 05h, 0fh and 85h and type 00h is used to identify the record is not used.
- The first primary partition if it is a data partition starts at head 1, sector 1 and ends on a cylinder boundary.
- Second, third and fourth primary partitions start at head 0, sector 1 and end on a cylinder boundary.
- Extended partitions start at head 0, sector 1 and end on a cylinder boundary.
- Secondary data partitions start at head 1, sector 1 and end on a cylinder boundary.
- Primary extended partitions contain a whole partition chain.
- Secondary extended partitions only contain 1 secondary data partition, the secondary extended partition starts at the sector where the contained secondary data partitions record exists and extends to the end of the secondary data partition.
- CHS addresses of all partition records are absolute addresses, whether the record exists inside a primary extended partition or not.
- The value in the Starts @ Sector field of partition records in the primary partition table are absolute addresses.
- The value in the Starts @ Sector field of partition records of type data inside a primary extended partition is relative to the start of its immediate parent extended partition.
- The value in the Starts @ Sector field of partition records of type extended inside a primary extended partition is relative to the start of the primary extended partition.
- All partition records must point to further down the disk than where the record itself resides.
Subsequent implications
- A partition chain can not link back on itself, hence creating a circular linked list.
- Partition records exist in the order the partitions are placed on disk.
The following table is provided to make some of the rules listed above a little more clear.
| Starts @ Head | Starts @ Sector | Ends @ Head | Ends @ Sector | |
|---|---|---|---|---|
| First primary partition if data | 1 | 1 | Last | Last |
| Second, third and fourth primary partitions | 0 | 1 | Last | Last |
| Extended partitions 4 | 0 | 1 | Last | Last |
| Secondary data partitions | 1 | 1 | Last | Last |
Fundamentals
- A partitions starting location must be before its ending location.
- Partitions can not overlap.
- Sector number, both Starts @ Sector and Ends @ Sector must never be 0.
- Cylinder numbers, that is Starts @ Cylinder and Ends @ Cylinder must never be greater than or equal to the number of Cylinders.
- Head numbers, that is Starts @ Head and Ends @ Head must never be greater than or equal to the number of Heads.
- Sector numbers, that is Starts @ Sector and Ends @ Sector must never be greater than the number of sectors per track.
- Boot field must either be 00h or 80h.
- Only one partition record in the primary partition table can have its boot field set to 80h at any one time. (More precisely, only one at boot time. But it is better to not let MS systems ever see an odd partition table)
What you are not restricted from
- You are able to have multiple primary data partitions (however IBM OS/2 warp for example will only make the first visible).
What you ought to avoid
- Going against partitioning scheme detailed here (nothing else comes to mind).
Reasoning for some of the rules
- Keeping partition records in the order partitions are stored on disk - Not all systems require partition records to be ordered as such, but Linux for example determines partitions by the partition record order (so I believe) and changing the order means references will be incorrect.
What I am unsure about
- Having multiple primary extended partitions. - Now this one I have to admit I have not looked into and do not know how different systems handle it, I should think either systems will display partitions from the second/third/fourth primary extended partitions or not at all but probably/hopefully not disrupt the multiple primary extended partitions you created.
What abiding by this scheme will mean
A combination of any of the following operating systems will be able to coexist on the one disk and you can even exchange data between the systems by using commonly recognised partitions.
- MS Windows NT/2K/XP
- MS Windows 9x/Me
- MS Windows 3.x
- MS/PC DOS
- IBM OS/2 warp 3 & 4
- Linux (come on, please find a distro that doesn't like these rules)
A further good reason to abide by these rules means recovery is greatly simplified in the event that your partitioning becomes corrupt. This also leads of into another topic of discussion, partition recovery.
Glossary
- A partition is where (in the case of a data partition) the file system is stored and within that is your data.
- A partition record is what details the boundaries of a partition (this is generally what is of interest when looking at partitioning).
- Primary partitions (either of type data or extended) are those whose partition records reside in the primary partition table (sector 0).
- Primary partition table is the group of 4 partition records in the first sector of the disk (sector 0).
- Secondary partitions (either of type data or extended) are those whose partition records reside inside a primary extended partition.
- Secondary partition table is a group of 4 partition records that reside in a sector of a primary extended partition.
- data partitions contain a file system.
- Extended partitions contain data partitions and if extended partition is a primary partition it will contain secondary extended partitions. Note: all extended partitions contain secondary partition tables that will include a data partition record and an extended partition record (unless end of partition chain).
- A partition chain consists of data partition records and extended partition records, where the extended partition records detail the location of the next secondary partition table and where that secondary partition tables data partition ends.
- Absolute addresses refer to a given sector with respect to the beginning of the disk.
- Relative addresses refer to a given sector with respect to the beginning of an extended partition, the extended parition may either be a primary or secondary partition.
- For detail on the words Cylinder, Head, Sector and Track see Design of Hard Disks.
Foot notes
1 - If anyone reads this I'm sure they'll disagree with at least this point if not all the others. But a byte is simply a collection of bits that are dealt with as a unit and a word consists of bytes, though does not have to be a complete number of bytes (eg. several bytes followed by a parity bit all within a single word). Back to the myth “a byte is 8 bits” firstly this is completely wrong as machines have been made that have no hardware for handling a byte, all they do is deal with words. It is part of the configuration of the machine that defines the way in which to handle discreet sections of a word eg. bytes and since you can define them they can be however many bits you like. Now please note I'm talking about hardware that most people in the IT industry have never seen and that includes me, I've just read and heard about it.
2 - Unfortunately I am not always able to stick to this when refering to certain things, such as addressing where sector 0 is the first sector.
3 - For anyone that still does not agree with my use of the units, take a look into the Weights and Measures laws passed. The legislation catagorically states that to use units they must be used as I have stated. And you'll note none of the hard disk manufactures for example are being sued for disks they are turning out for inaccurately stating the size of their disks. The reason is they use the legally defined units and not the child like approach to units used in computing circles. And now I'm certainly showing my bias :).
4 - If the first primary partition record is an extended partition then it can not start at Cylinder 0 Head 1 Sector 1 because data partitions are only able start in either Head 0 or Head 1 and if an extended partition start in Head 1 then its sibling data partition would have to start in Head 2 which is not supported by all systems.