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:

  1. Stopped all processes that were using /var. In my case they were sendmail and named.
  2. Backed up the data.
  3. # cd /var
    # find . | cpio -o -Hnewc > /root/var.cpio
  4. I had to comment out /var in /etc/fstab because even in a single user mode I failed to unmount it.
  5. Rebooted into a single user mode.
  6. Created, mounted /dev/md3 and restored the data.
  7. # 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
  8. And finally, updated /etc/mdadm.conf to reflect applied changes.
  9. # mdadm --detail --scan > /etc/mdadm.conf
  10. Rebooted.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.