What does all of this mean? For Linux users only one thing:
that they must make sure that LILO and fdisk
use the right
geometry where `right' is defined for fdisk
as the geometry
used by the other operating systems on the same disk, and for
LILO as the geometry that will enable successful interaction
with the BIOS at boot time. (Usually these two coincide.)
How does fdisk
know about the geometry?
It asks the kernel, using the HDIO_GETGEO
ioctl.
But the user can override the geometry interactively
or on the command line.
How does LILO know about the geometry?
It asks the kernel, using the HDIO_GETGEO
ioctl.
But the user can override the geometry using the `disk=
' option
in /etc/lilo.conf
(see lilo.conf(5)).
One may also give the linear
option to LILO, and it will store
LBA addresses instead of CHS addresses in its map file,
and find out of the geometry to use at boot time (by using
INT 13 Function 8 to ask for the drive geometry).
How does the kernel know what to answer?
Well, first of all, the user may have specified an explicit geometry
with a `hda=
cyls,
heads,
secs'
kernel command line option (see bootparam(7)), perhaps by hand, or by
asking the boot loader to supply such an option to the kernel.
For example, one can tell LILO to supply such an option by adding
an `append = "hda=
cyls,
heads,
secs"
'
line in /etc/lilo.conf
(see lilo.conf(5)).
And otherwise the kernel will guess, possibly using values
obtained from the BIOS or the hardware.
It is possible (since Linux 2.1.79) to change the kernel's ideas
about the geometry by using the /proc
filesystem.
For example
# sfdisk -g /dev/hdc
/dev/hdc: 4441 cylinders, 255 heads, 63 sectors/track
# cd /proc/ide/ide1/hdc
# echo bios_cyl:17418 bios_head:128 bios_sect:32 > settings
# sfdisk -g /dev/hdc
/dev/hdc: 17418 cylinders, 128 heads, 32 sectors/track
#
Sometimes it is useful to force a certain geometry
by adding `hda=
cyls,
heads,
secs'
on the kernel command line. Almost always one wants secs=63,
and the purpose of adding this is to specify heads.
(Reasonable values today are heads=16 and heads=255.)
What should one specify for cyls? Precisely that number
that will give the right total capacity of C*H*S sectors.
For example, for a drive with 71346240 sectors (36529274880 bytes)
one would compute C as 71346240/(255*63)=4441 (for example using
the program bc
), and give boot parameter hdc=4441,255,63
.
How does one know the right total capacity? For example,
# hdparm -g /dev/hdc | grep sectors
geometry = 4441/255/63, sectors = 71346240, start = 0
# hdparm -i /dev/hdc | grep LBAsects
CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=71346240
gives two ways of finding the total number of sectors 71346240.
The kernel output
# dmesg | grep hdc
...
hdc: Maxtor 93652U8, 34837MB w/2048kB Cache, CHS=70780/16/63
hdc: [PTBL] [4441/255/63] hdc1 hdc2 hdc3! hdc4 < hdc5 > ...
tells us about (at least) 34837*2048=71346176 and about (at least)
70780*16*63=71346240 sectors. In this case the second value happens
to be precisely correct, but in general both may be rounded down.
This is a good way to approximate the disk size when hdparm
is unavailable. Never give a too large value for cyls!
In the case of SCSI disks the precise number of sectors is given
in the kernel boot messages:
SCSI device sda: hdwr sector= 512 bytes. Sectors= 17755792 [8669 MB] [8.7 GB]
(and MB, GB are rounded, not rounded down, and `binary').