Creating a Software RAID in Linux

By Golden_Eternity
May 25, 2001  


If you're reading this, you probably already know that RAID is a Redundant Array of Inexpensive Disks, or as my Networking teacher used to call it a Redundant Array of Independent Disks (He didn't like the acronym suggesting that he hadn't paid a lot for those drives). It lets you use multiple disks to create one really large drive, or to create a fault-tolerant backup system in case of problems with one disk. If you want to know more about the various kinds of RAID, check out the Software RAID HOWTO on page 2

This document assumes you already know what kind of RAID you want to put together, that you have installed the raidtools package (I used version 0.90, which came with Red Hat 7.0), and that you already have the drives installed properly. 

I'm not going to bother much with disclaimers, but let me say this... If you have anything on the disks you want to use for your RAID, back it up now or you will lose it. Also, be aware that RAID on Linux is still in development; the raidtools are still an alpha release.

Note that initializing RAID devices destroys all of the
data on the consituent devices
.
                               - mkraid man page, mkraid(8)

First, you need to make sure your kernel has multi-device (MD) support. If you built your own kernel, scan through .config for CONFIG_MD and the RAID options that immediately follow. If your kernel came with your distribution, it may or may not be supported, and you may need to recompile. Kernels lower than 2.2 need to be specially patched to support RAID.

# Multi-device support (RAID and LVM)
#
CONFIG_MD=y
CONFIG_BLK_DEV_MD=y
# CONFIG_MD_LINEAR is not set
# CONFIG_MD_RAID0 is not set
CONFIG_MD_RAID1=y
# CONFIG_MD_RAID5 is not set
# CONFIG_BLK_DEV_LVM is not set

Next, you need to set up your raidtab file. You should hopefully have some sample scripts that came with your version of raidtools. If that is the case, then your work is largely done for you. Copy the file to /etc/raidtab and make any changes needed. The Software RAID HOWTO page 4 has information on how to set up your raidtab.

The following example is for a RAID 1 using drives /dev/hdb1 and /dev/hdc1 as mirrors.

# Sample raid-1 configuration
raiddev /dev/md0
raid-level 1
nr-raid-disks 2
nr-spare-disks 0
chunk-size 4

device /dev/hdb1
raid-disk 0

device /dev/hdc1
raid-disk 1

If the raidtab file is set up properly all you need to do is run mkraid.

mkraid /dev/md0

Once the raid is started, you may want to format the drive. Slight variations in disk size can produce problems when it comes time to write to the disk; creating a new filesystem on the RAID device will take care of this.

    mke2fs /dev/md0

You should now have a working RAID.