How does one convert LBA to CHS with regards to USBs whereupon the format is inapplicable

biosmbrpartitioningusb

I should like to manually write the partition table of the MBR (master boot record): the first sector of a drive.

Bytes 2 through 4 require one to find out the CHS (Cylinder-Head-Sector) Address. But, I am using a USB stick, and as far as I am concerned, they don't have physical cylinders, heads, or sectors (except that the sectors can be determined by sets of 512 bytes.)

Thus I was stopped in my writing of the partition table. The LBA address of any sector is incredibly easy to attain (the LBA address also being required in the partition table entry.) But I am clueless as of how to render CHS in a drive devoid of cylinders and heads.

So, if anyone could shed a light on how this conversion would go or better, give me a resource on how the BIOS interprets the MBR, I would be grateful.

Thank you.

Best Answer

Fill it with 0xFFFF.

Every modern system, both OS and BIOS, is LBA-capable; it will ignore the C/H/S field and use linear sector addresses.

(And on top of that, USB-connected disks must speak SCSI – not ATA – and SCSI only supports LBA requests anyway.)

Since most partitions are larger than the C/H/S field can express (and it's ignored by literally everything), the usual practice is to fill in the maximum possible value.

I am using a USB stick, and as far as I am concerned, they don't have physical cylinders, heads, or sectors (except that the sectors can be determined by sets of 512 bytes.)

As far as you're concerned, neither do actual HDDs – they just make up some values for the sake of ancient systems, but none of it corresponds to the physical structure, which is completely hidden from the outside. Even though they do physically have heads and such, they're designed to be used with linear LBA addresses only (and they have orders of magnitude more cylinders and sectors that can fit in the C/H/S field anyway).

So it doesn't matter what kind of disk the MBR partition table goes into, it's almost always enough to fill in placeholder values.

(Then there are SMR HDDs which don't even have a 1:1 correspondence of LBAs and physical sectors – they have a mapping table like SSDs do...)

Related Question