When a hard disk drive in one of my Linux machines failed, I took the opportunity to migrate from RAID5 to a 6-disk software RAID6 array.
At the time of the migration I did not have all 6 drives - more specifically the fourth and fifth (slots 3 and 4) drives were already in use in the originating array, so I created the RAID6 array with a couple of
missing devices. I now need to add those drives in those empty slots. Using
mdadm --add does result in a proper RAID6 configuration, with one glitch - the new drives are placed in new slots, which results in this
... md0 : active raid6 sde1 sdd1 sda1 sdf1 sdc1 sdb1 25185536 blocks super 1.0 level 6, 64k chunk, algorithm 2 [6/6] [UUUUUU] ...
mdadm -E verifies that the actual slot numbers in the device superblocks are correct, yet the numbers shown in
/proc/mdstat are still weird.
I would like to fix this glitch, both to satisfy my inner perfectionist and to avoid any potential sources of future confusion in a crisis. Is there a way to specify which slot a new device should occupy in a RAID array?
I have verified that the slot number persists in the component device superblock. For the version 1.0 superblocks that I am using that would be the
dev_number field as defined in
include/linux/raid/md_p.h of the Linux kernel source. I am now considering direct modification of said field to change the slot number - I don't suppose there is some standard way to manipulate the RAID superblock?
To modify the slot assignments in the device superblock I would need to do the following:
- Modify the
dev_rolesarray to mark the old slot as empty and place the proper role at the new slot
- Re-compute the superblock checksum
(1) and (2) are relatively simple and can be automated via a script or small program. (3) started to push things a little - I would have to rip the superblock checksum code from the
md driver, modify it to work with a userspace program and hope for the best.
Rather than spend my time debugging a C application and risk killing my arrays with a bug, I decided to try to trick
mdadm into doing my work for me, as mentioned in my answer. This seems to have worked, although it may still have a degree of risk...