2

This is my /etc/mdadm/mdadm.conf

ARRAY /dev/md/root   metadata=1.2 name=root   UUID=331728d9:c4d12r4f:f589d3ze:01ab3c17
ARRAY /dev/md/backup metadata=1.2 name=backup UUID=429845f1:d5e24f5g:8135dgte:120ff5c0

find report this situation:

find /dev/md -ls
     1656      0 drwxr-xr-x   2 root     root           80 nov  8 05:30 /dev/md
     1784      0 lrwxrwxrwx   1 root     root            8 nov  8 05:30 /dev/md/ibmlinux:backup -> ../md127
     1657      0 lrwxrwxrwx   1 root     root            8 nov  8 05:30 /dev/md/ibmlinux:root -> ../md126

as you can see we have md126 and md127, is possible to force it to name md0 and md1? I have tried to create duplicate arrays in mdadm.conf but don't work. System is Debian SID.

I want a result like this: preserve the /dev/md/name and have md0 and md1 instead of md127 and md126

find /dev/md -ls
     1656      0 drwxr-xr-x   2 root     root           80 nov  8 05:30 /dev/md
     1784      0 lrwxrwxrwx   1 root     root            8 nov  8 05:30 /dev/md/ibmlinux:backup -> ../md1
     1657      0 lrwxrwxrwx   1 root     root            8 nov  8 05:30 /dev/md/ibmlinux:root -> ../md0

Now I try this mdadm.conf

ARRAY /dev/md0 metadata=1.2 name=root   UUID=331728d9:c4d12r4f:f589d3ze:01ab3c17
ARRAY /dev/md1 metadata=1.2 name=backup UUID=429845f1:d5e24f5g:8135dgte:120ff5c0

and after update initramfs and reboot...

find /dev/md -ls
     9250      0 drwxr-xr-x   2 root     root           80 nov  8 05:50 /dev/md
     9299      0 lrwxrwxrwx   1 root     root            8 nov  8 05:50 /dev/md/ibmlinux:root -> ../md126
     9251      0 lrwxrwxrwx   1 root     root            8 nov  8 05:50 /dev/md/ibmlinux:backup -> ../md127

Same thing.

0

2 Answers 2

2

It's not possible to specify both alias and number in mdadm.conf so you'll have to rely on mdadm metadata.

By default, both hostname and number (super-minor) are stored in metadata. So you can just set your preferred md numbers there.

Changing the number can be done by assembling manually once, for example change it to 42:

# mdadm --stop /dev/md126
# mdadm --assemble /dev/md42 --update=name /dev/sdx3 /dev/sdy3
# mdadm --stop /dev/md42

This change should be reflected in metadata:

# mdadm --examine /dev/sdx3
Name : host:42

And in automated assemble, this number should be used, provided that the hostname matches as well.

The hostname can be an issue so you can ignore it by adding HOMEHOST <ignore> to your mdadm.conf.

You can also use HOMEHOST <none>, in that case the previous --assemble --update command would give you Name : 42 without any hostname stored in metadata.

The array specification itself stays unchanged as ARRAY /dev/md/name UUID=.... UUID alone should be sufficient here, if you add more things like metadata= name= you have to make sure these values still match, or the whole ARRAY line will be ignored.

6
  • I have boot with a livecd, update the name with # mdadm --assemble /dev/md4 --update=name /dev/vda2 /dev/vdb2. After reboot became.../dev/md127, even --examine return the right value name:4
    – elbarna
    Commented Nov 8, 2023 at 7:43
  • 1
    @elbarna did you also add HOMEHOST <ignore> to mdadm.conf, and update initramfs? Commented Nov 8, 2023 at 7:47
  • 1
    I also had an older answer regarding md names and issues around it. Personally I prefer to stick to numbers and leave the names to LVM. But it did work when I tested it earlier... Commented Nov 8, 2023 at 7:50
  • md names just aren't that well supported in the end. the metadata should have a dedicated field for each property (hostname, super-minor number, alias name) instead it's all mashed together in a single name field with 32 byte limit. so while you may be able to find a configuration where everything lines up, it shouldn't be considered too reliable... Commented Nov 8, 2023 at 8:00
  • 1
    mdadm.conf missing (in initramfs) or doesn't match the array, would be my guess, or mdadm changed its behavior recently. Just tested again and it works for me [on archlinux] for both manual --assemble and --incremental mode. Takes the name from mdadm.conf and the number from metadata... md127 is the default choice for when there are no other specifications at all (foreign arrays, no mdadm.conf, ...) it starts with 127 then decrements 126, 125...0, then jumps to 511..129. No one will have that many arrays normally so you never see beyond 127,126,125... Commented Nov 8, 2023 at 20:30
2

Solution found: dirty but works.

Create a script in /etc/initramfs-tools/scripts/init-premount

vim /etc/initramfs-tools/scripts/init-premount/md

#!/bin/sh

# Stop lvm
lvm vgchange -an vg-backup
lvm vgchange -an vg-ppclinux
sleep 3

# Stop raid
mdadm --stop /dev/md126
mdadm --stop /dev/md127
sleep 3

# Assemble with new names 
mdadm -A /dev/md0 /dev/sda2 /dev/sdb2
mdadm -A /dev/md1 /dev/sdc1 /dev/sdd1
sleep 3

# Create the symlinks
mkdir /dev/md
ln -sv /dev/md1 /dev/md/ibmlinux:backup
ln -sv /dev/md0 /dev/md/ibmlinux:root

# Start lvm
lvm vgchange -ay vg-ppclinux
lvm vgchange -ay vg-backup

update permissions

chmod 755 /etc/initramfs-tools/scripts/init-premount/md

update initramfs and grub

update-initramfs -cv -k all
update-grub2

and after reboot..

find /dev/md -ls
    11344      0 drwxr-xr-x   2 root     root           80 nov  8 06:12 /dev/md
    11345      0 lrwxrwxrwx   1 root     root            8 nov  8 06:12 /dev/md/ibmlinux:root -> /dev/md0
     9440      0 lrwxrwxrwx   1 root     root            8 nov  8 06:12 /dev/md/ibmlinux:backup -> /dev/md1

I only get this error/warning message on log

PV /dev/md0 9:0 is duplicate for PVID ........ on 9:126 /dev/md126 failed to create online file

but all works fine (pvs, lvcreate, mdadm..)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .