Let say you want to change the homehost and/or the name of a raid, for whatever reason. (one reason might be that you changed your system and so you want to match the homehost to match the hostid of your current system. mdadm has the option to auto load raids that have the same homehost as the hostid)

Imagine your systems hostid is this

# hostid
abc123

NOTE: the hostid is a unique identifier for your system. kind of like the mac address.

NOTE: there is a way to setup mdadm to auto start raids that have the same homehost as your systemd hostid.

Looking at 1 device/partition of a randomĀ raid deivce:

# mdadm -E /dev/sdg3
Name : abc123:data1

NOTE: the Name field in mdadm -E (–examine [partition]) and mdadm -D (–details [raid device[) output is of the format [homehost]:[name]. Where homehost should be the same on each raid for the same computer/server. name should be different per raid.

Looking at the raid that sdg3 belongs to (specifically the data1 raid of homehost abc123)

# mdadm -D /dev/md127
Name : abc123:data1

Lets say you changed your system, so the hostid changed (motherboard change, or mac address change, can cause the hostid to change). Lets assume our new systems hostidĀ is now WHATEVER.

So how do we change the homehost on the raid? Well each raid device (partition) has a raid superblock at the begin of the partition. To change that we can either recreate the entire raid (raid superblock with mdadm –assume-clean), or better we can just start up the raid (assemble the raid) and let it know to update(change) the homehost field (and likewise later the name field)

First make sure the RAID is stopped:

mdadm --stop /dev/md127

Typically we would start the raid like this (this doesnt change anything. this just starts the raid that is specified in the raid superblocks at the beginning of the listed devices: sda3, sdb3, sdc3, sdd3, sde3, sdf3, and sdg3):

mdadm -A /dev/md127 /dev/sd[abcdefg]3

If we want to change the homehost you would do this:

# ideally we want to change the homehost to the new hostid of the system `hostid` will return that value with bash substitution. instead of `hostid` you can also use $(hostid) as that is also bash substitution

mdadm -A /dev/md127 /dev/sd[abcdefg]3 --homehost=`hostid` --update=homehost 

# or change the homehost to whatever

mdadm -A /dev/md127 /dev/sd[abcdefg]3 --homehost=WHATEVER --update=homehost

NOTE: your homehost doesnt have to match the hostid, its just good practice. That way you know which device the raid came from. so if you move disks/devices from 1 system/computer to another, your other system wont try to boot up from the foreign raid.

So now the homehost is changed to the new hostid or WHATEVER.

Let say now we want to change the md127 raid from the name data1 to data-main.

NOTE: even though the raids name is data1, and after this its data-main. in /dev/ the raid is still named as md127 or whatever md number you pick. The md number that you pick is trivial (doesnt matter)

Well just do this to change the name of the raid:

If we want to change the name of the raid you would do this:

mdadm -A /dev/md127 /dev/sd[abcdefg]3 --name=datamain --update=name

Looking at 1 device/partition of that raid:

# mdadm -E /dev/sdg3
Name : WHATEVER:datamain

Looking at the full raid:

# mdadm -D /dev/md127
Name : WHATEVER:datamain

So here we changed the homehost from abc123 to WHATEVER and the name from data1 to datamain. The “Name :” field with mdadm -E/-D output changed from abc123:data1 to WHATEVER:datamain

Leave a Reply

Your email address will not be published. Required fields are marked *