How to prevent /sda /sdb changes between boots

block-devicedevicesgentoohard-diskudev

I am going to install Gentoo Linux onto an old hardware, which motherboard is having both IDE and SATA hard drives. I have two IDE and one SATA hard drives connected, and plan to do RAID on them.

However I notice a problem: the hard drive mapped to /dev/sda changes on every boot!

I was searching for answers from the Internet. And I found Persistent Device Names could be a solution. However I am worrying about will it run into compatibility problems system wide? In addition, it is quite inconvenient (because the names are quite long) unless I can use /dev/disk/by-label. But it seems by-label cannot refer to /dev/sda and /dev/sdb – only /dev/sda1 is possible. Moreover, for my old hardware that uses BIOS, I think I can only use MBR, but not GPT. How to change the disk labels in the MBR environment?

On the other hand, the ideal solution in my mind would be, the /dev/sda is mapped to the same hard disk in every boot. Imaginary, this can be achieved by saving a file named "bootmap" on the hard disk. And "/sda" is written in the "bootmap" file. While the system boot, if it finds "/sda" inside "bootmap", the drive is mapped to /dev/sda. If it finds "/sdb", it maps to /dev/sdb. And so on. (But I know it is probably not so ideal.)

So, how to avoid the mapping of /dev/sda changes from boot to boot?

As an alternative, way to edit the label would be nice too. – given that it won't get a compatibility issue anywhere.

(PS – either ways, there is not a solution on the Internet yet.)

Best Answer

Most filesystems have unique UUIDs and have labels which you can set to a distinctive values. These allow you to refer to the volume containing the filesystem through /dev/disk/by-uuid or /dev/disk/by-label. Other types of volumes (RAID, LVM, etc.) generally have a name as well. RAID and LVM volumes are assembled based on unique identifiers in the physical volumes, regardless of how the volume is connected. So it's unusual to need to refer to a disk as such.

If you really need to access a disk based on the way it's connected, you can use /dev/disk/by-id. Entries there are of the form BUS-SERIAL or BUS-NAME-SERIAL. All the /dev/disk/ subdirectories are maintained by udev, by the way, specifically the persistent storage rules.

Another solution is to create your own symbolic links under /dev. You can write udev rules to do this. Add a file /etc/udev/rules.d/50-local-persistent-disks.rules containing rules like

SUBSYSTEM=="block", ATTRS{model}=="Yoyodine HD9001", \
  ATTRS{serial}=="123-456-789", \
  SYMLINK+="myfancyname"

Run udevadm info -a /dev/sda to see what …==… patterns you can use. If you use multiple patterns, they have to be from the same output block, you can't mix patterns from different parent devices.

Related Question