1

I am creating a basic MBR that reads the Partition Table and loads the first sector of the Bootable Partition. I am confused by the CHS and LBA addressing modes. I read in a tutorial that CHS is more or less not used except for compatibility reasons. So, I opted to use LBA(INT 13h extensions). To load the sector of the drive, I have to read the CHS value from the Partition table of that partition. Only then I could convert it to LBA and store it in "Disk Address Packet".

My doubt is, The CHS in Partition table is 1 byte each. Should I take this value directly and convert it into LBA (or) I have to first convert it into,

Cylinder = 10 bits
Sector   = 6 bits
Head     = 8 bits

and then convert it into LBA?

Note: My MBR must be able to access sectors on both HDD and USB - That is the motive.

OS : Ubuntu

Assembler : Gas

Panther Coder
  • 1,058
  • 1
  • 16
  • 43

1 Answers1

2

Partition table entries use CHS only for backward compatibility with very old OSes.
They also have fields for the LBA address:

 
 
                    Format of the MBR partition table

 
 

Note that this use LBA32, thus there is a limit on the partition size and position. Quoting Wikipedia:

Since block addresses and sizes are stored in the partition table of an MBR using 32 bits, the maximum size as well as the highest start address of a partition using drives that have 512-byte sectors (actual or emulated) cannot exceed 2 TiB−512 bytes (2,199,023,255,040 bytes or 4,294,967,295 (232−1) sectors × 512 (29) bytes per sector).[2] Alleviating this capacity limitation was one of the prime motivations for the development of the GPT.

The same is also true for CHS addressing.
OSes that use the CHS fields have a limitation of about 8 GiB in size.
So if you want to be compatible with them, you need to stay under that limit.


The formula for converting LBA <-> CHS can be easily derived or found on the Internet, you can think in term of sector numbers (i.e. LBA) and convert into CHS when creating the partition entry (or use the defaults 1023, 255, 63 tuble for partition too big for CHS).

Bottom of the line, use the LBA fields.
Or go for GPT.

Margaret Bloom
  • 41,768
  • 5
  • 78
  • 124
  • So, to load a sector from hard disk(say), can I use the "starting sector" of the partition table using INT 13h extensions? As far as I know, the "starting sector" value is equivalent to the starting LBA value of the partition ri8? – Panther Coder Dec 21 '16 at 16:25
  • Does the same applies for booting using Pen drives too?(I mean, they all can use the LBA addressing mode as long as the BIOS supports it right?) – Panther Coder Dec 21 '16 at 16:26
  • @PantherCoder Yes, the INT13h abstract the details of the specific device, so you have just to give it the drive number and the address of the sector. It offers a standard interface. You should use the INT13h extensions though, they are better. – Margaret Bloom Dec 21 '16 at 17:31