Skip to contentSkip to conversation

fdisk geometry

DISCUSSION John Lane 3 participants 6 messages Jul 26, 2012 – Jul 27, 2012 Util-Linux package

lore
Share & tools
lore

John Lane

author
#0 lore raw

Hello, I'm in the middle of studying disk organisation to enhance my understanding in this area. I have a few questions about fdisk (trying to fill a gap in my knowledge if that's ok)...

In the below output of fdisk it shows (correctly) a geometry of 224 heads, 56 sectors/track. I'm unclear about where this information comes from. Normally a disk's geometry would be reported as 255 heads and 63 sectors. I explicitly partitioned this disk using a 224/56 geometry, so the report is correct. I'd just like to understand:

(a) where fdisk gets the information about the geometry from in this specific case?
(b) when fdisk defaults to 255/63 is that because it's hard coded that way or is there another reason?

I understand why it's 255/63 by default but haven't been able to understand how the geometry is determined. I do know that it's all kind of moot these days anyway because of sector based addressing but that leads to one other question: given sector based addressing why does fdisk even bother displaying a geometry any more ? Doesn't it just serve to confuse?

# fdisk /dev/sda
Welcome to fdisk (util-linux 2.21.2).

Changes will remain in memory only, until you decide to write them. Be careful before using the write command.

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
224 heads, 56 sectors/track, 12460 cylinders, total 156301488 sectors Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc4c4122e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          56      501759      250852   83  Linux
/dev/sda2          501760   156298239    77898240   8e  Linux LVM

Command (m for help): q

Many thanks for your time,
John Lane.

#1 lore raw
Quoted 3 lines · John Lane

Hello, I'm in the middle of studying disk organisation to enhance my understanding in this area. I have a few questions about fdisk (trying to fill a gap in my knowledge if that's ok)...

use the source, Luke :)

Quoted 9 lines

In the below output of fdisk it shows (correctly) a geometry of 224 heads, 56 sectors/track. I'm unclear about where this information comes from. Normally a disk's geometry would be reported as 255 heads and 63 sectors. I explicitly partitioned this disk using a 224/56 geometry, so the report is correct. I'd just like to understand:

(a) where fdisk gets the information about the geometry from in this specific case?

fdisk gets the information from (i) user input, (ii) what the kernel/bios thinks the geometry is, with the HDIO_GETGEO ioctl and (iii) by inferring it from the partition table geometry.

Quoted 2 lines

(b) when fdisk defaults to 255/63 is that because it's hard coded that way or is there another reason?

Correct.

Quoted 7 lines

I understand why it's 255/63 by default but haven't been able to understand how the geometry is determined. I do know that it's all kind of moot these days anyway because of sector based addressing but that leads to one other question: given sector based addressing why does fdisk even bother displaying a geometry any more ? Doesn't it just serve to confuse?

That's because fdisk is/was mostly legacy code, we are currently updating the program.

Cheers,
Davidlohr

Quoted 33 lines
# fdisk /dev/sda
Welcome to fdisk (util-linux 2.21.2).

Changes will remain in memory only, until you decide to write them. Be careful before using the write command.

Command (m for help): p

Disk /dev/sda: 80.0 GB, 80026361856 bytes
224 heads, 56 sectors/track, 12460 cylinders, total 156301488 sectors Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xc4c4122e

Device Boot Start End Blocks Id System

/dev/sda1   *          56      501759      250852   83  Linux
/dev/sda2          501760   156298239    77898240   8e  Linux LVM

Command (m for help): q

Many thanks for your time,
John Lane.

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#2 lore raw
Quoted 6 lines · Davidlohr Bueso
Quoted 2 lines

(a) where fdisk gets the information about the geometry from in this specific case?

fdisk gets the information from (i) user input, (ii) what the kernel/bios thinks the geometry is, with the HDIO_GETGEO ioctl and (iii) by inferring it from the partition table geometry.

BTW, does it make any sense to read the geometry from partition table if the partition table has been aligned according to the device topology (for example 1MiB offset and grain)?

Quoted 2 lines
Quoted 2 lines

fdisk even bother displaying a geometry any more ? Doesn't it just serve to confuse?

