MD device name changing to include "HOSTNAME:" after first reboot. How do I get a consistent name?

How do I get a consistent device path for my MD device, ideally the exact one I specified ("/dev/md/myarray")?

After mdadm --create /dev/md/foobar ..., both hostname and name are stored in the mdadm metadata, as you should verify with mdadm --examine or mdadm --detail:

# mdadm --detail /dev/md/foobar
           Name : ALU:foobar  (local to host ALU)

ALU happens to be the hostname of my ArchLinux machine:

# hostname
ALU

You can specify the host that should be stored at create time:

# mdadm --create /dev/md/foobar --homehost=barfoo
# mdadm --detail /dev/md/foobar
               Name : barfoo:foobar

...but usually nobody remembers to do that.


And that's already where the problems start... you might have created your RAID array from some LiveCD or other, and the hostname in that environment didn't match your main install at all. And then the metadata stores some completely unrelated hostname.

Similarly if you set everything up correctly, but then encounter problems with your RAID and boot a rescue system to check things out, yet again there's a mismatch with the hostnames.

Or the other way around, the hostname may match even if it's the wrong machine - if you used the same hostname for two independent systems and then migrate drives. Then the alien arrays take over the names of the original ones...


Now, the metadata can also be changed later using mdadm --assemble --update=homehost or --update=name, that is one way to deal with problem. It should be set correctly but it's difficult to change as (for some reason) short of hexediting metadata directly, it can only be done at assembly time.

Another way is to ignore the systems hostname and instead specify --homehost on assembly or set HOMEHOST in mdadm.conf. This is described in some detail in the mdadm.conf manpage.

HOMEHOST
The homehost line gives a default value for the --homehost= option to mdadm. There should normally be only one other word on the line. It should either be a host name, or one of the special words <system>, <none> and <ignore>. If <system> is given, then the gethostname(2) systemcall is used to get the host name. This is the default.
[...]
When arrays are created, this host name will be stored in the metadata. When arrays are assembled using auto-assembly, arrays which do not record the correct homehost name in their metadata will be assembled using a "foreign" name. A "foreign" name alway ends with a digit string preceded by an underscore to differentiate it from any possible local name. e.g. /dev/md/1_1 or /dev/md/home_0.

So you can try to set HOMEHOST ALU (in my case), or the more generic HOMEHOST <ignore> (or HOMEHOST <none>) in the mdadm.conf. But it will only work when that mdadm.conf is present. And again if you set ignore and then hook up an array from another machine, you might run into name conflicts.

So it'd be best to set the hostname correctly in metadata and mdadm.conf and not ignore it, and better yet set the actual hostname in initramfs before assembly but it can be hard to put into practice.

My personal preference is to just stick to the classic numeric style. Identify by UUID and nothing else:

ARRAY /dev/md1 UUID=8fe790ca:f3fa3388:4ae125b6:2c3a5d44
ARRAY /dev/md2 UUID=f14bef5b:a5356e51:25fde128:09983091
ARRAY /dev/md3 UUID=0639c68d:4c844bb1:5c02b33e:00ab4a93

This is also consistent (but also depends on it to have been created this way and/or set accordingly in the metadata, otherwise you also might have to --update it). And alien arrays that don't match the given UUIDs should end up as /dev/md127+.


At the end of the day no matter what you do, you should not blindly rely on /dev/mdX or /dev/md/names the same way you don't blindly rely on /dev/sdX letters. Always use filesystem UUIDs to identify whatever is on those arrays.

There's too many corner cases where names might unexpectedly change, so at best, this can be an orientation help or hint to the sysadmin, it's not the answer to all problems.

Tags:

Linux

Mdadm

Md