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

  • Two hard drives of the exact same size.
  • mdadm (install with aptitude or apt-get under Debian-like system).

Assumptions

The tutorial is written under the following assumptions:

  • The hard-drive that already contains the data will be referred to as /dev/sda.
  • The spare drive that will become part of the array will be referred to as /dev/sdb

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:

  • -d tells sfdisk to dump the partition table
  • /dev/sda is the drive containing the data
  • /dev/sdb is the spare drive

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:

  • /dev/md0 is the RAID device to use
  • –level=mirror is equivalent to RAID 1 mirror
  • –raid-devices 2 specifies that the array will contain two devices
  • /dev/sdb1 is the first partition of the spare drive that does not contain any data
  • missing tells mdadm to create the RAID 1 array with the second drive missing

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:

  • /dev/md0 is the RAID array we just created
  • /mnt/raid1 is a folder - can be any empty not-used folder

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

linux/create_raid_mirror_with_existing_data.txt · Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.