While upgrading my desktop to Fedora Core 12, I also decided to modify a software RAID mirror that I had on the old system. In particular, I wanted to do two things, without losing data:
- Change the partition layout, the old disks had partitions for OS and swap allocated to them, which I no longer needed. I know, LVM would have been nice here, but alas, I wasn't using it on this older box.
- I also wanted to upgrade to EXT4, and I've heard that upgrade process can potentially corrupt the entire disk (ask Bryan Call if you don't believe me).
So, since I'm using mirroring, I figure the "right" approach would be to just break the mirror, and do a migration safely that way. And of course, that does work, and there's plenty of information in the man-pages how to do this, but I figure I'll write down the steps I took so I can remember it myself (and maybe someone else finds it useful too).
The first step is to break the mirror, in my case, the RAID mirror is /dev/md2 using /dev/sdb and /dev/sdd, and then mount the broken mirror half on the file system:
# mdadm --manage /dev/md2 --fail /dev/sdb1 # mdadm --manage /dev/md2 --remove /dev/sdb1 # mkdir /mnt/old-data # mount /dev/sdb1 /mnt/old-data
We now have a complete "copy" of the mirrored data, make sure /mnt/old-data (or whatever you named it) looks good. The next step is to get rid of the old RAID device, and create a new one. In my case, I need to run fdisk as well, to change the partition layout, but I'm not going into details here exactly what I did, since it's very specific to my setup.
# mdadm --stop /dev/md2 # fdisk /dev/sdd # mdadm --create /dev/md0 --level 1 --raid-devices=2 missing /dev/sdd1
Finally, we can now create the new filesystem, and migrate the old data over to it:
# mke2fs -t ext4 -j /dev/md0 # mkdir /mnt/new-data # mount /dev/md0 /mnt/new-data # rsync -av /mnt/old-data/ /mnt/new-data
The final step is to add back the "old-data" partition into the new mirror, but before doing so, make sure the "new-data" looks alright.
# umount /mnt/old-data # fdisk /dev/sdb # mdadm --add /dev/md0 /dev/sdb1
That's it! Easy, and very little risk for lost data or corruptions.