1

Is possible to change an md name while the md is still active? AFAIK is not possible

mdadm -A --update=name --name=ibmlinux-root /dev/md126
ls /dev/md/126_0 
/dev/md/126_0 
ls /dev/md/ibmlinux-root
error: no such file or directory

Is possible only to stop it, update the name, then reassemble it

mdadm --stop /dev/md126
mdadm -A --update=name --name=ibmlinux-root /dev/md126

now the problem... the /dev/md126 is a root device, mounted on / so is impossbile to umount it.

The best thing is to reboot with live-cd and rename it, then reboot (works, I have did it a lot of times).

But I want a more fast and easy solution, Debian use scripts on this directory

/usr/share/initramfs-tools/scripts/local-premount

my idea is to create a script, rename the md, then after reboot remove the script.

I have create the script

vim /usr/share/initramfs-tools/scripts/local-premount/md

#!/bin/sh -e

PREREQ=""

prereqs()
{
        echo "$PREREQ"
}

case $1 in
# get pre-requisites
prereqs)
        prereqs
        exit 0
        ;;
esac

mdadm --stop /dev/md126
mdadm -A --update=name --name=ibmlinux-root /dev/md126

I make it executable, update initramfs and grub

chmod +x /usr/share/initramfs-tools/scripts/local-premount/md                                                   
update-initramfs -cv -k all
update-grub2

I reboot and voilà..has the new name as..127! :(

   ls /dev/md/127_0 
   /dev/md/127_0 
   ls /dev/md/ibmlinux-root
   error: no such file or directory

What I miss? I tried also to put the script in /etc/initramfs-tools/scripts/init-premount/ and nothing change.

1 Answer 1

1

I have forgot, my root array was created with 0.90 metadata, I have recreate it with metadata 1.2 (modern grub can boot it without no problem), and to update the name I have simply to edit /etc/mdadm/mdadm.conf (metadata 0.90 don't allow name on md raid)

vim /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

update initramfs and grub and reboot.

update-initramfs -cv -k all
update-grub2
shutdown -r now

after reboot..

ls /dev/md
ibmlinux:backup  ibmlinux:root

Using the scripts of initramfs is also possible to change name of md127 to md0 or whatever we want

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 .