Properties of partition tables.
Why partitions?The partition table of a disk cuts it into `logical disks'. There are several reasons for wanting to do this. DOS does not support filesystems larger than 2 GB, so partitioning is required to break this `2 GB barrier'. Different partitions may carry different operating systems or different filesystems (FAT, HPFS, NTFS, ext2, ...) to be used by one operating system. Sometimes small partitions are used for special purposes (OS/2 Boot Manager uses a small partition for itself, various laptops have a `hibernation' partition where the state of the system is stored when it goes asleep). Some `reliable' systems have backup partitions. For backup purposes, say to tape, it is often convenient to have partitions of a size such that the entire partition can be written to a single tape. It is a good idea to keep your own things (say under /home) and privately installed packages (say under /usr/local) separate from the software installed from a distribution. In case these are on a different partition, it is easier to do a complete reinstall (or switch to a different distribution) without losing your own stuff. For well-designed systems it is often possible to have all basic system software on a read-only partition, thus diminishing the probability of corruption and saving backup time. There is also a security aspect; for example on a Unix system one might mount all filesystems other than the root filesystem `nosuid,nodev', and have /tmp, /home, /var not on the root filesystem, to minimize the possibility that some suid program is tricked into overwriting a vital system file via a hard link to it. Finally there is the old BIOS problem that can make it impossible to boot a system that lives past cylinder 1024. This may mean that one has to have a partition that ends before the 1024 cylinder limit where the stuff needed at boot time is stored. Some reasons why you want to avoid Disk Managers are given on The Invircible Anti-virus Manual, Appendix C. What does a partition table look like?One may have an arbitrary number of partitions on a disk. However, the Master Boot Record (MBR, sector 0 of the disk) only holds descriptors for 4 partitions, called the primary partitions. Usually the BIOS can boot only from a primary partition. (Of course it can boot a boot loader that itself is able to access nonprimary partitions or other disks.) The descriptors for the remaining partitions, called logical partitions, are scattered along the disk in a linked list of partition table sectors, starting with the MBR. In a partition table sector the partition descriptors start at offset 0x1be = 446, and the last two bytes have the 0xaa55 signature. In the MBR the part before offset 446 is used for the bootstrap code. Just before the partition table some operating systems save some interesting stuff. For example, DRDOS stores a password starting at offset 0x1b6. Each partition table sector contains 4 partition descriptors. A partition descriptor may be of type 5 (DOS extended partition), f (W95 extended partition) or 85 (Linux extended partition), in which case it points to another partition table sector. In this way, we obtain a quaternary tree of partitions. Linux accepts 85 as a synonym for 5 - this is useful if one wants to have extended partitions past the 1024 cylinder limit (to prevent DOS fdisk from crashing or hanging). Windows 95 uses f for LBA mapped extended partitions. Thus, an extended partition is not a partition containing data, but is a box containing other partitions. Nevertheless, the partition table sector that starts an extended partition has enough room left to contain a boot loader like LILO, so that it is possible to boot an extended partition. Most operating systems severely restrict the accepted trees. Usually branching is not allowed, and one gets a linear chain of partition table sectors. Linux will accept several extended primary partitions. Partition descriptorsA partition table entry is 16 bytes long and contains 6 items (not listed in order). 1. A byte that is 0x80 or 0 denoting `bootable' or not. The standard DOS MBR will not boot a partition unless it is the unique bootable primary partition. For nonprimary partitions this byte is unused. 2. A byte that gives the type. 3. A 4-byte starting sector number. 4. A 4-byte length (in sectors). 5. A 3-byte starting sector given in C/H/S (cylinder/head/sector) format. 6. A 3-byte final sector given in C/H/S format. Linux only uses items 2-4, and hence is not interested in the `geometry' of the disk, and can use disks with up to 2^33 sectors (4 TB). DOS uses 5-6 instead of 3-4, and this leads to the well-known problems with geometry, with the 1024 cylinder limit, the 500 MB limit, the 8 GB limit. For some details, see the large disk HOWTO. For an extended partition, only the first sector is
important - it contains the descriptors for its logical partitions. There
are various conventions about how the descriptor of an extended partition
(different from the outer one) should look like. There is the paradigm of
`nested boxes', where each extended partition covers a disk area
containing all the logical partitions inside. There is also the paradigm
of `chained boxes', where each extended partition (except possibly the
outer one) just contains the next logical partition. I don't know which
systems follow which paradigms. (David A. Burton
Partition hidingThe OS/2 Boot Manager does not want you to have more than one primary DOS partition (MS-DOS itself does not mind), and will change the type from 1,4,6,7 to 11,14,16,17. Also other programs or systems use this `partition hiding'. For example, System Commander will OR the type with 0x10, changing the Linux 83 into the Amoeba 93. What does FDISK /MBR do?People often recommend the undocumented DOS command FDISK /MBR to solve problems with the MBR. This command however does not rewrite the entire MBR - it just rewrites the boot code, but leaves the partition information alone. Thus, it won't help when the partition table has problems. Moreover, it can be dangerous to restore the boot code to its original state: if the cause of the problems was a boot sector virus, then vital information may have been stored elsewhere by the virus, and killing the virus may mean killing access to this information. (For example, the stoned.empire.monkey virus encrypts the original MBR to sector 0/0/3.) However, people who want to uninstall LILO, and do not know that LILO has a -u option, can use FDISK /MBR for this purpose. In a Linux environment, one can wipe all of the MBR with a command like "dd if=/dev/zero of=/dev/hda count=1 bs=512". If only the boot code must be removed, but not the partition table, then "dd if=/dev/zero of=/dev/hda count=1 bs=446" will do. Be very careful with such commands. Usually one regrets them later. NamingDOS uses drive letters A: and B: for floppy disk drives, and assigns drive letters C: ... Z: in the order: first all primary DOS partitions on the first disk, then all primary DOS partitions on the second disk, ..., then all logical DOS partitions on first disk, etc. DOS will stop investigating logical partitions in a given extended partition as soon as a non-DOS partition is encountered. (DOS recognizes partition types 1,4,6 and 5 for extended.) Systems like Windows 95, Windows 98 and OS/2 follow a similar convention, but recognize different partition types. Thus, a drive can have a different drive letter for each of these operating systems. LimitsThe partition table describes the location of partitions both in 1-dimensional (`LBA') and in 3-dimensional (CHS) form. The former is easy enough, but for the latter one needs to know the disk geometry. Note that these days this geometry is entirely fake, and different systems use different faked geometries for the same disk, giving lots of problems. (For example, a modern disk may have 2 or 4 heads, but will probably report 15 or 16 heads to the BIOS, which in turn may report 255 heads to DOS or Windows.)
For another discussion of this topic, see Breaking the Barriers, and, with more details, IDE Hard Drive Capacity Barriers. Hard drives over 8.4 GB are supposed to report their geometry as 16383/16/63. This in effect means that the `geometry' is obsolete, and the total disk size can no longer be computed from the geometry. Details for various operating systemsEarly MSDOS filled the partition table starting at the end. In particular, in the case of only one partition, the descriptor was stored in the fourth primary slot. These days DOS FDISK starts at the beginning, but other systems, like Unixware, still start at the end. Also Iomega writes the single partition of a ZIP disk in the last entry (so that it has to be mounted as /dev/sda4 or /dev/hdc4 or so), but some people say that that is because on a macintosh one starts with configuration partitions and it is the fourth partition that holds the user data. (However, that does not sound like the right explanation.) MSDOS fdisk creates the four entries in the partition table sector that starts an extended partition as 1. a data partition (or empty), 2. the next extended partition, 3. and 4. empty. (But old versions of MS-DOS start at the end, and first fill entry 4.) DRDOS fdisk will put the link to the next extended partition in the first place if there is no data partition (because it has been deleted). Many systems are willing to accept more than two nonempty parts in an extended partition, but will not create such themselves. It is rumoured that the outer extended partition should be the 4th in the MBR, but I don't know any systems that have this restriction. (However, the OS/2 Warp fdisk is very instable, and hangs or crashes with general protection fault as soon as the partition table is somewhat unusual, cf. Cannot set an installable partition with FDISK.) MSDOS fdisk shows 4 primary partitions, and of the logical partitions only those that have a DOS type (1, 4 or 6). It will list the type of a logical partition as `Unknown' if the partition is not formatted. It is rumoured that DRDOS ignores the high-order bit of the ID (and that is the reason for the additional Linux IDs 41, 42, 43), but I don't know whether that is true (and for which versions of DRDOS). It is also rumoured that DRDOS will write 1 sector past the end of a partition - I have never seen this either. Confirmation? It is however true, that DRDOS fdisk only looks at the last 4 bits when printing a type, so that types 11, 21, etc are printed as DOS 2.0, but such types are not acceptable for DRDOS itself. The Windows NT Disk Administrator will corrupt your disk when it writes a signature on a disk with two or more logical partitions. See Disk Administrator Corrupts Partitions. The use of Win95/Win98 FDISK in a mixed system is dangerous. It will delete a non-FAT logical partition when you had actually told it to delete a FAT partition somewhere farther down the chain of logical partitions. See Cannot View NTFS Logical Drive After Using FDISK. The system partition in Windows NT 4 must be contained in the first 7.8 GB of the disk (or less, in case the BIOS geometry does not have 255 heads and 63 sectors/track; the actual restriction is that all of it must be accessible using BIOS Int 13). It must not be larger than 4 GB because Windows NT 4 first installs into a FAT16 partition and then converts it into NTFS during the second phase of the installation. It must start before the 4 GB mark (bug fixed in Service Pack 5). See Windows NT 4.0 Supports Maximum of 7.8-GB System Partition and Windows NT Partitioning Rules During Setup and Boot Partition Created During Setup Limited to 4 Gigabytes and Windows NT Does Not Boot to a Partition That Starts More Than 4 GB into Disk. Windows NT and Windows 2000 use for SCSI disks whatever the BIOS says (usually C/H/S=C/255/63) for the boot drive, and C/64/32 for all other SCSI drives. See How Windows NT Handles Drive Translation. Windows 2000 seems to require that the partition order agrees with the disk order. The OS/2 fdisk writes some strange length in the descriptor of the last extended partition. This is probably a bug. OS/2 fdisk fails to update the length of the (outer) extended partition when a primary partition is created in the free space (space not used by a logical partition) at the end of this extended partition. This can lead to overlapping partitions. OS/2 FDISK does not know about type f, but accepts DOS Extended Partitions extending beyond cylinder 1023. When some other partition handler, like Partition Magic 4.0, changes the type of a large extended partition from 5 to f, OS/2 loses access. OS/2 Boot Manager keeps a private copy of the partition table data. This leads to problems when changing the partition table with 3rd party tools. Then there is the problem of what to write in C/H/S
if the numbers do not fit. The main three strategies seem to be 1. Mark
C/H/S as invalid by writing 1023/255/63. 2. Leave H, S but do something to
C. 2a. Truncate C to 1023, writing (1023, #heads-1, #sectors). 2b. Reduce
C mod 1024, writing only its last 10 bits. Of course, both fail if H or S
does not fit. The first seems most sensible. Some versions of Linux fdisk
used 2a or 2b, and this confuses OS/2 fdisk - cf. Linux, OS/2 and
>1024 Cylinder HDDs. David A. Burton
Partition MagicA very convenient tool for manipulating partitions is Partition Magic, a commercial program from PowerQuest. Below a description of some of its error numbers. (Here the complete list.) This is of interest also for those who do not have this program: it indicates what conditions the PowerQuest people think a partition table should satisfy. (Not all of these conditions are complied with by DRDOS or OS/2 or Linux or Windows NT on Alpha, so a partition manipulator should accept a much wider range of partition tables, but such a program might try to follow these rules when creating partitions.)
AcknowledgementsA lot of useful information was supplied by various
people: Thomas Wolfram ( |