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.)

  • sudo e2label /dev/sdb1 "mydiskname" - seen on ubuntuforums.org/showthread.php?t=1113236
    – Yaron
    May 5, 2016 at 14:37
  • Thanks for reply. I have successfully changed the label by ntfslabel as it was from a Windows drive. Can "by-label" by used system wide? What if in some cases I need to specify /dev/sda?
    – midnite
    May 5, 2016 at 17:34

3 Answers 3


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", \

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.

  • Thanks for reply and pointing me to the direction of writing udev rules. I am studying on Writing udev Rules. It seems it is possible to swap /dev/sda with /dev/sdb even after system start up. It's quite magical.
    – midnite
    May 6, 2016 at 7:18
  • I am not sure if it is a typo that they should be ATTRS{model}=="..." and ATTRS{serial}=="...".
    – midnite
    May 6, 2016 at 7:49
  • Please help on this. In the webpage linked in my first comment, it teaches us to change /dev/sdb to /dev/my_spare_disk by KERNEL=="hdb", NAME="my_spare_disk". I created the rule KERNEL=="sd?", ATTRS{model}=="TOSHIBA MK1034GS", NAME="sdz" and did udevadm test /block/sda. But I am getting kernel device nodes can not be renamed. I guess @ibre5041 mentioned we can no longer change the /dev/sd* in the last comment here. Would you please confirm? Any workaround?
    – midnite
    May 6, 2016 at 17:21
  • It's so weird and I just notice that I can simply mv sda sdz! Inspired by here. Magic - and I didn't know it's such simple....
    – midnite
    May 6, 2016 at 19:01
  • @midnite Oh, right, you can't rename disks. Use a symlink then. May 7, 2016 at 10:48

I think you can safely use the /dev/disk/by-id/ links that are bound only to the disk type/model:

lrwxrwxrwx 1 root root   9 Jul 14 15:13 ata-Hitachi_HDS123456789_PVC1234567890 -> ../../sda

Unlikely the /dev/disk/by-path can chance with the controller:

lrwxrwxrwx 1 root root   9 Jul 14 15:13 pci-0000:00:1f.2-ata-2 -> ../../sda
lrwxrwxrwx 1 root root  10 Jul 14 15:13 pci-0000:00:1f.2-ata-2-part1 -> ../../sda1
lrwxrwxrwx 1 root root  11 Jul 14 15:40 pci-0000:00:1f.2-ata-2-part10 -> ../../sda10
lrwxrwxrwx 1 root root  11 Jul 14 15:43 pci-0000:00:1f.2-ata-2-part11 -> ../../sda11
lrwxrwxrwx 1 root root  11 Jul 14 15:13 pci-0000:00:1f.2-ata-2-part12 -> ../../sda12

In my case I fixed it by mounting the /dev/sdb (extra HDD) within my home directory (example:- /home/username/Data). But if I mount the /dev/sdb inside /mnt it swap sda & sdb every time I reboot the computer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .