Wednesday, December 30, 2015

Ubuntu and software RAID, getting a device path that won't change from boot to boot

While I love mdadm (software RAID), it's perplexing me at the moment as it keeps changing its device number under Ubuntu.  When I created the array, I created it as "md100", but whenever I restart it ends up as "md127" (and could end up as something else!).  Normally, this doesn't matter, but I'm doing LVM on LUKS, so I need a static (unchanging) path to the array device.

This is a (4) disk array, running mdadm's raid10, and was created with the command:

$ sudo mdadm --create /dev/md100 --raid-devices=3 --spare-devices=1 --level=raid10 /dev/sd[bcde]1

After creating the array, I can check the details with:

$ sudo mdadm --detail --scan /dev/md100

ARRAY /dev/md127 metadata=1.2 spares=1 name=freya:100 UUID=deafbeef:deadbeef:beafdeff:beaffffa

Notice the "name=freya:100".  That's the key to finding a static path to the array.  If I then look under the /dev/md directory, I will see:

$ ls -l /dev/md
total 0
lrwxrwxrwx 1 root root 8 Dec 30 08:15 freya:100 -> ../md127

That means the static path to this array is "/dev/md/freya\:100" and I can use LUKS format on it with:

$ sudo cryptsetup -y -v luksFormat /dev/md/freya\:100

Alternate, I can search for the UUID in the /dev directory and find:

$ sudo find /dev -name '*deafbeef*'

I can then add a LUKS keyfile to the device and unlock the device at boot by listing it in the /etc/crypttab file.  Either path will work, but the colons (:) will likely have to be escaped in /etc/crypttab.

PS: Yes I've tried putting the array line in the /etc/mdadm/mdadm.conf file as just "ARRAY /dev/md100 UUID=deafbeef:deadbeef:beafdeff:beaffffa", which is supposed to fix the issue.

PS #2: It's interesting that the mdadm UUID appears in /dev/disk/by-id and not /dev/disk/by-uuid.

No comments: