[#obfdisko]:

OpenBSD fdisk Partition Report

This report came from an actual physical drive that was about a TB in size.

fdisk: 1> p
Disk: sd0       geometry: 121601/255/63 [1953525168 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
*0: A6  16710   0   1 -  33419  85  16 [   268446150:   268435456 ] OpenBSD
 1: 82  34919   0   1 -  38052   0   3 [   560973735:    50331648 ] Linux swap
 2: 83  38053   0   1 -  54762  85  16 [   611321445:   268435456 ] Linux files*
 3: 83  54764   0   1 - 121600 254  63 [   879783660:  1073736405 ] Linux files*
fdisk: 1>

This provides quite a few details; understanding every single detail may be typically unnecessary these days, but going through this anyway may help remove some of the mystery behind the numbers.

Next to the word Disk is the name of the disk.

Just below that is an Offset. Its purpose is relatively unknown. This offset seems to always be 0. (Speculation: perhaps this may have been non-zero when using the now-discontinued support for the Atari Gemdos variation, and may be non-zero on some more modern removable media like some memory cards.) Anyway, for a standard hard drive, don't be surprised if it is zero.

The “geometry” refers to an old style of describing different sections of a disk. In the example shown above, 121601 cylinders x 255 heads/tracks x 63 half-KB sectors per track = 1,953,520,065 sectors, which is just a bit less than the 1,953,525,168 sectors. By using the hard disk geometry, we may effectively be unable to access the last 5,103 half-KB sectors on the disk, which effectively wastes a bit under 2.5 MB. However, this is a small portion of the disk (less than the size of a single 16,065 KB cylinder) that gets wasted. Also, using geometry references is likely to increase compatability and speed. The most common hard drive geometry (on drives that are sufficiently new, perhaps meaning drives exceeding a 7,560MB limit mentioned by a web page about a 4GB hard drive limit) is to use 63 heads/tracks for each cylinder, and 255 sectors on each head/track.

Annoyingly, although sector numbers are numbered using a 1-based (from 1 to 63) count, heads/tracks use a zero-based count. So if there are 255 heads/tracks, then they are numbered from zero through 254. So there won't be a head/track number 255.

The Signature should be set to the known “Magic signature” for boot drives if this drive contains the “boot code” that runs every time the system gets started. (If that signature isn't set yet, then make sure to run the update command in the fdisk program.)

The next two rows represent two-row column labels. The labels refer to: partition number, MBR Partition Type Identifier, Starting Cylinder, Starting Head/Track, Starting Sector, Ending Cyinder, Ending Head/Track, Ending Sector, Logical Block Access start, Logical Block Access size. The last column is not given a label, but is a description of the drive. The description, provided in the last and unlabeled column, is a description that fdisk has for the value of the MBR Partition Type Identifier. (If the value of the MBR Partition Type Identifier gets changed, then that description will also change to reflect the new value of the MBR Partition Type Identifier.)

The third partition (which is partition #1 since the partitions are described using a zero-based count) provides a set of numbers that are fairly useful for demonstrating how some of these numbers relate to each other, so that will be focused on for an example. (The disk layout is also about to be repeated for convenience.)

For each partition, if we multiply the starting cyliner (which, in the previous example, is 38053 for the second partition, which is partition number 1) by the number of heads per cylinder (255 in the previous example) and the number of sectors per head/track (63 in the previous example), the result will be a sector number on where the cylinder starts. Using that example, 38053 x 255 x 63 = 611,321,445. In the previous example, the partition starts on the first track (head number zero) and on the first sector (sector number one), and so the partition's starting sector is the same sector as the cylinder's starting sector. That is extremely common. If a different track/head and sector are used, then things get a bit more complicated; that is usually the case for the Ending sector, so the upcoming discussion for the Ending sector will demonstrate how that gets handled.

As promised, here is a repeat of the hard drive layout:

fdisk: 1> p
Disk: sd0       geometry: 121601/255/63 [1953525168 Sectors]
Offset: 0       Signature: 0xAA55
            Starting         Ending         LBA Info:
 #: id      C   H   S -      C   H   S [       start:        size ]
-------------------------------------------------------------------------------
*0: A6  16710   0   1 -  33419  85  16 [   268446150:   268435456 ] OpenBSD
 1: 82  34919   0   1 -  38052   0   3 [   560973735:    50331648 ] Linux swap
 2: 83  38053   0   1 -  54762  85  16 [   611321445:   268435456 ] Linux files*
 3: 83  54764   0   1 - 121600 254  63 [   879783660:  1073736405 ] Linux files*
fdisk: 1>

The size can also be calculated from the other data found. First, figure out the ending sector. Start by taking the ending cylinder (54762 for partition number 2 in the previous example), and multiply that by the number of heads per cylinder (255 in the previous example) and the number of sectors per head/track (63 in the previous example). 54762 x 255 x 63 = 879,751,530. That is the sector number for the cylinder that contains the end of the partition. Then, in the previous example, we see that the partition ends on track/head number 85 of that cylinder. Each track/head is 63 sectors large, so multiply 85 x 63 = 5,355. So the partition ends on a head which starts on sector 5,355 of the cylinder that starts at 879,751,530. Now, add the Cylinder's starting position (879,751,530) to the head's relative starting position (5,355) and add those to the sector offset (which is in the next column, and shows as 16 in the example output). 879,751,530 + 5,355 + 16 = 879,756,901.

So, the partition ends on sector 879,756,901. If the starting sector (611,321,445) is subtracted from the ending sector (879,756,901), then the difference/result should be the size. (879,756,901 - 611,321,445 does need equal 268,435,456.)

Now, that is a lot of math. Some other partition editing programs may show the ending sector directly, instead of showing the size. (At least one program can flip between showing the size or showing the ending sector.) Actually doing that math is something that does not typically need to be done manually. However, the reason for demonstrating this math is that hopefully it is now clear how some of these numbers are related. The start of details of the LBA Info is simply a compact way of showing the same thing as the Starting Cylinder, Head/Track, and Sector position. The size is determined by comparing that partition's starting position and the partition's ending position. The partition's ending position can be determined from the Ending Cylinder, Head/Track, and Sector.