Drive Geometry

Drive Geometry refers to the specifics of how the drive is accessed and addressed by the lower levels of the Linux kernel (and similarly for other operating systems.) This is relevant primarily to hard drives, and derives from physical characteristics of the early implementations of rotating storage. It is less tied to physical implementation currently, but drives maintain some backward-compatible interface features to accomodate older system software. This in turn can have some impact on modern usage.

= Vocabulary = There are a few terms which need to be understood for the rest of this to make sense.
 * sector -- the smallest unit of storage that can be transferred to or from a storage device. This used to be identical to the size of the records that the drive hardware wrote on the surface, but this connection is no longer maintained.  Buffering in the drives' RAM allows for storage on the drive to be in much larger units, perhaps 2 MiB.
 * block -- the unit size for files stored on the device, always a multiple of the sector size. This may be specified independently for each filesystem/partition on the drive.  Linux extended file systems use block sizes between 1K and 4K (2 to 8 sectors).
 * head -- a read-write head used by the hardware to transfer signals between the media surface and the electronics. Also used abstractly as discussed below.  If a device has more than one head, they are almost always arranged in a comb such that when they move all heads move the same amount at the same time.
 * platter -- a physical disk which is a component of rotating magnetic media, potentially offering two recording surfaces for data storage.
 * track -- the collection of sectors which can be accessed by a single head without moving. Think of this as a circular path on one rotating surface of a platter.
 * cylinder -- the collection of all tracks which can be accessed without moving the comb or heads. Since the tracks of the heads are arranged in a stack, they suggest a geometric cylinder.
 * seek -- the action taken by a drive to move the comb of heads to a new cylinder.
 * partition -- a subdivision of a hard drive. For Linux, each partition may contain a filesystem, or may be used as swap space.
 * master boot record (MBR) -- the first sector of a drive. Here are found a disk label, the first part of a system bootstrap, and (some of) the partitioning information for the drive.
 * drive -- as used here, a physical unit of rotating magnetic storage. Be aware that this term is used differently depending on the context or software being used.  Microsoft uses this term to refer to what is defined as a partition here.  RAID storage or other virtual volume management systems may create virtual disks which are more or less simulations of a drive.

= Geometry = It used to be that drives had an inherent set of constraints, established by physical characteristics of their manufacture. For some time now, it has been much more common for the total number of sectors on a drive to be the only unchanging characteristic, and the others are set as desired and the drive's electronics will map sectors to the hardware as needed.

The other aspects, which are arbitrarily set, and their limits (for MSDOS compatibility) are: The usable capacity of a drive is the product of the cylinder, head, and sector counts times 512 bytes per sector. Thus, the maximum capacity of a MSDOS-compatible drive is 1048576*255*63*512 = 8624831201280 = 8225280 mibibytes, or around 8 terrabytes. These values are set for the entire drive, and must be uniform across all of the partitions on that drive.
 * cylinders -- the number of cylinders, 1-1048576.
 * heads -- the number of heads, and accordingly the number of tracks per cylinder, 1-255.
 * sectors -- the number of sectors per track, 1-63.

There are non-MSDOS arrangements that may be used, but are not (yet) discussed here. They usually go with a different kind of MBR, disk label and partitioning scheme.

= Choosing the Geometry = The fdisk utility has an "expert" mode in which the drive geometry can be changed. This is not for the novice or the faint of heart. Changing these things surely will make any existing partitions on the drive unreadable. If the settings are incompatible with (too large for) the drive capacity, the drive will be unusable by some other utilities such as gparted, and may be prone to loss of data.

Some versions of fdisk have a quirk that requires you to create a partition in the same session in which you define the geometry, or else your changes will not take effect.

Fdisk falls back on 255 heads and 63 sectors per track (the maximum values) whenever it's in doubt. Since MSDOS-compatible partitions must begin and end on cylinder boundaries, it often happens that this forces there to be unallocated sectors at the end of the drive. You can generally see these in gparted, for instance.

Take current 2 TB drives, for instance. These drives have recently become quite affordable. A common size is 2000398934016 bytes, which is 3907029168 512-byte sectors. The factor utility is useful for working with this number: $ factor 3907029168 3907029168: 2 2 2 2 3 3 3 3 7 269 1601

