Migrate to RAID

From Gentoo Linux Wiki

(Redirected from HOWTO Migrate To RAID)
Jump to: navigation, search
Please format this article according to the Style Guidelines and Wikification suggestions, then remove this notice {{Wikify}} from the article.

Reason(s):

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. CREATE A BACKUP BEFORE STARTING.
  2. Read the man page and understand each command before executing it.
  3. Make sure to use a recent enough kernel and raid tools (mdadm > 2.5).

Contents

[edit] Prerequisites

  • A BACKUP OF YOUR DATA.
  • RAID support must be compiled into the kernel (not as modules):
Device Drivers  --->
  Multi-device support (RAID and LVM)  --->
    [*] Multiple devices driver support (RAID and LVM)
    <*>   RAID support
      < >     Linear (append) mode (NEW)
      <*>     RAID-0 (striping) mode
      <*>     RAID-1 (mirroring) mode
      <*>     RAID-10 (mirrored striping) mode (EXPERIMENTAL)
      <*>     RAID-4/RAID-5/RAID-6 mode
      [*]       Support adding drives to a raid-5 array (NEW)
  • SCSI disk support must be also compiled into the kernel (not as modules). Even you will use SATA or PATA discs:
Device Drivers  --->
  SCSI device support  --->
    <*> RAID Transport Class
    -*- SCSI device support
    < > SCSI target support
        [*] legacy /proc/scsi/ support
    *** SCSI support type (disk, tape, CD-ROM) ***
    <*> SCSI disk support

  • Raid userland tool : emerge -av mdadm

If you wish to use genkernel, copy a kernel config file, with the above settings enabled, to /etc/kernels/kernel-config-x86-`uname -r`

  1. emerge -av device-mapper
  2. genkernel --dmraid all
  3. Add dodmraid to the kernel parameters in /boot/grub/grub.conf

1

[edit] 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, you can not simply enable RAID with a RAID superblock without data loss on top of an existing partition.

[edit] 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.

[edit] To RAID-1

If the system is very active, it should be placed in single user mode (telinit 1 from a running system, or boot with the single kernel parameter) or booted from LiveCD. |The guide will assume the current disk with data is /dev/sda and the new disk is /dev/sdb. Repeate the same instructions for all partitions.

[edit] Create partitions on new device

Copy the existing partition schema (if both disks are the same size):

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

Or create a new one with fdisk.

After either operation, run fdisk /dev/sdb and set all partition to type fd. Do not forget to set all RAID partition types to fd. You will receive no warning message from the RAID tools or the kernel if you fail to do so, and the raid will not get reassembled after rebooting. Do not set partition type to fd after you have already set up the raid. It is better to recreate the raid and copy the data again.

[edit] Set up RAID devices

If udev isn't active:

# cd /dev
# MAKEDEV md

If udev is active, set RC_DEVICE_TARBALL to "yes" in /etc/conf.d/rc to keep these devices after reboot. If the MAKEDEV command is missing install sys-apps/makedev and call it with /sbin/MAKEDEV

[edit] Activate new RAID partitions

In the following commands, replace /dev/md0 with the first free raid device (could be other than /dev/md0 if the data is currently on a different raid), and /dev/sdb1 with the correct partition.

  • Create the RAID:
# mdadm -C /dev/md0 -l 1 -n 2 missing /dev/sdb1
  • Create the filesystem on the RAID. For example:
# mkreiserfs /dev/md0
  • Create temporary mount points for the RAID partitions:
# mkdir /mnt/raid-md0
  • Mount the new RAID partition:
# mount /dev/md0 /mnt/raid-md0
  • Migrate the data (the -x flag forces rsync to stay on the same source partition when recursing through directories):
# rsync -avH --progress -x / /mnt/raid-md0
  • 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:

(--delete flag tells rsync to delete files from the destination which do not exist on the source):

# rsync -avH --delete --progress -x / /mnt/raid-md0
  • Modify /boot/grub/menu.lst and /etc/fstab to make /dev/md0 the root partition.
  • Reboot.

You should now be running with a degraded RAID on /dev/sdb1:

  • Verify the RAID is mounted:
# df
  • Verify the RAID status:
# cat /proc/mdstat

The following step destroys data on the old drive. Make sure the new system is behaving properly.

  • Copy the partition map from the new drive to the old drive:
# sfdisk -d /dev/sdb | sfdisk /dev/sda
  • Add the partitions to the live RAID:
# mdadm /dev/md0 -a /dev/sda1

You can watch the RAID rebuild with:

# watch -n1 'cat /proc/mdstat'

Do not reboot or power off the computer until the RAID has finished rebuilding. At best it will start from the beginning next boot. At worst some data loss may occurr.


  • 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 /etc/mdadm.conf.

[edit] To RAID-5

Same as the migration process to RAID1. Mofidy the create RAID command to use RAID-5 and to have additional partitions.

# mdadm -C /dev/md0 -l 5 -n 3 missing /dev/sdb1 /dev/sdc1

[edit] Expanding a RAID1 to more than 2 drives

Example scenario: If you wish to migrate your root partition to RAID5 and use grub 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 /dev/sda1 and /dev/sdb1 are mirrod on /dev/md0, add /dev/sdc1:

  • Add the partition as a spare:
# mdadm /dev/md0 -a /dev/sdc1
  • Grow the RAID-1 from 2 elements to 3:
# mdadm -G /dev/md0 -n 3
  • Observe the rebuild:
# watch -n .5 cat /proc/mdstat

[edit] Adding a drive to RAID

These instructions are for ending up with RAID-5.

[edit] 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.

[edit] Method 2 : Migrate as similar to above

If you are going from 2 to 3 drives then you can do something similar to the following:

  • Remove an element in your live RAID:
# mdadm /dev/md0 -f /dev/sdb1 -r /dev/sdb1
  • Make a new md device with new drives and the old element:
# cd /dev
# MAKEDEV md
# mdadm -C /dev/md1 -l 5 -n 3 missing /dev/sdb1 /dev/sdc1
  • Format and mount /dev/md1 and migrate your data.
  • Boot on your new RAID device and verified everything is ok.
  • Stop your old RAID device:
# mdadm -S /dev/md0
  • Add the remaining old element to your new /dev/md1:
# mdadm /dev/md1 -a /dev/sda1
  • Watch your new RAID rebuild
# watch -n .1 cat /proc/mdstat
Personal tools