2nd HDD as a RAID 1 Mirror on a Existing Ubuntu Server

5,824

I'm presuming one of the drives has the data you want to save. (One of the 2TB drives).

Let's say drive A has data, and drive B is blank.

You'll need to create a degraded raid on drive B. Start the raid on drive B and rsync all of your data over the newly created raid. Once that's done, you can add drive A to the raid, and it'll sync up and become part of the raid.

For example:

#create degraded raid (in this case /dev/sda1 is the blank drive)
sudo mdadm --create /dev/md0 -l raid1 -f -n 1 /dev/sda1
#create a file system on degraded raid.
sudo mkfs -t ext4 /dev/md0   #pick whatever fs you like here. ext4/xfs is my preference
#mount raid
sudo mount /dev/md0 /mnt/newRaid
# mount data you want to keep
sudo mount /dev/sdb1 /mnt/oldData
#copy data from old drive to newly created raid.
sudo rsync -avP /mnt/oldData /mnt/newRaid
#unmount old data drive
sudo umount oldData
#add drive.
sudo mdadm --manage /dev/md0 --add /dev/sdb2
#leave computer on until cat /proc/mdstat reposts as done.
Share:
5,824

Related videos on Youtube

Neil
Author by

Neil

Updated on September 18, 2022

Comments

  • Neil
    Neil almost 2 years

    Can any one point me in the right direction as to how I can add a additional HDD as a RAID 1 to my existing Ubuntu Server which works flawlessly. My present set up is that I have 2 HDD on my Ubuntu BOX. 1-160GB HDD which has the Ubuntu OS(12.04LTS). 2-2TB HDD which has all the Data. Basically I want to add the another HDD to the Box on a RAID configuration and I do not want to destroy any data on either HDD's... Is it Possible? if so how can I go about doing so?

  • csgeek
    csgeek about 10 years
    On a side note, if you're creating a new raid setup, I would look into LVM (easier to grow the FS volume) and encryption is nifty too. There are guides online on raid + lvm + encryption you might want to look at. But the snippet above will get you on a simple raid and keep your data.
  • Neil
    Neil about 10 years
    @csqeek; excuse me as i am a noobee, So running the above will not destroy my data in either of the HDD like the OS & the Data?
  • csgeek
    csgeek about 10 years
    from your description, this is what I assume you have. 1. an OS drive 160GB, and 2 more hard drives which are 2GB each. It was my impression that you have some data on one of the 2GB drives that you want to keep but convert into a raid. Let's label these to avoid confusion. OS (/dev/sda), Drive with data (/dev/sdb), blank new drive (/dev/sdc). My suggestion was to start a new raid on /dev/sdc in degraded mode, mount sdb and copy the data to the newly degraded raid, and then re-add sdb to the newly created raid. Does that make sense?
  • Neil
    Neil about 10 years
    @csqeek, excellent!!! Thank you very much... now I need to find out how to do these things you said. Du u have any how to doc of any sort? :)
  • csgeek
    csgeek almost 10 years
    There's standard tutorials on how to setup a raid, as mentioned in the previous posts, but nothing specific for the use case you described. I already listed the steps needed above. Also some on how to recover from a failed drive, but probably nothing specific to your use case.
  • Patrick Di Martino
    Patrick Di Martino over 9 years
    Csgeek's response does the trick. You just need to tell the array to use the added drive: mdadm --grow /dev/md0 --raid-devices=2
  • Shane
    Shane about 4 years
    Is this still relevant for 18.04? I haven't been able to find similar steps to these (i.e. retain data) anywhere else.
  • csgeek
    csgeek about 4 years
    @shane it's still relevant but I would still backup your day before doing it if possible but this still should work. I have a blog post buried somewhere on how to migrate from raid 1 to raid 5 without data loss but in general mdadm is a very powerful tool.