# SATA drive order

## dalai

I recently added a new SATA drive and I have a problem with their order changing when the kernel loads.

First SATA: ST320 (this is the new)

Second SATA: WD120

Third SATA: WD80 (this is the old boot drive)

Without changing anything in the BIOS boot order, my system loads grub from ST320 and then grub loads the kernel from (hd0) which still corresponds to ST320. While the kernel boots, it recognises WD80 as sda, ST320 as sdb and WD120 as sdc and from that point on ST320 is (hd1)! Since I told grub that root is in /dev/sda1 which has become /dev/sdb1 it fails.

The same happens if I boot from the liveCD - ST320 is hd1 instead of hd0 in grub and sdb instead of sda in /dev. I've tried to remove grub from WD80 and make the first partition inactive from fdisk but nothing changed. As long as it is plugged in the kernel sees it as sda, despite the fact that in the BIOS it is third.

I've managed to work around it by unplugging WD80 (and I could also change the root to /dev/sdb1 in grub and my /etc/fstab accordingly) but I was wondering if anyone has some insight as to why this happens.

My grub.conf

```

#splash image

splashimage=(hd0,0)/boot/grub/splash.xpm.gz

# Boot automatically after 30 secs.

timeout 10

# By default, boot the first entry.

default 0

# Fallback to the second entry.

fallback 1

# Gentoo

title  Gentoo Linux

root (hd0,0)

kernel /boot/gentoo root=/dev/sda1 vga=794,mtrr,ywrap splash=verbose

initrd /boot/fbsplash

```

The device.map file shows this:

```

(fd0)   /dev/fd0

(hd0)   /dev/sda

(hd1)   /dev/sdb

(hd2)   /dev/sdc
```

The motherboard is an ASUS A8N-E

----------

## eccerr0r

Are all these controllers all on-board, and all true SATA disks (and no libata PATAs)?

Is the BIOS detection order the same as what (hd0) upon boot?

Usually linux kernel differs from BIOS because the kernel detection order is different from BIOS detection method, and thus the disks get assigned differently.  This is unlike old PATA/IDE drivers since there's pretty much only one way/order to detect them.  It's a similar issue to multiple ethernet on PCI enumeration.

I ended up just doing /dev/sdb1 in grub on my PATA/SATA issue (which does match detection order, PATA ends up with the /dev/sda but my root disk is on SATA or /dev/sdb), though the "clean" way to do it is use a initrd to specify root by label, and have all disks labeled differently.

----------

## burzmali

dalai,

have you had any more luck with this?  I just added a third sata drive to my a8n-e and I am having the same problem!  grub seems to detect the drives in the same order as they show in the bios (since it finds the kernel located in (hd1,0)), but after the kernel starts sda and sdb move to sdb and sdc respectively while boot time sdc becomes sda.

M/B position of sata cables:

bios:

```

 sdd         sdc 

 sdb         sda

```

kernel:

```

 sdb         sda 

 sdd         sdc

```

it seems the kernel flips the two rows.

my system kernel is 2.6.23-gentoo-r3 and I am posting this from kubuntu livecd (which also exhibits the problem) running 2.6.22-14-generic

I guess maybe i should look at labelling my drives, but i have never done that before.

----------

## burzmali

interestingly enough, windows also swaps the drive around after booting!  but it does boot.  I tried my hand at labeling my partitions, and I thought I had it but no.  anyone got any pointers?

----------

## jburns

 *burzmali wrote:*   

> grub seems to detect the drives in the same order as they show in the bios

  Grub references to drives are based on the order as shown in the bios.

For how to reference the partitions by UUID number see https://forums.gentoo.org/viewtopic-t-627464-highlight-uuid.html

----------

## burzmali

I got it all working now using intird from genkernel.

thanks for the help!

----------

