Complete Handbook/Software RAID

From Gentoo Wiki
Jump to: navigation, search
This article is a stub. You can help Gentoo Wiki by expanding it.

Software RAID


Redundant Array of Inexpensive Disks (RAID) is a technology to combine multiple disks in order to improve their reliability and/or performance. There is hardware RAID, implemented by the controller on your motherboard or specific extension cards, and there is software RAID, implemented by the kernel.

Be aware that a reliable RAID does not remove the need for regular backups!

Advantages of RAID

The main advantages of RAID are reliability and/or performance improvements.

There are vast differences between soft- and hardware RAID. Differences include: cost (monetarily), performance, overhead and flexibility. Of course software RAID comes cheapest. Another advantage of soft- over hardware RAID is that you can easily move you RAID set to another (Linux) computer. With hardware RAID you will depend on the Vendor.

Disadvantages of RAID

RAID usually takes more disk space then it delivers. E.g. a RAID-1 set of 2 3TB disks delivers a 3TB RAID disk (a reduction of 50%).

  • The time it takes to synchronize you RAID disk (initially and when they need to rebuild).
  • The extra effort to manage and monitor your RAID disks. To make full use of software raid, you need to learn about disk failures so you don't end up loosing two disks from your 3 disk RAID-5 just because you don't notice failure of the first one.

Setting up Software RAID

Installing the Tools

Start with the kernel configuration. After all, the kernel does most of the work:

[*] Device Drivers  --->
    <*> Multiple devices driver support (RAID and LVM)
        <*> RAID support
            [*] Autodetect RAID arrays during kernel boot

            If you want to combine multiple disks or partitions to one (bigger) device:
                <*> Linear (append) mode

            If you want to increase IO performance by striping data across multiple disks (at the expense of reliability):
                <*> RAID-0 (striping) mode

            If you want to increase reliability by mirroring data across multiple disks (at the expense of less storage capacity):
                <*> RAID-1 (mirroring) mode

            If you want to combine the previous two options (for whatever reason):
                <*> RAID-10 (mirrored striping) mode

            If you want to combine 3 or more disks for reliability and performance:
                <*> RAID-4/RAID-5/RAID-6 mode

Get the proper RAID admin tool:

root #emerge mdadm

Make sure your RAID disks are started and stopped:

root #rc-update add mdraid boot

Using Software RAID

To create a simple mirrored disk, make sure you have two partitions that have the same size and bring them together in your first RAID-1 disk:

root #mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdd1 /dev/sde1

The disks in the mirror will now be synchronized (also when there is no data or file system yet). you can check the status like this:

user $cat /proc/mdstat
Personalities : [raid1] 
md1 : active raid1 sde2[1] sdd2[0]
      1900953472 blocks super 1.2 [2/2] [UU]
      [======>..............]  resync = 31.6% (600768512/1900953472) finish=819.4min speed=26444K/sec
md0 : active raid1 sde1[1] sdd1[0]
      52395904 blocks super 1.2 [2/2] [UU]
unused devices: <none>

Create a filesystem of choice:

root #mkfs.ext4 /dev/md0

Start using the RAID!

Software RAID for Root File System

Boot Using GRUB 2.x

When using GRUB 2.x and the root file system is located on a software RAID, add the domdadm parameter to the Kernel parameters in /etc/default/grub

FILE /etc/default/grub

Managing Software RAID

Adding Disks

To add a new disk to the software RAID, issue this command:

root #mdadm /dev/md0 --add /dev/sdd1

If the RAID has healthy members, the new disk will be added as spare disk (S).

Removing Disks

First determine the disk to be removed.

root #cat /proc/mdstat
md0 : active raid1 sdd1[1](F) sde1[0]
      32000 blocks [2/1] [U_]
      bitmap: 0/4 pages [0KB], 4KB chunk

As you can see, there sdd1 marked as failed (F) and RAID missing one of disks [U_]. To remove the failed drive execute following command:

root #mdadm /dev/md0 --remove /dev/sdd1

Physically replace the (sdd) disk or add blank space from another attached location.

Sometimes you may need remove healthy member. For this you need to mark drive as failed then remove it from the software RAID set. Perform this action all in one command:

root #mdadm /dev/md0 --fail /dev/sdd1 --remove /dev/sdd1

Changing RAID Layout

In some cases it is necessary to change the RAID layout. An example case would be when adding disks to a RAID1 or converting a RAID1 to a RAID5.

See Also

External Resources