Migrating from RAID0 -> RAID1 with mdadm
Because of a stupid mistake made during a hectic installation of RHEL /var partition was configured as RAID0 instead of RAID1. Thankfully, it could be easily fixed though with a short downtime. Here is how I did it:
- Stopped all processes that were using /var. In my case they were sendmail and named.
- Backed up the data.
- I had to comment out /var in /etc/fstab because even in a single user mode I failed to unmount it.
- Rebooted into a single user mode.
- Created, mounted /dev/md3 and restored the data.
- And finally, updated /etc/mdadm.conf to reflect applied changes.
- Rebooted.
# cd /var # find . | cpio -o -Hnewc > /root/var.cpio
# mdadm --stop /dev/md3 # mdadm --create --verbose /dev/md3 --level=1 --raid-devices=2 /dev/sdb2 /dev/sd2 # mkfs.ext3 /dev/md3 # mount /var # cd /var; cpio -i < /root/var.cpio
# mdadm --detail --scan > /etc/mdadm.conf