HOWTO Migrate To RAID

From Gentoo Linux Wiki

Jump to: navigation, search
This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

Contents

This guide describes migrating an existing setup to software RAID. Please read and make sure you understand HOWTO Install on 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.
    • In particular, verify the rsync flags. Many people edit the rsync flags on this page and the original author has long ago given up restoring the flags.
  3. Make sure to use a recent enough kernel and raid tools (mdadm > 2.5).

[edit] Prerequisites

  • A BACKUP OF YOUR DATA.
  • RAID support must be compiled into the kernel (not as modules):
Linux Kernel Configuration: RAID settings
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)
  • 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 all

[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 disk drive 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

Note: 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.
Note: 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.

Warning: Do not forget to set all RAID partition types (except type 85, Linux extended) to hex value fd (Linux raid auto). 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.
Warning: 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] Setup & Activate new RAID partitions

Note: 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
  • Add a new entry into /boot/grub/grub.conf, setting "root=/dev/md0"
  • Add a RAID entry to /etc/mdadm.conf (retrieve the UUID by running mdadm -D /dev/md0)
# echo "ARRAY /dev/md0 UUID=deadbeef:deadbeef:deadbeef:deadbeef" >> /etc/mdadm.conf
  • Create the filesystem on the RAID. For example:
# mkreiserfs /dev/md0

[edit] Put data on new array

  • 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:
    • -a preserves most attributes
    • -H preserves hard links, maintaining space saving on the destination (takes longer)
    • -S tries to handle sparse files efficiently so they take less space on the destination (takes more CPU, sparse files are rarely used by programs)
    • -x restricts the sync to the source filesystem/partition (useful if you have used bind to multiply mount directories)
    • --progress shows progress of the command
    • -h output in human readable format
# rsync -avHhx --progress / /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 -avHhx --progress --delete / /mnt/raid-md0
  • Create needed device nodes:
# cd /mnt/raid-md0/dev/ && MAKEDEV generic
  • Modify /mnt/raid-md0/etc/fstab to make /dev/md0 the root partition.
  • Reboot.

[edit] Finalize RAID setup

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
Warning: 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'
Warning: 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 occur.


Now you may wish to jump across to HOWTO_Install_on_Software_RAID and setup

  • the bootloader on the new drive so it will be possible to boot from it if the first one fails,
  • the write intent bitmap
  • e-mail notification in /etc/mdadm.conf.

[edit] To RAID-5

Same as the migration process to RAID1. Modify 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 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