This tech article will address building a Linux RAID mirror from an existing, unraided disk. Some assumptions are made:
+There are three drives.
+The existing drive (with the original data to mirror) is /dev/sdc.
+The other two (/dev/sda and /dev/sdb) are identical make and model.
+/dev/sdb will receive the installation from /dev/sdc first. The '/' partition will be sdb3.
+/dev/sda will then receive the installation via the mirror process.
Additionally, for this exercise, CentOS 5.5 was the optical boot media. Feasibly, just about any distribution should work.
Put all three drives online, and boot to the CentOS 5.5 media. After the media has booted to the colon prompt, enter:
The boot process continues. Choose the appropriate language and keyboard. There is no need to start the network, and there is no need to search for existing installations. Just choose "Skip" at the end to go straight to the rescue prompt.
Now we will duplicate the original disk's partition structure. For this example, partition 3 is '/'. But, we want all partitions anyway, so at the rescue prompt:
This command will warn, and also output some rather dire appearing language. It's bark is worse than it's bite!
Now we want to create the RAID:
Remember, sda and sdb will be in the RAID. sdc will NOT. So, we have just setup the RAID to include sdb. sda will come later.
Now you should be able to have a look at the RAID with the following command:
The output should show one drive online/working/active (sdb) out of a total of two. The state will be 'clean, degraded'.
Now to create the filesystem on the RAID:
This will take some processing but should finish with the output:
180 days, whichever comes first. Use tune2fs -c or -i to override.
Now, we want to get our ducks in a row. Referencing the "assumptions" portion at the top, enter the following:
#mount -t ext4 /dev/md0 raid1
#mount -t ext4 /dev/sdc3 original
The 'raid1' mountpoint implicitly mounts sdb3, added to the RAID just prior. The 'original' mountpoint contains our precious installation. Next we will clone that installation into the degraded RAID:
NOTE!!! the trailing '/' after "original". Be sure to include this or you will find yourself reworking this recipe.
The entire partition should copy from the original to the raid. When it's done we will unmount the original:
Now we want to add the second drive to the RAID mirror:
Mirroring should begin immediately. To check it's progress:
Also, be sure to edit fstab to include /dev/md0 as '/'. The original installation was not to this device.