Maybe it's an XY Problem, so here's a full situation:
We have lots of servers now which will be used as storage/databases. All of them have similar setup: SSD drive for OS (Ubuntu 18.04.2 LTS) and 6 HDDs as JBODs. These six drives need to be grouped into RAID-10 array via mdadm.

I took 6 servers and manually installed Ubuntu, using server ISO, not live-server one (without Cloud-Init). During the install and after booting I noticed that "system" partition is named as /dev/sda on some servers and /dev/sdg on others. In this case I cannot run mdadm command via some script with xCat, Ansible and other "automation" utilities to create RAID array automatically.

I installed Ubuntu in "Legacy" mode and those 6 HDDs have MBR partitioning scheme, so they don't have UUID when I run ls -l /dev/disk/by-uuid. I noticed that udev might be helpful, but it still requires human's work to write rules for selected server and running it, so it might be better not to do this and manually a create a RAID instead. But we're going to have 100+ servers overall and I'm willing to automate this routine as much as possible. Any ideas?

  • 1
    If your system supports ZFS and GPT labels, consider using ZFS instead of RAID. Then this problem goes away. – Jim L. Aug 1 '19 at 23:09
  • Thank you for suggestion! Unfortunately, this is not an option for me – Groosha Aug 2 '19 at 8:26
  • What about using /dev/disk/by-label? – Emmanuel Rosa Aug 5 '19 at 9:44

It has been documented kernel behaviour for many years now that you can not rely on consistent device naming for drives even across reboots on the same server, let alone on different servers.

You will have to write your auto-RAID setup script to detect which drives are in the system and distinguish between the root SSD and the storage JBOD drives.

One obvious way to detect the root drive is to run mount | grep " on / ".

Otherwise, you can use /dev/disk/by-id/, which is a symlink farm populated by udev. Each entry is a symlink with a name based on the drive's manufacturer and serial number, with the symlinks pointing to the block devices for the drives (and partitions, if any). e.g. on one of my systems, /dev/disk/by-id contains:

lrwxrwxrwx 1 root root  9 Jul 24 16:56 ata-ST2000DL003-9VT166_5YD1QFAG -> ../../sdb
lrwxrwxrwx 1 root root 10 Jul 24 16:56 ata-ST2000DL003-9VT166_5YD1QFAG-part1 -> ../../sdb1
lrwxrwxrwx 1 root root 10 Jul 24 16:56 ata-ST2000DL003-9VT166_5YD1QFAG-part9 -> ../../sdb9
lrwxrwxrwx 1 root root  9 Jul 24 16:56 ata-WDC_WD20EARS-00MVWB0_WD-WCAZA5353040 -> ../../sdd
lrwxrwxrwx 1 root root 10 Jul 24 16:56 ata-WDC_WD20EARS-00MVWB0_WD-WCAZA5353040-part1 -> ../../sdd1
lrwxrwxrwx 1 root root 10 Jul 24 16:56 ata-WDC_WD20EARS-00MVWB0_WD-WCAZA5353040-part9 -> ../../sdd9
lrwxrwxrwx 1 root root  9 Jul 24 16:56 ata-WDC_WD20EARS-00MVWB0_WD-WCAZA5379164 -> ../../sdc
lrwxrwxrwx 1 root root 10 Jul 24 16:56 ata-WDC_WD20EARS-00MVWB0_WD-WCAZA5379164-part1 -> ../../sdc1
lrwxrwxrwx 1 root root 10 Jul 24 16:56 ata-WDC_WD20EARS-00MVWB0_WD-WCAZA5379164-part9 -> ../../sdc9
lrwxrwxrwx 1 root root  9 Jul 24 16:56 ata-WDC_WD20EARX-008FB0_WD-WCAZAJ827116 -> ../../sda
lrwxrwxrwx 1 root root 10 Jul 24 16:56 ata-WDC_WD20EARX-008FB0_WD-WCAZAJ827116-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Jul 24 16:56 ata-WDC_WD20EARX-008FB0_WD-WCAZAJ827116-part9 -> ../../sda9

That's one Seagate 2TB drive, and three WD 2TB drives, each with two partitions (partitions 1 and 9 - and yes, they're used for a zfs pool).

If your script created a single partition on each RAID drive (highly recommended), and used that partition instead of the entire drive, it would be easy to identify drives which are already in use (i.e. have a partition) and those which are not (and thus may safely used in a raid array).

There will almost certainly be device names beginning with wwn- in that directory as well. These are the World Wide Name identifiers belonging to each drive. I find them less useful than the vendor+serial number names because they don't provide any obvious way to physically identify the drives without using a lookup table to translate OUI codes to manufacturers.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.