3. Disk Access
Disk access is done in units called sectors. In order to read or
write something from or to the disk, we have to specify the position
on the disk, for example by giving the sector number. If the disk is
a SCSI disk, then this sector number goes directly into the SCSI
command and is understood by the disk. If the disk is an IDE disk
using LBA, then precisely the same holds. But if the disk is old, RLL
or MFM or IDE from before the LBA times, then the disk hardware
expects a triple (cylinder,head,sector) to designate the desired spot
on the disk.
3.1. Cylinders, heads and sectors
A disk has sectors numbered 0, 1, 2, ... This is called LBA
addressing.
In ancient times, before the advent of IDE disks, disks had a geometry
described by three constants C, H, S: the number of cylinders, the
number of heads, the number of sectors per track. The address of a
sector was given by three numbers: c, h, s: the cylinder number
(between 0 and C-1), the head number (between 0 and H-1), and the
sector number within the track (between 1 and S), where for some
mysterious reason c and h count from 0, but s counts from 1. This is
called CHS addressing.
No disk manufactured less than ten years ago has a geometry, but this
ancient 3D sector addressing is still used by the INT13 BIOS interface
(with fantasy numbers C, H, S unrelated to any physical reality).
The correspondence between the linear numbering and this 3D notation
is as follows: for a disk with C cylinders, H heads and S
sectors/track position (c,h,s) in 3D or CHS notation is the same as
position c*H*S + h*S + (s-1) in linear or LBA notation.
Consequently, in order to access a very old non-SCSI disk, we need to
know its geometry, that is, the values of C, H and S. (And if you
don't know, there is a lot of good information on
www.thetechpage.com.)
3.2. Sectorsize
In the present text a sector has 512 bytes. This is almost always
true, but for example certain MO disks use a sectorsize of 2048 bytes,
and all capacities given below must be multiplied by four. (When
using fdisk on such disks, make sure you have version 2.9i or later,
and give the `-b 2048' option.)
3.3. Disksize
A disk with C cylinders, H heads and S sectors per track has C*H*S
sectors in all, and can store C*H*S*512 bytes. For example, if the
disk label says C/H/S=4092/16/63 then the disk has 4092*16*63=4124736
sectors, and can hold 4124736*512=2111864832 bytes (2.11 GB). There
is an industry convention to give C/H/S=16383/16/63 for disks larger
than 8.4 GB, and the disk size can no longer be read off from the
C/H/S values reported by the disk.
3.4. The 1024 cylinder and 8.5 GB limits
The old INT13 BIOS interface to disk I/O uses 24 bits to address a
sector: 10 bits for the cylinder, 8 bits for the head, and 6 bits for
the sector number within the track (counting from 1). This means that
this interface cannot address more than 1024*256*63 sectors, which is
8.5 GB (with 512-byte sectors). And if the (fantasy) geometry
specified for the disk has fewer than 1024 cylinders, or 256 heads, or
63 sectors per track, then this limit will be less.
(More precisely: with INT 13, AH selects the function to perform, CH
is the low 8 bits of the cylinder number, CL has in bits 7-6 the high
two bits of the cylinder number and in bits 5-0 the sector number, DH
is the head number, and DL is the drive number (80h or 81h). This
explains part of the layout of the partition table.)
This state of affairs was rectified when the so-called Extended INT13
functions were introduced. A modern BIOS has no problems accessing
large disks.
(More precisely: DS:SI points at a 16-byte Disk Address Packet that
contains an 8-byte starting absolute block number.)
Linux does not use the BIOS, so does (and did) not have this problem.
However, this geometry stuff plays a role in the interpretation of
partition tables, so if Linux shares a disk with for example DOS, then
it needs to know what geometry DOS will think the disk has. It also
plays a role at boot time, where the BIOS has to load a boot loader,
and the boot loader has to load the operating system.
3.5. The 137 GB limit
The old ATA standard describes how to address a sector on an IDE disk
using 28 bits (8 bits for the sector, 4 for the head, 16 for the
cylinder). This means that an IDE disk can have at most 2^28
addressable sectors With 512-byte sectors this is 2^37 bytes, that is,
137.4 GB.
The ATA-6 standard includes a specification how to address past this
2^28 sector boundary. The new standard allows addressing of 2^48
sectors. There is support in recent Linux kernels that have
incorporated Andre Hedrick's IDE patch, for example 2.4.18-pre7-ac3
and 2.5.3.
Maxtor sells 160 GB IDE disks since Fall 2001. An old kernel will
treat such disks as 137.4 GB disks.
4. History of BIOS and IDE limits
ATA Specification (for IDE disks) - the 137 GB limit
At most 65536 cylinders (numbered 0-65535), 16 heads (numbered
0-15), 255 sectors/track (numbered 1-255), for a maximum total
capacity of 267386880 sectors (of 512 bytes each), that is,
136902082560 bytes (137 GB). In Sept 2001, the first drives
larger than this (160 GB Maxtor Diamondmax) appeared.
BIOS Int 13 - the 8.5 GB limit
At most 1024 cylinders (numbered 0-1023), 256 heads (numbered
0-255), 63 sectors/track (numbered 1-63) for a maximum total
capacity of 8455716864 bytes (8.5 GB). This is a serious
limitation today. It means that DOS cannot use present day
large disks.
The 528 MB limit
If the same values for c,h,s are used for the BIOS Int 13 call
and for the IDE disk I/O, then both limitations combine, and one
can use at most 1024 cylinders, 16 heads, 63 sectors/track, for
a maximum total capacity of 528482304 bytes (528MB), the
infamous 504 MiB limit for DOS with an old BIOS. This started
being a problem around 1993, and people resorted to all kinds of
trickery, both in hardware (LBA), in firmware (translating
BIOS), and in software (disk managers). The concept of
`translation' was invented (1994): a BIOS could use one geometry
while talking to the drive, and another, fake, geometry while
talking to DOS, and translate between the two.
The 2.1 GB limit (April 1996)
Some older BIOSes only allocate 12 bits for the field in CMOS
RAM that gives the number of cylinders. Consequently, this
number can be at most 4095, and only 4095*16*63*512=2113413120
bytes are accessible. The effect of having a larger disk would
be a hang at boot time. This made disks with geometry
4092/16/63 rather popular. And still today many large disk
drives come with a jumper to make them appear 4092/16/63. See
also over2gb.htm. Other BIOSes would not hang but just detect a
much smaller disk, like 429 MB instead of 2.5 GB.
The 3.2 GB limit
There was a bug in the Phoenix 4.03 and 4.04 BIOS firmware that
would cause the system to lock up in the CMOS setup for drives
with a capacity over 3277 MB. See over3gb.htm.
The 4.2 GB limit (Feb 1997)
Simple BIOS translation (ECHS=Extended CHS, sometimes called
`Large disk support' or just `Large') works by repeatedly
doubling the number of heads and halving the number of cylinders
shown to DOS, until the number of cylinders is at most 1024.
Now DOS and Windows 95 cannot handle 256 heads, and in the
common case that the disk reports 16 heads, this means that this
simple mechanism only works up to 8192*16*63*512=4227858432
bytes (with a fake geometry with 1024 cylinders, 128 heads, 63
sectors/track). Note that ECHS does not change the number of
sectors per track, so if that is not 63, the limit will be
lower. See over4gb.htm.
The 7.9 GB limit
Slightly smarter BIOSes avoid the previous problem by first
adjusting the number of heads to 15 (`revised ECHS'), so that a
fake geometry with 240 heads can be obtained, good for
1024*240*63*512=7927234560 bytes.
The 8.4 GB limit
Finally, if the BIOS does all it can to make this translation a
success, and uses 255 heads and 63 sectors/track (`assisted LBA'
or just `LBA') it may reach 1024*255*63*512=8422686720 bytes,
slightly less than the earlier 8.5 GB limit because the
geometries with 256 heads must be avoided. (This translation
will use for the number of heads the first value H in the
sequence 16, 32, 64, 128, 255 for which the total disk capacity
fits in 1024*H*63*512, and then computes the number of cylinders
C as total capacity divided by (H*63*512).)
The 33.8 GB limit (August 1999)
The next hurdle comes with a size over 33.8 GB. The problem is
that with the default 16 heads and 63 sectors/track this
corresponds to a number of cylinders of more than 65535, which
does not fit into a short. Many BIOSes couldn't handle such
disks. (See, e.g., Asus upgrades for new flash images that
work.) Linux kernels older than 2.2.14 / 2.3.21 need a patch.
See ``IDE problems with 34+ GB disks'' below.
The 137 GB limit (Sept 2001)
As mentioned above, the old ATA protocol uses 16+4+8 = 28 bits
to specify the sector number, and hence cannot address more than
2^28 sectors. ATA-6 describes an extension that allows the
addressing of 2^48 sectors, a million times as much. There is
support in very recent kernels.
The 2 TiB limit
With 32-bit sector numbers, one can address 2 TiB. A lot of
software will have to be rewritten once disks get larger.
Hard drives over 8.4 GB are supposed to report their geometry as
16383/16/63. This in effect means that the `geometry' is obsolete,
and the total disk size can no longer be computed from the geometry,
but is found in the LBA capacity field returned by the ``IDENTIFY
command''. Hard drives over 137.4 GB are supposed to report an LBA
capacity of 0xfffffff = 268435455 sectors (137438952960 bytes). Now
the actual disk size is found in the new 48-capacity field. |