Server!/Horror! I have a magnet and I don't mind using it!

Migrating RAID Levels in Linux with mdadm

This is a quick note. If you try the stuff here I suggest you do it in a virtualised guest machine. This does not resemble the whole truth you can use --backup-file to minimize the number of hot spares required...

Clear out any RAID information on the disks involved

$ sudo mdadm --zero-superblock /dev/sd[bcdefghijk]

Keep Status overview running while we work on this:

$ while true;
        cat /proc/mdstat
        /bin/echo -e '\nmdadm --detail'
        sudo mdadm --detail /dev/md/md0
        sleep 2

Create a RAID1 with a missing disk:

$ sudo mdadm --create md0 --raid-devices 2 --level 1 /dev/sdb missing

Add a hot spare(s), mdadm will start a recovery process so that the degraded array will gain a clean state:

$ sudo mdadm --manage /dev/md/md0 --add /dev/sdc

Add a hot spare(s):

$ sudo mdadm --manage /dev/md/md0 --add /dev/sdd

Check the hot spare is working and make sdc available again:

$ sudo mdadm --manage /dev/md/md0 --fail /dev/sdc --remove /dev/sdc --add /dev/sdc

Convert into a RAID5 array:

$ sudo mdadm --grow /dev/md/md0 --level 5

Add a disk to the array, to get a clean state for the array:

$ sudo mdadm --grow /dev/md/md0 --raid-devices 3

Add a hot spare(s):

$ sudo mdadm --manage /dev/md/md0 --add /dev/sd[ef]

Grow the RAID5 to have more space available:

$ sudo mdadm --grow /dev/md/md0 --raid-devices 4

Add a second hot spare so that we can migrate from RAID5 to RAID6 (RAID5 to RAID6 needs to spares available):

$ sudo mdadm --manage /dev/md/md0 --add /dev/sdg

Convert into a RAID6 array and make it rebuild to a clean state:

$ sudo mdadm --grow /dev/md/md0 --raid-devices 6 --level 6

Add another hot-spare to be able to migrate from RAID6 to RAID5 (RAID6 to RAID5 needs one spare available):

$ sudo mdadm --manage /dev/md/md0 --add /dev/sdh

Convert from RAID6 to RAID5:

$ sudo mdadm --grow /dev/md/md0 --level 5 --raid-devices 7

Add 3 more spares (just in case):

sudo mdadm --manage /dev/md/md0 --add /dev/sd[ijk]

Exercise left to the reader (in that order):

  1. Convert from RAID5 to RAID6
  2. Convert from RAID 6 to RAID5

Generated: 2017-11-02 10:20:47 +0100