2023 UPDATE
Things are easier now, and this more-or-less works without any messing around, or manual assembly, or access to the original config, and so on. The procedure below was tested on a move of a 10-year-old 3-drive RAID 5 setup from SL (ie. RedHat) 6.9 to Ubuntu 22.04.
If you can, get the following from the old machine:
mdadm.conf
(/etc/mdadm.conf
or /etc/mdadm/mdadm.conf
)
/etc/fstab
- The output from
cat /proc/mdstat
- The output from
mdadm -D /dev/mdx
, where 'mdx' can be found from (3) (ie. /dev/md0
)
It doesn't really matter if you can't get this information; you just need it for a sanity check.
Now install mdadm
on the new machine, and reboot. There will be a new mdadm.conf
(almost certainly in /etc/mdadm
), which should correctly report the drive UUID (it should be the same UUID as the one reported by mdadm -D
on the old machine). This will look something like
ARRAY /dev/md/0 metadata=1.1 UUID=68d1ea02:83b09989:707c6320:1905a656 name=0
The new output from cat /proc/mdstat
and mdadm -D
should be pretty much identical to the output from the old machine, except that the device is likely to have changed (in my case, /dev/md127
changed to /dev/md0
) and the sizes reported may be slightly different.
You now need to create an /etc/fstab
entry, and you (preferably) need an fstab-style UUID for this (this is not the same UUID as the one reported by mdadm
). If your new array is /dev/md0
, then
$ blkid | grep /dev/md0
/dev/md0: UUID="some-long-uuid" BLOCK_SIZE="4096" TYPE="ext4"
Now create the directory where you want to mount the new drive, and create an /etc/fstab
entry:
UUID=some-long-uuid /data ext4 defaults 0 2
In this case, the array will be mounted at /data
.
Test the new fstab entry by running mount -a
as root; this will mount anything which has not yet been mounted. You should also check /etc/mtab
to confirm that the mount options are correct:
$ cat /etc/mtab | grep /dev/md0
/dev/md0 /data ext4 rw,relatime,stripe=256 0 0
Don't try to reboot before running these tests. If you get the UUID incorrect, the kernel will boot to an emergency console with a dependency error. To recover, remove your new /etc/fstab
entry and reboot.
After a reboot you should see the old array at the mount point.