[TriLUG] Grub question

Rick DeNatale rick.denatale at gmail.com
Sat Feb 18 16:49:38 EST 2006


>From what I've been able to discern, the device.map file is only used
by the grub COMMAND which is a version of the grub shell run from a
running system.

If I'm deciphering the docs correctly, the grub command (/sbin/grub on
my system) is actually a simulation of the grub shell which runs at
boot time (i.e. stage1). During stage1 boot the grub shell only has
bios to talk to the drives and works with bios hard drive numbers. The
mapping of these numbers to actual drives depends on how the bios is
configured (i.e. the drive boot order), and is not affected by the
drive type (IDE or SCSI).  When running under, say linux, grub
apparently goes through the kernel drivers so it needs to map a grub
drive specification in the form of  (HDn[,p]) to a device path like
/dev/{s|h}dmq?  where s|h depends on whether it's an IDE or SCSI
drive, m is the letter cooresponding to the particular IDE or SCSI
drive, and q is the partition number which is mapped from grubs
partition number p, which is zero-origin instead of the one-origin
number used by the kernel, with logical partition numbering starting
with 4.

So here's an experiment.

$sudo grub
Probing devices to guess BIOS drives. This may take a long time.

    GNU GRUB  version 0.95  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename. ]
grub>root (hd0,0)
grub> root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83

grub> kernel /v[tab]
Error 15: File not found
grub> root (hd2,0)
 Filesystem type is ext2fs, partition type 0x83

grub> kernel /v[tab][tab]
 Possible files are: vmlinuz-2.6.12-9-386 vmlinuz-2.6.12-10-386
vmlinuz-2.6.12-10-686-smp

grub> quit

So if I leave grub running UNDER linux to figure out the mapping, it
gets it wrong. Clearly since all of the stanzas in my
/boot/grub/menu.lst file are using (hd0,0) and it's successfully
booting off /dev/sda1 the mapping is not the same as at boot time.

Now, if I edit /boot/grub/device.map to look like this:
(hd0)   /dev/sda
(hd1)   /dev/sdb
(hd2)   /dev/hdc
(hd3)   /dev/hdd

and then
$sudo grub --device-map=/boot/grub/device.map

    GNU GRUB  version 0.95  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename. ]

grub> root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83

grub> kernel /v[TAB][TAB]
 Possible files are: vmlinuz-2.6.12-9-386 vmlinuz-2.6.12-10-386
vmlinuz-2.6.12-10-686-smp

grub> quit

Now, (hd0,0) does map to my first scsi drive.  Notice also the grub
doesn't probe the devices to guess the BIOS drives.

The grub-install command is actually a shell script which goes through
various gyrations to map things. Seeing how tricky this is, I can see
why the grub documentation recommends against using this script
http://www.gnu.org/software/grub/manual/grub.html#Installing-GRUB-using-grub_002dinstall



More information about the TriLUG mailing list