10

As per subject.

When converting from RAID-1 to RAID-5 using mdadm, why must a RAID 1 array contain 2 devices and not more than 2 devices? I don't understand RAID strong enough to pinpoint a reason.

Background: My three RAID-1 arrays contain 3 devices each, my goal is to remove one device from two of the arrays, and attach the spare devices to the remaining RAID-1 array. That will leave two RAID-1 arrays with 2 devices each, and the remaining RAID array with 4 devices. The goal is take the 4 device RAID-1 array and convert that to RAID-5. This is not a discussion about which RAID architectures are better or worse, just the process to change a RAID-1 array to a RAID-5 array.

5 Answers 5

11

Upgrading an N-disk RAID1 to an N-disk RAID5 is possible, though a bit tedious:

  • Remove all but two disks from the RAID1. To do so, repeatedly execute:

    mdadm ARRAY --fail DEVICE
    mdadm ARRAY --remove DEVICE
    

    Where ARRAY is the ID of the array like /dev/md2 and DEVICE is a partition of that array like sdc2 or sdd2.

  • Change the size of the RAID1 to two disks:

    mdadm --grow ARRAY -n 2
    
  • Change the type of array from RAID1 to RAID5:

    mdadm --grow ARRAY -l 5
    
  • Now add all the disks again, that were removed in the first step:

    mdadm ARRAY --add-spare DEVICE DEVICE ...
    

    Please note, that unlike for --fail and --remove, you need to specify the full pathnames of the DEVICEs.

  • Grow the RAID5 to the number of available DISKS:

    mdadm --grow ARRAY -n DISKS
    

    This is the only slow operation, as it needs to move all data on the disks and generate parity. However, while it is in progress, you can still work on the machine, but you should expect degraded disk performance.

  • After the grow operation has finished (use cat /proc/mdstat to see its progress), you can resize the file system. Assuming, that you use ext4, this goes via:

    resize2fs ARRAY
    

Because of the lengthy re-arrangement of the data, it is often faster to delete the RAID1, then create a fresh RAID5 (which still needs to create parity, but which is an easier operation than to re-shuffle all data) and restore the data from a backup.

4
  • Thank you! For the step mdadm --grow ARRAY -n DISKS - what is DISKS? Is it a number of total disks, which I want to have after rebuild? I did sudo mdadm --grow /dev/md127 -n 3 and got the message: mdadm: Need to backup 128K of critical section... I see the rebuild is in progress now...
    – Slavik
    Oct 21, 2020 at 6:44
  • 1
    Yes, it is the number of disks, not the actual devices. The message, that you got is normal, and the rearrangement of the array will take some time.
    – Kai Petzke
    Oct 21, 2020 at 10:19
  • It worked! Converted 3 x 2TB RAID1 to RAID5. The grow step took ~11hours.
    – Slavik
    Oct 21, 2020 at 19:23
  • For some reason I got mdadm: /dev/md0: cannot get superblock from /dev/sda1 Oct 14, 2021 at 16:06
8

There is no migration path from RAID-1 to RAID-5, except for the special case with two disks, where RAID-1 conveniently is the same as RAID-4 and RAID-5 (because the parity of a single bit is the bit itself), so the migration code just changes the RAID level without touching the data.

After converting to RAID-5, you can add more disks to the array — this migration path exists.

So your migration plan would be:

  1. Run a consistency check on all devices (/usr/share/mdadm/checkarray …)
  2. Reduce all arrays to two disks¹
  3. Convert the array you want to switch to RAID-5 (--grow … -l5)
  4. Add the extra disks to the RAID-5 as spares (--grow … --add …)
  5. Set the new number of disks (--grow … -n4).

¹ That is tricky, because there is no good way to reduce the number of disks. You can, from a rescue system, overwrite the RAID superblock and use the --assume-clean option to avoid a rebuild, but you need to use the same superblock version as before (use mdadm --examine … on one of the component devices to find out).

1
  • 2
    Fortunately, it is possible to reduce an N-disk RAID1 (N > 2) to a two-disk RAID1 without hacks: Just use mdadm ARRAY --fail DEVICE repeatedly to mark a disk as "failed", then use madm ARRAY --remove DEVICE to remove it from the array. Once only two disks are left, use mdadm --grow ARRAY -n 2 to set the number of disks to two. Voilà, you now have a clean two-disk RAID1, to which steps 3 to 5 can be applied.
    – Kai Petzke
    Sep 2, 2020 at 19:01
4

As per mdadm documentation, you can 'upgrade' a mirror raid (raid1) to a degraded parity raid (raid5) and then add a new disk. Your raid will mostly not survive a single disk failure during rebuild, so you should have a recent backup, just in case.

3
  • 2
    I'm confused why the new array would be degraded. RAID5 with two total disks should be non-degraded, no?
    – cdhowie
    Jun 3, 2018 at 23:54
  • @cdhowie raid 5 can't have 2 drives, it's 3 drive minimum. Lossing the 3rd drive means it's degraded with no parity.
    – Evan R.
    Jul 6, 2018 at 19:20
  • 2
    mdadm RAID5 supports two disks as a non-degraded configuration, this is how my answer works. Jul 31, 2020 at 14:28
-2

It will not work on-the-fly and as simple as this. If you want to change RAID level from 1 to 5, you need to:

  1. Backup your data.
  2. Prepare your disks to support new RAID level.
  3. Configure RAID and format.
  4. Restore your data.

RAID-1 uses mirroring which means identical copy of your disk. However, RAID-5 uses a different technique called distributed parity. This page explains the standard RAID levels.

-2

Actually its fairly straightforward, use the "--grow" option

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .