[H-GEN] Changing IDE HDD Controller Drama

Russell Stuart russell-humbug at stuart.id.au
Tue Mar 22 20:37:57 EST 2005


On Tue, 2005-03-22 at 23:11, De Crow wrote:
> Ok guys here's a screwy one for you all.
> 
> I have a FileServer with 7 IDE HDDs in it, and one CDROM
> 
> ....
> 
> Any ideas on how to fix this?  BIOS still lists the drives in the same
> order, not this new order, so I'm thinking that it's a Linux/GRUB or
> something glitch?

My take on this is to attack the problem with Grub.  As a
rule of thumb, unless there is a good reason not to, I install
Grub into the Master Boot Record of all disk drives on the
machine.  This means the thing will always boot, and Grub's
command prompt is powerful enough to take it from there.

Within Grub there is a translation table that says in effect:

  What Linux calls /dev/hdc the BIOS calls hd0.

If you have any experience with BIOS calls, grub translates the
hd0 in "root (hd0,0)" to a 0x8x number which is passed to the
raw BIOS I/O functions.  In the BIOS, drives are identified by
a single byte.  Floppies are A:=0x00, B:=0x01, etc.  HDD's have
the MSB set, and so the DOS C: is always on HDD 0x80.  Thus
when grub sees a disk drive spec of the form (hdN,0), it
translates this to the drive number (0x80 + N), which it
passed to the BIOS.

Grub has to do this translation, because when it boots it must
use BIOS calls, but when it is running under Linux is must use
Linux's device drivers.

This mapping can be set in one of two ways: in a config file,
typically /boot/grub/device.map, or via the grub shell command
prompt using the "device" command.  Here is the contents of a
standard device.map file:

  (fd0)   /dev/fd0
  (hd0)   /dev/hda

Here is the contents of a not so standard one, with hardware
Raid and what not:

  (fd0)   /dev/fd0
  (hd0)   /dev/sda
  (hd1)   /dev/sdb

In this system /dev/sda is actually a Raid array, which the BIOS
sees as the master on the primary IDE controller, and /dev/sdb 
is the slave on the primary IDE controller.  Of course they aren't
IDE drives at all - they are SCSI drives.  Its is only the Raid
BIOS that makes the motherboard BIOS think they are.

I don't as a rule change the hardware / BIOS settings to
accommodate the software.  Many machine I administer are 1000's
of km's away, and BIOS settings have a nasty habit of being
reset to the default.

OK, so much for the theory.  In practise this means you have to
figure out what your BIOS sees the drives as, and what devices
Linux sees them as.  I think you have already done that.

The next step is to boot off a install CD - Debian will be fine,
start a shell, create a device.map file like that ones above,
and run grub like this:

  grub --device-map=my-device.map
  > root (hdX,Y)

Here hdX is in fact hd0, or some such, and there will be a line
of the form:

  (hdX)  /dev/sdA

in your device.map.  /dev/sdA is where your kernel images and grub
boot sectors live: typically the drive that holds /boot.  The X
(0, 1, 2, etc) is determined by how the BIOS sees that drive, ie
0 for primary IDE master, 1 for primary IDE slave, 2 for secondary
IDE master, 3 for secondary IDE slave, and so on.

>From there installing grub into the MBR's involves typing one of
these commands for each MBR:

  setup (hdZ)

Again, the Z in (hdZ) is one of 0, 1, 2, etc, and depends on what
the BIOS calls the drive.  And of course there must be a line in
my-device.map which tells Grub what Linux calls the device, like
this:

  (hd4)  /dev/hdc

If you booted your machine Grub should load at this point.  The
final steps are to put the Linux boot drive onto the kernel
command line, and into fstab, which you accomplish by editing
/boot/grub/menu.lst, and /etc/fstab.







More information about the General mailing list