Linux: Rename SoftRAID device name from md127 to md0

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
peter_b
Chatterbox
Posts: 383
Joined: Tue Nov 12, 2013 2:05 am

Linux: Rename SoftRAID device name from md127 to md0

Post by peter_b »

[PROBLEM]
After re-installing Debian 7 (Wheezy) on a server with re-integrating existing Kernel software RAIDs, I ended up with "ugly" device names, such as:
/dev/md127 instead of /dev/md0

I don't know where Linux stores the device names it assigns to software RAIDs, but in my case it wasn't "/etc/mdadm/mdadm.conf", because in there, I used the md-labels, like this:

Code: Select all

ARRAY /dev/md/dlp_raid_1 metadata=1.2 UUID=957faa4b:899b682b:a6b7e34b:b247dd85 name=bb2:dlp_raid_1
ARRAY /dev/md/dlp_raid_2 metadata=1.2 UUID=2c51e39a:291e5fe2:4f3586d4:fa543b72 name=bb2:dlp_raid_2
ARRAY /dev/md/dlp_raid_3 metadata=1.2 UUID=43e76209:1f7f56a8:ef426abe:e574b892 name=bb2:dlp_raid_3
[SOLUTION]
There are 2 options:
  1. Modify /etc/mdadm/mdadm.conf (requires reboot)
  2. Stop/re-assemble arrays during runtime (no reboot required)
0) Edit mdadm.conf:
In my mdadm.conf I used the md-labels "/dev/md/xxx", which work regardless of the actual /dev/mdXXX device name, but that parameter can be used to tell the kernel which device names to actually create.
So edit/adjust the "ARRAY" parameter accordingly.
Here's my edited config, for example:

Code: Select all

ARRAY /dev/md1 metadata=1.2 UUID=957faa4b:899b682b:a6b7e34b:b247dd85 name=bb2:dlp_raid_1
ARRAY /dev/md2 metadata=1.2 UUID=2c51e39a:291e5fe2:4f3586d4:fa543b72 name=bb2:dlp_raid_2
ARRAY /dev/md3 metadata=1.2 UUID=43e76209:1f7f56a8:ef426abe:e574b892 name=bb2:dlp_raid_3
Once that's done, you must update your Kernel's initramfs to reflect the changes after reboot:

Code: Select all

$ update-initramfs -k all -u

If you can reboot the server, do so now, and your md-devices should be named properly.
If you can not reboot at the moment, the following steps describe how to change stuff in runtime (except if the OS-partition itself is on the RAID, because you can't do that without unmounting, etc).

1) Stop the affected array(s):
NOTE: This only works for arrays which are not your system disk!

Code: Select all

$ mdadm --stop /dev/mdXXX
2) Assemble the arrays and give them the desired device name:
In a nutshell, it's like this:

Code: Select all

$ mdadm --assemble --no-degrated /dev/md0 /dev/sda1 /dev/sdb1 ...
In my setup (Backblaze 45drives pod v3), each array is RAID6 and has 15 disks: 14 active + 1 spare, so I use a wildcard-mask on "/dev/disk/by-path/pci-0000..." to list all the drives that belong to that RAID array.

The "--no-degraded" option is very important: In case not all disks were properly found/assembled, it will not start the array.
Without this, you might end up with an automatic re-sync that would actually not be necessary...

3) Verify array status using /proc/mdstat:
If the above assemble-command worked properly, you should now see this array with the desired device name, when looking at /proc/mdstat:

Code: Select all

$ cat /proc/mdstat
For example, mine now looks like this:

Code: Select all

md0 : active (auto-read-only) raid6 sda1[0] sdo1[14](S) sdn1[13] sdm1[12] sdl1[11] sdk1[10] sdj1[9] sdi1[8] sdh1[7] sdg1[6] sdf1[5] sde1[4] sdd1[3] sdc1[2] sdb1[1]
      35161602048 blocks super 1.2 level 6, 512k chunk, algorithm 2 [14/14] [UUUUUUUUUUUUUU]
      bitmap: 0/11 pages [0KB], 131072KB chunk
Excellent! :)

4) Repeat steps 1-3 for all affected arrays.


Links:
User avatar
peter_b
Chatterbox
Posts: 383
Joined: Tue Nov 12, 2013 2:05 am

Re: Linux: Rename SoftRAID device name from md127 to md0

Post by peter_b »

What I still haven't figured out is, why it is necessary in this case to keep /dev/mdX in mdadm.conf - and not being able to use the array-name - for reboot-safe /dev/mdX device names.
It seems that it is somewhere remembered that an array was once called "/dev/md12X" - and it will then revert to this device name, if "ARRAY /dev/md/{array_name}" is used.

The above instructions work, but might lead to inconsistency in the output of the following 2 commands:

Code: Select all

$ mdadm --detail --scan
vs.

Code: Select all

$ sudo /usr/share/mdadm/mkconf
In a proper/perfect setup, they match.
I suspect "udev" to play some role here...

Maybe "/lib/udev/rules.d/64-md-raid.rules"?


to be continued...
User avatar
peter_b
Chatterbox
Posts: 383
Joined: Tue Nov 12, 2013 2:05 am

initramfs!

Post by peter_b »

I think I might have found out how to do it (not 100% confirmed yet, but...):

The mdadm.conf is stored in the initramfs image used at boot.
I think the issue is that the boot image uses older/different mdadm.conf info - and therefore uses a different md-number to avoid collisions.

Using "update-initramfs" after updating the mdadm.conf to the current state might do the trick:
http://manpages.ubuntu.com/manpages/pre ... mfs.8.html


Still have to test it.
Post Reply