IMHO for non-DOS compatible mode it would be better to ignore PT geometry (read only info from kernel to have "some" values) and don't display geometry in the default output, because it's completely irrelevant.

The same we can do with -S -C -H options -- it would be better to print a warning if the options are specified for non-DOS mode.

I still see on many places suggestions like "use -S -H to align your flash disk" or so... all this is legacy.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#3 lore raw
Quoted 11 lines · Karel Zak
Quoted 6 lines · Davidlohr Bueso
Quoted 2 lines

(a) where fdisk gets the information about the geometry from in this specific case?

fdisk gets the information from (i) user input, (ii) what the kernel/bios thinks the geometry is, with the HDIO_GETGEO ioctl and (iii) by inferring it from the partition table geometry.

BTW, does it make any sense to read the geometry from partition table if the partition table has been aligned according to the device topology (for example 1MiB offset and grain)?

Hmm not really, no. In any case we got rid of the pt geometry, __discover_system_geometry() only gets the info from the kernel.

Quoted 11 lines
Quoted 2 lines
Quoted 2 lines

fdisk even bother displaying a geometry any more ? Doesn't it just serve to confuse?

IMHO for non-DOS compatible mode it would be better to ignore PT geometry (read only info from kernel to have "some" values) and don't display geometry in the default output, because it's completely irrelevant.

The same we can do with -S -C -H options -- it would be better to print a warning if the options are specified for non-DOS mode.

I agree.

Quoted 5 lines

I still see on many places suggestions like "use -S -H to align your flash disk" or so... all this is legacy.

Karel

maintainer
#4 lore raw
Quoted 9 lines · Davidlohr Bueso
Quoted 8 lines · Karel Zak
Quoted 6 lines · Davidlohr Bueso
Quoted 2 lines

(a) where fdisk gets the information about the geometry from in this specific case?

fdisk gets the information from (i) user input, (ii) what the kernel/bios thinks the geometry is, with the HDIO_GETGEO ioctl and (iii) by inferring it from the partition table geometry.

Quoted 6 lines
Quoted 3 lines

BTW, does it make any sense to read the geometry from partition table if the partition table has been aligned according to the device topology (for example 1MiB offset and grain)?

Hmm not really, no. In any case we got rid of the pt geometry, __discover_system_geometry() only gets the info from the kernel.

I have moved get_partition_table_geometry() to dos_probe_label() :-) It seems we need if (dos_compatible) there.

It means that for MBR we still read the PT geometry ;-)

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
author
#5 lore raw
In reply to Davidlohr Bueso
Quoted 5 lines · Davidlohr Bueso
Quoted 3 lines · John Lane

Hello, I'm in the middle of studying disk organisation to enhance my understanding in this area. I have a few questions about fdisk (trying to fill a gap in my knowledge if that's ok)...

use the source, Luke :)

:)

Quoted 11 lines
Quoted 8 lines

In the below output of fdisk it shows (correctly) a geometry of 224 heads, 56 sectors/track. I'm unclear about where this information comes from. Normally a disk's geometry would be reported as 255 heads and 63 sectors. I explicitly partitioned this disk using a 224/56 geometry, so the report is correct. I'd just like to understand:

(a) where fdisk gets the information about the geometry from in this specific case?

fdisk gets the information from (i) user input, (ii) what the kernel/bios thinks the geometry is, with the HDIO_GETGEO ioctl and (iii) by inferring it from the partition table geometry.

Thanks, yes I was able to deduce this from the source but I wasn't confident I had it right. Reading this confirms nicely what I thought was going on.

Quoted 4 lines
Quoted 2 lines

(b) when fdisk defaults to 255/63 is that because it's hard coded that way or is there another reason?

Correct.

Quoted 8 lines
Quoted 6 lines

I understand why it's 255/63 by default but haven't been able to understand how the geometry is determined. I do know that it's all kind of moot these days anyway because of sector based addressing but that leads to one other question: given sector based addressing why does fdisk even bother displaying a geometry any more ? Doesn't it just serve to confuse?

That's because fdisk is/was mostly legacy code, we are currently updating the program.

I've just seen the upcoming changes, removing the messages when not in dos mode.

Quoted 4 lines

Cheers,
Davidlohr