May '22 05

Build loopback raid md

Create Loop devices

cd /tmp
truncate -s 1G L{1,2,3}.img
losetup --show -f L1.img
losetup --show -f L2.img
losetup --show -f L3.img

Create the Array

mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/loop{0,1}
mkfs.ext4 /dev/md0

Add 3rd Disk as Spare

mdadm --add /dev/md0 /dev/loop2
mdadm --detail /dev/md0

Convert Raid1 to Raid5 (reshape).

mdadm --grow /dev/md0 --level=5 --raid-devices=3
cat /proc/mdstat

Grow Filesystem to suit. Notice the Array and Used size changes after conversion.

mdadm --detail /dev/md0
resize2fs /dev/md0

Cleanup Loopback interfaces / md devices

mdadm --stop /dev/md0
losetup -d /dev/loop{0,1,2}
rm -fv /tmp/L{1,2,3}.img