Is it possible to convert an existing raid0 md device with only one disk to a raid1 md device with one disk in order to add a second mirror disk later? It should be possible online.
2 Answers
mdadm --grow cannot change raid0 into raid1 directly. This operation is not supported.
That also applies to raid0 with only a single drive, even though it may have the same on-disk layout as raid1. This is a corner case which is not supported since it's very unusual to have raid0 on a single drive (creating such an unusual array requires the --force option).
However, it is possible to grow raid0 to raid5. A two drive raid5 still has the same on-disk layout as raid1. This case is normally meant to allow growing raid1 to raid5. And raid5 allows switching back to raid1 in this configuration.
Example:
# truncate -s 1G raidtest.img
# losetup --find --show raidtest.img
/dev/loop3
# mdadm --create --level=0 --raid-devices=1 --force /dev/md/raidtest /dev/loop3
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md/raidtest started.
# cat /dev/urandom > /dev/md/raidtest
cat: write error: No space left on device
# sha3sum /dev/md/raidtest
20f42a814aaa8a181fd05bc79130fa8debd4eedad0e0f116e0cf177f /dev/md/raidtest
# mdadm --grow /dev/md/raidtest --level=5
mdadm: level of /dev/md/raidtest changed to raid5
# mdadm --grow /dev/md/raidtest --level=1
mdadm: level of /dev/md/raidtest changed to raid1
# mdadm --grow /dev/md/raidtest --raid-devices=1 --force
raid_disks for /dev/md/raidtest set to 1
# sha3sum /dev/md/raidtest
20f42a814aaa8a181fd05bc79130fa8debd4eedad0e0f116e0cf177f /dev/md/raidtest
Note: I ended up deadlocking md when trying to reduce number of drives to 1 while the array was in raid456 state. Unusual things happen, when you do weird stuff with mdadm. Nobody ever tests these things...
-
0 > 5 > 1, that's wild. Curious to understand why 0 > 5 is permitted; is there a reference you can point me to?Chris Davies– Chris Davies2024-09-22 13:44:03 +00:00Commented Sep 22, 2024 at 13:44
-
1raid0 has the same on-disk layout as raid5 with a dedicated parity disk. raid5 supports a ton of layouts, modes, and growing/reshaping, so it's the most flexible raid mode for conversions. even then it has limitations and it's only possible in this case since it's raid0 in name only on a single disk. if there were more disks, the raid5->raid1 step would fail since its only supported for 2-disk raid5.frostschutz– frostschutz2024-09-22 14:43:14 +00:00Commented Sep 22, 2024 at 14:43
-
1There is some documentation on this in mdadm(8)
--layout=,RAID-DEVICES CHANGES, and in md(4)RESTRIPING, or check linux/drivers/md/raid*.c for takeover functions.frostschutz– frostschutz2024-09-22 15:14:39 +00:00Commented Sep 22, 2024 at 15:14
No, it's not possible.
The best approach would be to wait until you have a second disk (why else would you want to switch to RAID1?). You would set that up as a new RAID1 array with a single disk, containing a copy of your data. When you had verified the data was safely copied you could incorporate the old now no longer required disk into your RAID1 as the other half of the mirror.
Don't forget to take a backup. Not just before migrating the data but also on a regular basis afterwards. (Actually this might be a better use of a second drive anyway.)
-
ok, it ends by am rsync and switch to the new mdWilliWuff– WilliWuff2024-09-13 09:26:30 +00:00Commented Sep 13, 2024 at 9:26