In order to use the entire drive capacity, these factors must be grouped into the sector, head and cylinder values so that the product of these three values is exactly the drive capacity in sectors. Because 269 and 1601 are both too large to be part of sector or head counts, they must be instead part of the cylinder count. Their product is 430669 and the cylinder count is limited to 1048576, so the cylinder count must be either 430669 or 861338, because 430669*3 is too large. The impact of the choice here is mainly that more cylinders gives more choices about the size of each partition. However, in either case a cylinder is at most 4 megabytes or so, or about 1/500000 of the drive. This is fine-grained enough for almost any purpose. Having chosen a cylinder count (and corresponding cylinder size), the choice of head and sector counts is arbitrary so long as they divide the cylinder size evenly. The options are numerous, but do not make much difference in practice: Cylinders           Heads              Sectors 269*1601  =430669   2*2*2*2*3*3  =144   3*3*7     =63 269*1601   =430669   2*3*3*3*3    =162   2*2*2*7   =56 269*1601   =430669   2*2*2*3*7    =168   2*3*3*3   =54 269*1601   =430669   3*3*3*7      =189   2*2*2*2*3 =48 269*1601   =430669   2*2*2*3*3*3  =216   2*3*7     =42 269*1601   =430669   2*2*3*3*7    =252   2*2*3*3   =36 269*1601*2 =861338   2*2*2*3*3    =72    3*3*7     =63 269*1601*2 =861338   3*3*3*3      =81    2*2*2*7   =56 269*1601*2 =861338   2*2*3*7      =84    2*3*3*3   =54 269*1601*2 =861338   2*2*3*3*3    =108   2*3*7     =42 269*1601*2 =861338   2*3*3*7      =126   2*2*3*3   =36 269*1601*2 =861338   2*3*3*3*3    =162   2*2*7     =28 269*1601*2 =861338   2*2*2*3*7    =168   3*3*3     =27 269*1601*2 =861338   3*3*3*7      =189   2*2*2*3   =24 269*1601*2 =861338   2*2*2*3*3*3  =216   3*7       =21 269*1601*2 =861338   2*2*3*3*7    =252   2*3*3     =18

In all of these cases, each of the three geometry values is an even divisor of the total number of sectors and is within the allowed limits for that value. This is what ensures the maximum number of usable sectors. Notice that while fdisk's default value of 63 for sectors/track does occur, the value of 255 heads does not. If you choose default MSDOS formatting on a new drive, you are going to have unallocated space. Drives that are formatted by the vendor often arrive in such a non-optimum default state.

You can try this derivation yourself. You'd think a 1 TB drive would be half the size of a 2 TB drive, but you would be wrong. This author has no idea why these sizes are chosen, but it is common for a 1 TB drive to be 1,000,204,886,016 bytes, or 1,953,525,168 sectors. Practice your math and see if you get 15 optimal geometries. HINT: all have the same cylinder count and size, and one of them has 252 heads and 12 sectors per track.

= Why You Should Not =

For almost all users, actually reconfiguring the drive is a bad idea. This article is here to satisfy the curious and help those who cannot stop themselves from making fatal mistakes. The rest of you should just let this slide. Here's why.


 * 1) It is dangerous.  You'll be working on bare drives, and there will be nothing between you and damaging data that you probably don't want to lose.
 * 2) It is dangerous.  If you ever do this stuff on a drive that contains any data, you are liable to lose that data.  Especially if you do it to the wrong drive by mistake.
 * 3) It is dangerous.  Some of the things you will do can get the drive out of sync with the kernel's cache and tables, and I don't even discuss that here.
 * 4) It is tricky.  You have to do things in the right order, and I don't even discuss that here.
 * 5) It is not worth the effort.  You are trying to recover a partial cylinder of the original formatting.  These cylinders are a shade over 8 MB.  Maybe your drive is small, say 320 GB for a laptop.  One cylinder is .000025 (25 parts in a million) of the drive capacity.  Likely this is not worth taking any considerable risk at all.
 * 6) It is weird. Most of the world has gotten used to large disks with the default formatting.  When people get used to one thing, they often make mistakes if something else comes along.
 * 7) The guidance here is incomplete, and may be wrong.  If you're like me and want to do this anyway, there can be other drawbacks.  Drives of different sizes, or even drives from different manufacturers, will have different possible cylinder sizes.  Among other things, this makes it impossible to simply copy a partition between these kinds of drives (using a utility such as dd).  With uniform cylinder sizes, this is can be possible (only sometimes, it also depends on the partitions involved since some partitions reserve the first track for a partition table, and others do not).
 * 8) There are no guarantees.  I have not checked that this sort of foolery works with Microsoft operating systems, or any of a number of other things that could go wrong.

= Links =