Linux – Easy way to convert from from IMSM to linux md RAID

fakeraidlinuxmdadmraidsoftware-raid

I generally use linux software md raid, but made the mistake of keeping IMSM "fakeraid" on a machine that came with it pre-configured. The fakeraid seeemed appealing because it worked seamlessly with both the bios and linux, which made it easier to configure (e.g., only install the bootloader once). Unfortunately, it seems to be impossible to set up a write intent bitmap with IMSM raid, and so my machine becomes painfully slow for 8 hours every time it crashes and reboots. (And unfortunately, I seem to be suffering a string of power outages.)

My question: is there an easy way to convert from IMSM fakeraid to linux software RAID without copying the data off somewhere (as I don't have another disk in the machine)? Alternatively, is there some way I haven't yet discovered to add a write intent bit map to fakeraid, so I don't have to rebuild the whole RAID array after every unexpected reboot?

Best Answer

Commands which I have used to convert my RAID10 from IMSM to software RAID:

Check which set of the disks:
# mdadm --detail /dev/md/vol0
Number   Major   Minor   RaidDevice State
3       8        0        0      active sync set-A   /dev/sda
2       8       48        1      active sync set-B   /dev/sdd
1       8       16        2      active sync set-A   /dev/sdb
0       8       32        3      active sync set-B   /dev/sdc

Remove set-B:
# mdadm /dev/md126 --fail /dev/sdc
# mdadm /dev/md126 --fail /dev/sdd

# mdadm /dev/md127 --remove /dev/sdc
# mdadm /dev/md127 --remove /dev/sdd

(Optional) Erase filesystem/old RAID info:
# dd if=/dev/zero of=/dev/sdc count=1024
# dd if=/dev/zero of=/dev/sdd count=1024

Create new RAID:
# mdadm --create --verbose /dev/md0 --level=10 --raid-devices=4 missing /dev/sdc missing /dev/sdd

Create new filesystem:
# mkfs.ext4 /dev/md0
Remember filesystem UUID
# mkdir -p /mnt/1
# mount /dev/md0 /mnt/1
Copy data:
# rsync -avux --progress --delete /mnt/raid/ /mnt/1

Edit fstab (change UUID of RAID filesystem to remembered):
# vim /etc/fstab

Synchronize changes while was long copy:
# rsync -avux --progress --delete /mnt/raid/ /mnt/1

=== Here if RAID filesystem is on / also needed bootloader setup. ===

Remount filesystem as readonly:
# mount -f -o ro,remount /mnt/raid

And again synchronize:
# rsync -avux --progress --delete /mnt/raid/ /mnt/1

# reboot
# mdadm --stop /dev/md126
# mdadm --stop /dev/md127
# mdadm /dev/md125 --add /dev/sda /dev/sdb