19

On newer systems /usr/share/mdadm/mkconf (the script that is used to generate /etc/mdadm/mdadm.conf) tends to use the device name /dev/md/0 instead of /dev/md0:

new-system ~ # /usr/share/mdadm/mkconf | grep ARRAY
ARRAY /dev/md/0 metadata=1.2 UUID=a0021927:0e4f10bf:2c47dc72:ca0b352e name=unassigned:0

This may cause some irritation for users who expect /dev/md0 there, but apparently it works fine because the server boots without problems.

In /proc/mdstat the device is still called /dev/md0:

new-system ~ # cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb2[2] sda2[0]
      1953381184 blocks super 1.2 [2/2] [UU]

unused devices: <none>

ls shows that /dev/md/0 is a symlink to /dev/md0:

new-system ~ # ls -l /dev/md/0 
lrwxrwxrwx 1 root root 6 Nov 20 14:06 /dev/md/0 -> ../md0

On another older system mkconf still uses /dev/md0 instead, and /dev/md is empty:

old-system ~ # /usr/share/mdadm/mkconf | grep ARRAY
ARRAY /dev/md0 UUID=76472cf5:83fd8e5a:ad617046:69b2ebf1
old-system ~ # ls -l /dev/md
total 0

I'd like to know the difference between these device names, and I can't find any explanation on Google. Is /dev/mdN the old name, and md is planning to move to /dev/md/N device names? Is this change related to the 1.2 metadata (I've noticed that the new server is using md 1.2, while the old one is still using 0.90)?


EDIT 2017-09-11: I think Krzysztof Stasiak's answer is the correct one. I had by now totally forgotten about this question. While playing with a test RAID last friday I thought "why not name my array instead of memorizing what md0, md1, md2, ... etc. does in complex setups?", and so I tried:

test-server ~ # mdadm --assemble /dev/mdfoobar /dev/loop[01]
mdadm: /dev/mdfoobar is an invalid name for an md device.  Try /dev/md/mdfoobar

And indeed that works:

test-server ~ # mdadm --assemble /dev/md/foobar /dev/loop[01]
mdadm: /dev/md/foobar has been started with 2 drives.

test-server ~ # ll /dev/md/foobar 
lrwxrwxrwx 1 root root 6 Sep 11 10:45 /dev/md/foobar -> ../md0

test-server ~ # cat /proc/mdstat 
Personalities : [raid1]
md0 : active (auto-read-only) raid1 loop0[0] loop1[1]
      102272 blocks super 1.2 [2/2] [UU]

unused devices: <none>

(You can also do mdadm --assemble foobar DEV...).

There's a detailed explanation in man mdadm, section DEVICE NAMES.

Martin von Wittich
  • 13,857
  • 6
  • 51
  • 74
  • 2
    https://lkml.org/lkml/2002/11/19/342 – frostschutz Jan 29 '14 at 14:27
  • @frostschutz ah, so the array name from `mdadm -E` that is currently `unassigned:0` on the new server is split at the `:`, and the second part becomes part of the `/dev/md/`? So if I'd change the array name to `unassigned:asdf`, the symlink would be called `/dev/md/asdf`? And the actual device is always called `/dev/mdN`, where N is the next free number? – Martin von Wittich Jan 29 '14 at 14:36
  • 1
    You could use it that way, but nobody does it; it doesn't really work, since usually the md is created from a live cd that does not have your host name set, etc. A name like `unassigned:0` is just braindead. – frostschutz Jan 29 '14 at 15:14

3 Answers3

4

When it comes to device names, better ask udev. To my understanding,

  1. md%d naming is used by kernel, it is generated directly by driver md.c#L5646, and it's used in /proc/partitions and sysfs. Hence, it appears in /dev

  2. /dev/md/... and /dev/disk/by-id/... are generated as symlinks by udevd. In my system corresponding rules are kept in /usr/lib/udev/rules.d/63-md-raid-arrays.rules:

    ENV{DEVTYPE}=="disk", ENV{MD_DEVNAME}=="?*", SYMLINK+="md/$env{MD_DEVNAME}"
    

It seems that udev file comes from openSUSE 11.1-rc3 according to this commit in mdadm. I've checked this file in openSUSE 11.0, but it doesn't have md/%d symlinks...

fra-san
  • 9,931
  • 2
  • 21
  • 42
myaut
  • 1,411
  • 10
  • 12
3

you can name array as own name (not only 0-127) and since mdadm 3.0.3 you can use only name. If think path was changed to use subfolder /dev/md/$name to make more flexibility or some kind of clean or group arrays. If md array is created in format /dev/mdX there is added symlink to make compability to new format.

0

Probably the original path varies depending on the Linux kernel version or Unix system. The symbolic link /dev/md/N may exist for compatibility reasons. Programs or scripts that may use this path instead of /dev/mdN.

jayhendren
  • 8,224
  • 2
  • 30
  • 55
hongo
  • 111
  • 2