Hard disks perform a very simple function -- they store data and reliably retrieve it on command.
When discussing issues such as disk partitioning, it's important to know a bit about the underlying hardware; unfortunately, it's easy to become bogged down in details. Therefore, let's use a simplified diagram of a disk drive to help us explain what goes on ``under the hood.'' Figure 135 shows a brand-new, unused disk drive.
Not much to look at, is it? But if we're talking about disk drives on a basic level, it will do. Let's say that we'd like to store some data on this drive. As things stand now, it won't work. There's something we need to do first...
The old-timers in the audience probably got this one of the first try. We need to format the drive. Formatting (usually known as ``making a filesystem'' in Linux parlance) writes information to the drive, creating order out of the empty space in an unformatted drive.
As Figure 136 implies, the order imposed by a filesystem involves some tradeoffs:
Given that filesystems make things like directories and files possible, these tradeoffs are usually seen as a small price to pay.
It's also worth noting that there is no single, universal filesystem; as Figure 137 shows, a disk drive may have one of many different filesystems written on it. As you might guess, different filesystems tend to be incompatible; that is, an operating system that supports one filesystem (or a handful of related filesystem types) may not support another. This last statement is not a hard-and-fast rule, however. For example, Red Hat Linux supports a wide variety of filesystems (including many commonly used by other operating systems), making data interchange easy.
Of course, writing a filesystem to disk is only the beginning. The goal of this process is to actually store and retrieve data. Let's take a look at our drive after some files have been written to it.
As Figure 138 shows, 14 of the previously-empty inodes are now holding data. We cannot determine how many files reside on this drive; it may be as few as one or as many as 14, as all files use as least one inode. Another important point to note is that the used inodes do not have to form a contiguous region; used and unused inodes may be interspersed. This is known as fragmentation. Fragmentation can play a part when attempting to resize an existing partition.
As with most computer-related technologies, disk drives continued to change over time. In particular, they changed in one specific way -- they got bigger. Not bigger in size, but bigger in capacity. And it was this additional capacity that drove a change in the way disk drives were used.
As disk drive capacities soared, some people started wondering if having all that space in one big chunk wasn't such a great idea. This line of thinking was driven by several issues, some philosophical, some technical. On the philosophical side, above a certain size, it just seemed that the additional space provided by a larger drive made for more clutter. On the technical side, some filesystems were never designed to support larger drives. Or the filesystems could support larger drives, but the overhead imposed by the filesystem became excessive.
The solution to this problem was to divide disks into partitions. Each partition can be accessed as if it was a separate disk. This is done through the addition of a partition table.
Please Note: While the diagrams in this chapter show the partition table as being separate from the actual disk drive, this is not entirely accurate. In reality, the partition table is stored at the very start of the disk, before any filesystem or user data. But for clarity, we'll keep it separate in our diagrams.
As Figure 139 shows, the partition table is divided into four sections. Each section can hold the information necessary to define a single partition, meaning that the partition table can define no more than four partitions.
Each partition table entry contains several important characteristics of the partition:
Let's take a closer look at each of these characteristics. The starting and ending points actually define the partition's size and location on the disk. The ``active'' flag is used by some operating systems' boot loaders. In other words, the operating system in the partition that is marked ``active'' will be booted.
The partition's type can be a bit confusing. The type is a number that identifies the partition's anticipated usage. If that statement sounds a bit vague, that's because the meaning of the partition type is a bit vague. Some operating systems use the partition type to denote a specific filesystem type, to flag the partition as being associated with a particular operating system, to indicate that the partition contains a bootable operating system, or some combination of the three.
Figure 140 contains a listing of some popular (and obscure) partition types, along with their numeric values.
Partition Type | Value | Partition Type | Value |
Empty | 00 | Novell Netware 386 | 65 |
DOS 12-bit FAT | 01 | PC/IX | 75 |
XENIX root | 02 | Old MINIX | 80 |
XENIX usr | 03 | Linux/MINIX | 81 |
DOS 16-bit <=32M | 04 | Linux swap | 82 |
Extended | 05 | Linux native | 83 |
DOS 16-bit >=32M | 06 | Linux extended | 85 |
OS/2 HPFS | 07 | Amoeba | 93 |
AIX | 08 | Amoeba BBT | 94 |
AIX bootable | 09 | BSD/386 | a5 |
OS/2 Boot Manager | 0a | OpenBSD | a6 |
Win95 FAT32 | 0b | NEXTSTEP | a7 |
Win95 FAT32 (LBA) | 0c | BSDI fs | b7 |
Win95 FAT16 (LBA) | 0e | BSDI swap | b8 |
Win95 Extended (LBA) | 0f | Syrinx | c7 |
Venix 80286 | 40 | CP/M | db |
Novell? | 51 | DOS access | e1 |
Microport | 52 | DOS R/O | e3 |
GNU HURD | 63 | DOS secondary | f2 |
Novell Netware 286 | 64 | BBT | ff |
Now you might be wondering how all this additional complexity is normally used. See Figure 141 for an example.
That's right -- in many cases there is but a single partition spanning the entire disk, essentially duplicating the pre-partitioned days of yore. The partition table has only one entry used, and it points to the start of the partition. We've labeled this partition as being of type ``DOS,'' although as you can see from Figure 140, that's a bit simplistic, but adequate for the purposes of this discussion. This is a typical partition layout for most newly purchased computers with some version of Windows pre-installed.
Of course, in time it became obvious that four partitions would not be enough. As disk drives continued to grow, it became more and more likely that a person could configure four reasonably-sized partitions and still have disk space left over. There needed to be some way of creating more partitions.
Enter the extended partition. As you may have noticed in Figure 140, there is an ``Extended'' partition type; it is this partition type that is at the heart of extended partitions. Here's how it works.
When a partition is created and its type is set to ``Extended,'' an extended partition table is created. In essence, the extended partition is like a disk drive in its own right -- it has a partition table that points to one or more partitions (now called logical partitions, as opposed to the four primary partitions) contained entirely within the extended partition itself. Figure 142 shows a disk drive with one primary partition, and one extended partition containing two logical partitions (along with some unpartitioned free space).
As this figure implies, there is a difference between primary and logical partitions -- there can only be four primary partitions, but there is no fixed limit to the number of logical partitions that can exist. (However, in reality it is probably not a good idea to try to define and use more than 12 logical partitions on a single disk drive.)