Converting to RAID 1

I was at Fry’s recently and saw a good deal on a 500 GB hard drive. I decided to get it to expand my home server from a single 500 GB drive to two drives in RAID 1. With Linux, it is possible to do the conversion without any downtime (but lots of time spent copying files). The secret is to create the RAID 1 volume in a degraded state with the new drive, copy the files to the RAID 1 voume, and then add the old drive to the volume. With LVM2, the extents can be moved with pvmove.

  1. Partition the new drive

    fdisk /dev/sdb

  2. Create the RAID 1 volume

    mdadm –create /dev/md0 –level=1 –raid-devices=2 missing /dev/sdb1

  3. Create the Physical Volume

    pvcreate /dev/md0

  4. Add PV to Volume Group

    vgextend vg0 /dev/md0

  5. Move all the extents to new volume (takes a long time)

    pvmove /dev/sda1 /dev/md0

  6. Remove old disk from volume group

    vgreduce vg0 /dev/sda1

  7. Add the old disk to RAID volume (takes a long time)

    mdadm /dev/md0 –add /dev/sda1