Mounting Linux software raid using a consistent device name

It’s recommended these days to use the UUID of a mdadm based raid partition in your fstab.  This is fine for a single server but if you have dozens of identical servers, it’s a pain to have to maintain different fstabs for each server.

Ideally you want your fstab to contain something like

/dev/md/data     /data    ext3    defaults 0 2

Rather than this:

UUID=550e8400-e29b-41d4-a716-446655440000     /data    ext3    defaults 0 2

The trick here is to set a name and a homehost for your mdadm array (you will need version 1.2 RAID metadata). The RAID array will still use the UUID to identify members of the array and the array will still be mounted as /dev/mdXXX however a link to this mount point will be made under /dev/md/ and it will be named the same as the name of the array.  If you don’t explicitly set the array’s homehost to “<none>” then the host name of the server setting the array name will be preprended to the name of the array which defeats the point of what we’re trying to do (identical fstabs across multiple servers).

You can set a name for the RAID array by stopping it and them reassembling is as follows:

mdadm --stop /dev/mdXXX
mdadm --assemble /dev/md0 /dev/sd[a-z] --update=name --name=data --homehost="<none>"

Replace /dev/sd[a-z] with the appropriate disks or partitions that make up your array.

The last thing you need to do is change your mdadm.conf HOMEHOST setting to <ignore>. If you do not change this then mdadm on boot will mount your array as /dev/md/name_0 because the homehost of the array is empty and does not match the name of the mounting server. By adding this option, the integer suffix will only be appended if there are multiple arrays on the system with the same name.

# /etc/mdadm/madm.conf
HOMEHOST <ignore>

Make sure you run update-initramfs after you change mdadm.conf.

Leave a Reply

Your email address will not be published.