I have a 320GB hard drive with an LVM2 volume group that was created as part of the default installation. If I put a second 320GB hard drive into the computer, can I make the second drive mirror the first using Linux software RAID1 or something similar? I tried adding a new RAID array in the Gnome Disk Utility, but it only gave me the option of creating an array with two empty partitions.

  • Interesting question. If you can somehow change drive0 to be half of a raid1.., boot that up and somehow use drive1 as a "replacement drive" to recovery your "degraded" raid. IDK how you get drive0 to be like that though.
    – user606723
    Aug 5 '11 at 20:12

If anyone is still reading this older question, note that raid1 is now built-in to lvm2. To mirror an existing lv on a new drive using lvm2:

  • install the new drive and create lvm2 partition(s) (at least the same size as your existing drive's lvm partition(s), or those you want to mirror in any case) (use parted /dev/newdrive or use sfdisk -d /dev/sda | sfdisk /dev/sdb assuming sdb is your new drive)
  • initialise new partition(s) as lvm2 pv(s) (pvcreate /dev/newpartition)
  • extend your existing lvm2 vg(s) to the new partition(s) (vgextend /dev/myvg /dev/newpartition) and then first check and confirm that the number of extents on the new drive is the same or more (pvdisplay) Free PE on new drive should be more than Total PE of the old drive.
  • for each lv that you want to mirror on the new partition:

    lvconvert -m1 /dev/myvg/existinglv /dev/newpartition

    (ie, convert my existing (linear) lv to a raid1 mirrored lv with 1 additional mirror leg, and allocate the new PEs required for the mirror leg on the given new pv/partition)

  • note that you will need some additional space on the existing and new lv, because lvm2 raid1 mirror segments (the default) store their logs on the same pv/segment as the mirror leg (you will need an additional 1 PE per mirror leg on both the existing and new pv).

    If you get an error like 1 extents needed, but only 0 available then it might indicate a problem creating the log, and you might need to create some free space on the existing pv, possibly by shrinking the relevant lv to allow room (lvreduce). If you do this, you might need to resize the underlying filesystem beforehand (resize2fs)).


Firstly, you should backup your data just in case.
Also, make sure you read the steps carefully and know exactly what you're doing. I have never done this before, I just extracted the steps from some forum posts.

  1. With fdisk, create a new partition of type fd on your new drive, sdb.
  2. Create a degraded RAID1 array:
    mdadm -C /dev/md0 --force --level=1 --raid-devices=2 /dev/sdb1 missing
  3. Create a file system on /dev/md0: mkfs -t ext4 /dev/md0
  4. Now, /dev/md0 is currently a degraded raid1 with two drives, but one is missing.
  5. do a full copy from sda1 to md0, dd if=/dev/sda1 of=/dev/md0
  6. Mount /dev/md0 and inspect.

Ok, at this point you should have a raid1 with all the correct information. Now you should configure your grub2 configuration, fstab, etc. Make sure you have all the correct kernel modules etc. Once this is done, turn off the computer, and physically disconnect drive0 (sda). Now, get the system up and running with md0 alone.

Once you have the computer fully operational without drive0 connected, turn it off again, and reattach sda.

  1. With fdisk, repartition /dev/sda with a partition of type fd.
  2. Add /dev/sda1 to your existing RAID1 array: mdadm /dev/md0 --add /dev/sda1
  3. Done!. The array will start to 'rebuild' and you can check the status with mdadm -D /dev/md0

source: http://ubuntuforums.org/showthread.php?t=1703904


I achieved this by backing up all of my data onto an external drive, reinstalling Ubuntu onto a raid array, and then restoring my backup in the new file system. In particular, I followed these steps:

  1. Backup data using instructions at this forum thread using command

    sudo tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=backup.tgz --exclude=/mnt --exclude=/sys --exclude=/dev --exclude=/etc/fstab --exclude=/etc/mtab --exclude=/boot --exclude=/media /

    replacing backup.tgz in both cases with the location of the backup

  2. Turn computer off and install two hard drives with the smaller one being at least the size of the raid array (possibly including the original hard drive)

  3. Boot into install disk and run the installer.

  4. Using manual partitioning, make a partition in each hard drive for each partition in the final file system. For example, if you want your /home partition to be 100 GB, make a 100GB partition in each hard drive. Set all partitions that will be part of a RAID array to RAID autodetect (0xfd).

  5. Choose to make raid arrays, and put each partition into a raid array with the corresponding partition on the other disk.

  6. Finish the installation as normal and reboot into the fresh Ubuntu installation.

  7. Mount the external drive if it is not already mounted and restore the backup as described in the forum thread above using the command

    sudo tar xvpfz backup.tgz -C /
  8. Run sudo update-grub and then reboot. The new operating system should now be exactly like the original.

I prefer this method for a few reasons:

  • Making file system level copies instead of disk level copies seems preferable in general

  • It does not depend on keeping the partition structure the same

  • Once I figured out how to do it, the entire process took less time than the disk level copy took

  • It allows the installer to create the correct entries for boot devices and mounted devices, which need to change because raid partitions are referred to differently than regular partitions are.

  • aww, didn't like my answer?
    – user606723
    Aug 12 '11 at 18:28
  • I voted it up, but I could not get it to work. Aug 12 '11 at 18:29
  • what exactly couldn't you get to work?
    – user606723
    Aug 12 '11 at 18:29
  • I don't remember exactly (I tried several different things) but I think it was related to getting the output of dd to fit with the partitioning of the disk. I also prefer my way because it only uses filesystem level operations and doesn't have to copy several hundred GB of zeroes. Aug 12 '11 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.