Table of Contents

About

Usually when creating a RAID array, it is expected to transfer the data outside before creating the RAID array because creating a new RAID array is a destructive process. However, that does not necessarily apply to a RAID 1 (mirror) array that can be created using a drive with already existing data given that all the requirements for a RAID 1 array are satisfied.

A side-effect advantage of this procedure is that the data has to be copied only once after which the data can be used whilst the RAID array synchronises.

Requirements

Assumptions

The tutorial is written under the following assumptions:

Copying Over the Partition Table

In order to copy over the existing partition table from the drive already containing the data (/dev/sda) to the spare drive (/dev/sdb) we issue:

sfdisk -d /dev/sda | sfdisk /dev/sdb

where:

Create the RAID Array with a Missing Drive

Next we create a RAID 1 array with two drives from the spare drive that does not contain any data:

mdadm --create /dev/md0 --level=mirror --raid-devices 2 /dev/sdb1 missing

where:

Copying Data

Now we would have created a RAID 1 array referenced by the /dev/md0 device with only the spare drive /dev/sdb being a member. To confirm, issue:

cat /proc/mdstat

which should output something like:

md0 : active raid1 sdb1[0]

The next step is to format this RAID device with only one member. For instance, to use the Ext4 filesystem, we would issue:

mkfs.ext4 /dev/md0

Finally, what we are going to do is copy over the existing data from /dev/sda1 into the newly created RAID array with one missing drive. In order to do that, we mount /dev/md0 to a mount-point:

mount /dev/md0 /mnt/raid1

where:

Then, we mount the drive that already contains data (/dev/sda1) to some other mount point:

mount /dev/sda1 /mnt/trans

And copy the data over from the drive already containing the data /dev/sda1 into the RAID array:

rsync -P -av /mnt/trans/ /mnt/raid1

which, depending on your situation, could take a while.

Assembling the Full RAID Mirror Array

After all the data has been copied over, unmount all the mount points (/mnt/raid1 and /mnt/trans in this tutorial):

umount /mnt/raid1
umount /mnt/trans

and then add the drive from which we copied the data over (/dev/sda1) to the RAID 1 array:

mdadm --add /dev/md0 /dev/sda1 

Watching the Synchronisation

In order to watch the RAID array synchronising both drives you can issue:

cat /proc/mdstat

as well as get other details about the RAID array with:

mdadm --detail /dev/md0