Using GRUB to figure out the mapping of BIOS drive numbers
Suppose you have a piece of hardware where the mapping between BIOS drive numbers and Linux device names is not straightforward, and you want to figure out just what the mapping is (at least for your current disks). If you use GRUB (and you probably do), there's a relatively simple way of doing this.
GRUB has two important attributes for this: it can read Linux filesystems and tell you what's in them, and at boot time it is working with the BIOS drive numbering. So the basic approach is to plant unique flag files in filesystems on each drive, reboot your system, break into the GRUB shell, and use GRUB commands to find out what flag file is on each BIOS disk number.
(Okay, there's an important qualifier to this: this is the BIOS boot order, not the actual labels that the BIOS and the motherboard use. It is possible to have the BIOS perturb the boot order from the label order, so that 'SATA 3' is the boot drive, not 'SATA 1'.)
GRUB doesn't have an explicit
ls command or the like, but what it does
have is filename autocompletion. So the basic way to look for the flag
file on each partition is something like the following commands:
This will helpfully tell you which 'FLAG-*' file is on partition Y of BIOS disk number X (numbering from 0). You can repeat this sequence for each BIOS disk number that you have.
(You will probably have to break out of the usual GRUB menu into GRUB's command mode during booting. As far as I know there's no way back to menu mode, so just reboot the machine afterwards.)
Depending on your configuration, getting a unique flag file onto a
simple filesystem in a simple partition on each disk may be either
trivial or very complex (this is one situation where a mirrored
/boot is a drawback). GRUB needs a whole
filesystem of a type that it can read (ext2, ext3, and some others); it
can't read things inside LVM, software RAID-5, and so on.
If you don't already have such a set of filesystems, here's some suggestions:
- if you have a mirrored
/boot, consider deliberately breaking the mirror apart temporarily.
- if you have swap partitions, you can turn off swapping to them and
reuse them for filesystems. (If they're mirrored, you can break
the mirroring too.)
- if your disks have different numbers of partitions, you may not
need a flag file at all; you can use GRUB's
rootcommand by itself to see what partitions are defined on each drive.
(But then, if you have a different number of partitions on each drive you probably have single partition filesystems that GRUB can read.)
In my case, it turned out that ASUS M4N2-SLI motherboards invert the
order of the first pair of SATA channels relative to the last two;
SATA 1 and 2 were
sdd in Linux, and SATA 3 and 4 were
sdb (at least in Fedora 8; later kernels may have changed this). Then
I had extra fun because the BIOS boot order had gotten perturbed to
something like 2, 3, 1, 4.