6

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.

1
  • 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, 2011 at 20:12

2 Answers 2

13

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)).

-1

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.

4
  • aww, didn't like my answer?
    – user606723
    Aug 12, 2011 at 18:28
  • I voted it up, but I could not get it to work. Aug 12, 2011 at 18:29
  • what exactly couldn't you get to work?
    – user606723
    Aug 12, 2011 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, 2011 at 18:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .