convert 1x2TB HDD with LVM into 2x2TB HDD with RAID1+LVM or with LVM mirroring?

Solution 1:

assuming sda is the original disk, and sdb is the new disk:

  1. partition the new drive. if using fdisk, be sure to hit c so it is aligned, and change the partition type to da.
  2. sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 missing to create the raid device from the newly partitioned drive.
  3. sudo mdadm -Es and copy the output of this to /etc/mdadm/mdadm.conf so the raid device gets started automatically when the server reboots.
  4. sudo pvcreate /dev/md0, after this just do vgcreate on /dev/md0 and lvcreate like usual, or you can use pvmove

After the data is moved off the old drive and on to the new, you can repartition the old drive, making sure the partition size is the same as the new raid drive. Then add it to the raid device with: sudo mdadm --manage --add /dev/md0 /dev/sda1. Since it sounds like these are boot drives, you'll want to install grub to both drives.

Since this is a remote system, you'll probably want to do sudo dpkg-reconfigure mdadm (assuming this is a debian-based system, such as Ubuntu) and enable boot with degraded raid.

You'll also want to set up email so mdadm can notify you of issues with the Raid device (such as a failed drive).

  1. sudo aptitude install postfix
  2. choose a satellite system, I use the fqdn servername (or whatever you prefer), enter a smarthost if necessary.
  3. Edit /etc/aliases and add root: yourusername so root's mail go to you
  4. Edit ~/.forward with [email protected] so your emails go to your email account

Solution 2:

I was advised that possibly the easiest way to convert 1xHDD into 1xRAID1 is by:

  • creating a degraded 1-disk RAID1 on the newly installed HDD
  • copying data from current HDD to that degraded RAID1
  • adding the earlier-installed HDD to the degraded RAID1, and rebuilding the RAID.

Relevant links: 1, 2.