I have 3 exactly the same drives (4tb ironwolf) where i would like to make a raid-5 with using MDADM for a small degree of data security. Now the problem is, 1 drive is filled with data which i am unable to make a backup for.

Yes, i understand that when building and a drive fails all my data is gone, but still i would like to give it the best try.

To make it more understandable lets call them sda1 and sdb1 which are empty, and sdc1 with data.

mdadm --create --verbose /dev/md0 --level=5 --raid-devices=2 /dev/sda1 /dev/sdb1;
rsync -av --exclude-from=excludefile /dev/sdc1 /dev/md0;    
mkfs.ext4 /dev/sdc1;    
mdadm --add /dev/md0 /dev/sdc1;    
mdadm --grow --raid-devices=3 --spare-devices=1 /dev/md0;

Can someone confirm that this is a proper way?


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 ($lc)

mkfs -t ext4 -L data "$lc"
mount "$lc" /mnt
cp -a /usr/share/man/man1 /mnt
umount /mnt

Now try creating the RAID5 arrays per your ideas. In this scenario we have $la and $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.

umount /mnt/src
umount /mnt/dst

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
  • Thanks alot for this detailed information! It worked out properly! – Sahbe30 Oct 15 '18 at 17:48
  • @Sahbe30 pleased it was useful for you. I find with RAID that where you're touching live data, it's usually worth testing out on a number of loopback devices before going anywhere near the real disks. – roaima Oct 15 '18 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.