Linux Software RAID

From MyWiki

Jump to: navigation, search

Software RAID is more flexible than hardware RAID, although it can be more complex to administer.

Linux uses the MD (Meta-Device) infrastructure, which creates a virtual block device, in software, out of physical devices. It can be used for much more than RAID, including, for example, simulating faulty hardware. Also, its RAID support is inherently flexible; there is no need for a backing device to be a disk, for example, or even for different backing devices to be of the same type. You could conceivably mirror RAID a local disk with a network storage service, for example.

This example is drawn from setting up two VM servers, running CentOS 5.1 (a free clone of RHEL 5.1). I suspect that other distributions support software RAID just as well.

Contents

RAID 1 for Boot

RAID 1 is uniquely useful for boot disks because if one disk fails, the other can still boot. For data, more complex schemes, such as 5 and 10, can provide performance and efficiency benefits.

Installation

When installing the OS, I created a custom disk partition scheme. I used RAID 1 (mirroring), since my main concern is simple, inexpensive reliability. For better performance, you can get more than 2 disks and do RAID 5. Software RAID also supports spare disks that can be used to replace a broken disk on the fly.

Here's a sample partition scheme:

  • sda
    • 100 MB: RAID partition (for boot)
    • Remaining: RAID partition (for /)
  • sdb: same as sda
  • RAID
    • 100 MB boot partition
    • Remaining: Put into LVM, and mount at /

Boot robustness

By default, only the first disk will have a master boot record (MBR). Install an MBR on the second disk so that if the first one fails, you can still run your machine on one disk, until you can get a replacement:

# grub
Probing devices to guess BIOS drives. This may take a long time.
...
grub> find /grub/stage1
(hd0,0)
(hd1,1)
grub> device (hd0) /dev/sdb
grub> root (hd0,0)
 Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd0)
 Checking if "/boot/grub/stage1" exists... no
 Checking if "/grub/stage1" exists... yes
 Checking if "/grub/stage2" exists... yes
 Checking if "/grub/e2fs_stage1_5" exists... yes
 Running "embed /grub/e2fs_stage1_5 (hd0)"...  15 sectors are embedded.
succeeded
 Running "install /grub/stage1 (hd0) (hd0)1+15 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.

Fault recovery

Repair the array with mdadm (after obtaining a spare disk, if necessary).

Cloning

Use a rescue disk and dd to clone machines. Note that when you boot from the rescue disk, you don't have mount your existing file system.

Caution: When you add disks to a machine, the order may change. Verify your dd target disks carefully; for example, you can check their partition tables with fdisk -l.

Alerts

Use mdadm to set up RAID alerts. It can email you when a disk fails, for example.

Personal tools