Migrate to RAID

This guide describes migrating an existing setup to software RAID. Please read and make sure you understand installing on a software RAID before proceeding. The guide assumes some prior knowledge (Modifying the partition table, configuring and installing a kernel).

Handling live data can be dangerous:


 * 1) Read man pages and understand each command before executing it.
 * 2) Use an up-to-date kernel, and a modern version of mdadm.

= Prerequisites =


 * RAID support must be compiled into the kernel (not as modules):


 * SCSI disk support must be also compiled into the kernel (not as modules). Even you will use SATA or PATA discs:


 * Install RAID userland tools:

Genkernel Users
If using genkernel, copy a kernel config file, with the above settings enabled, to


 * 1) Add dodmraid to the kernel parameters in

= Technical background =

RAID elements have a superblock to hold RAID information. This is used to:
 * Allow booting on RAID
 * Automount RAID partitions at boot time
 * Allow easy management with tools such as mdadm:

The super block is placed at the end of a RAID element. Therefore, with mirrored RAID, slightly less space is available for data. Because of this, it is not possible to simply enable RAID with a RAID superblock without data loss on top of an existing partition.

= Migrating data without extra drives = The following sections assume you have data on an existing disks drives, and some new disk drives. At the end of this procedure, all the drives will be used in the RAID setup, and no extra drives will be needed to move the data. The filesystem type can be changed during this process.

Create partitions on new device
Copy the existing partition schema (if both disks are the same size): , create your partition table and set all partition to type fd. If you forget this, the RAID will not get reassembled after rebooting.

Now, either manually create an identical table on the other disk, or copy the table with sfdisk.

Activate new RAID partitions
In the following commands, replace with the first free RAID device (could be other than  if the data is currently on a different RAID), and  with the correct partition.


 * Create the RAID (If sdb1 is the /boot or root partition add "--metadata=0.90"):


 * Create the filesystem on the RAID. For example:


 * Create temporary mount points for the RAID partitions:


 * Mount the new RAID partition:


 * Migrate the data (the -x flag forces rsync to stay on the same source partition when recursing through directories):

(--delete flag tells rsync to delete files from the destination which do not exist on the source):
 * If the system wasn't previously in single user mode, move to single user mode and update the data that changed during the first copy:


 * Modify and  to make /dev/md0 the root partition.

System should now be running with a degraded RAID on :
 * Verify the RAID is mounted:


 * Verify the RAID status:


 * Copy the partition map from the new drive to the old drive:


 * Add the partitions to the live RAID:


 * Watch the RAID rebuild status with:


 * setup the booloader on the new drive so it will be possible to boot from it if the first one fails,
 * setup the write intent bitmap
 * setup e-mail notification in

To RAID-5
Same as the migration process to RAID-1. Modify the create RAID command to use RAID-5 and to have additional partitions.

= Expanding a RAID1 to more than 2 drives = Example scenario: If you wish to migrate s root partition to RAID5 and use as the bootloader, please note that it does not support booting from RAID5. The boot partition must remain at most on RAID1. However, RAID1 can span more than 2 disks. This is reasonable for the boot partition, since it is seldom read from (on boot) or written to (kernel upgrade).

Assuming and  are mirrored on, add


 * Add the partition as a spare


 * Grow the RAID-1 from 2 elements to 3:


 * Observe the rebuild:

= Adding a drive to RAID =

These instructions are for ending up with RAID-5.

Method 1 : Reshape the RAID
Software RAID can be reshape the live RAID. See the man page for instructions. Many file systems have resizing tools that can then be used to grow them.

Method 2 : Migrate as similar to above
If expanding a RAID from 2 to 3 drives:


 * Remove an element in the live RAID:


 * Make a new md device with new drives and the old element:


 * Format and mount and migrate the data.
 * Boot on the new RAID device and verify everything is ok.
 * Stop the old RAID device:


 * Add the remaining old element to the new /dev/md1:


 * Watch the new RAID rebuild