If you have a small amount of disk space available you can test out these commands with loopback devices.
Create the loopback devices a, b, c:
dd if=/dev/zero bs=1M count=50 > diska.img # Plan for RAID5
dd if=/dev/zero bs=1M count=50 > diskb.img # Likewise
dd if=/dev/zero bs=1M count=50 > diskc.img # Original data will be here
la=$(losetup --find --show diska.img); echo $la
lb=$(losetup --find --show diskb.img); echo $lb
lc=$(losetup --find --show diskc.img); echo $lc
Create some "important original data" and put it onto the third disk (
mkfs -t ext4 -L data "$lc"
mount "$lc" /mnt
cp -a /usr/share/man/man1 /mnt
Now try creating the RAID5 arrays per your ideas. In this scenario we have
$lb as the two blank disks, and
$lc representing your important third disk:
mdadm --create --verbose /dev/md0 --level=5 --raid-devices=2 "$la" "$lb"
Success; this has created a RAID5 array with two members. Personally, I'd have specified three, with the third element as the word
missing, because this makes it clearer what I've intended:
mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 "$la" "$lb" missing
Your next command, though, is not quite right.
rsync copies between filesystems, not between devices, so first you need to create the new filesystem and mount both:
mkfs -t ext4 -L data /dev/md0
mkdir -p /mnt/src /mnt/dst
mount "$lc" /mnt/src # Here you could use mount /dev/sdc1 /mnt/src
mount /dev/md0 /mnt/dst
rsync -av --exclude-from=excludefile /mnt/src/ /mnt/dst
You should use
rsync --dry-run to check what it's going to do before it does it.
At this point you need to be absolutely sure that you have successfully copied the data from the original disk to the new (degraded) RAID5 array, as we are going to add the old disk into the array.
If you originally specified only two devices you need to grow the array to include a third:
mdadm --grow /dev/md0 --raid-devices=3 --add "$lc" # /dev/sd1c when you do this for real
On the other hand, if you took my recommendation and started with three devices (one of which was
missing) you just need to add the device:
mdadm --manage /dev/md0 --add "$lc"
Finally, you can remount the RAID 5 array in the intended part of the filesystem. Use
cat /proc/mdstat to see how the resynchronisation is going.
For the testbed ONLY, you need to stop the array and delete the components
mdadm --stop /dev/md0
losetup -d "$la"
losetup -d "$lb"
losetup -d "$lc"
rm diska.img diskb.img diskc.img