Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
    
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
add comment

2 Answers 2

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
http://www.tek-tips.com/viewthread.cfm?qid=1318503&page=1

share|improve this answer
add comment
up vote -1 down vote accepted

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.

share|improve this answer
    
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. –  murgatroid99 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. –  murgatroid99 Aug 12 '11 at 18:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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