19.4.1 Creating Software RAID Devices

To create a software RAID device:

  1. Use the mdadm command to create the MD RAID device:

    # mdadm --create md_device --level=RAID_level [options] --raid-devices=N device ...

    For example, to create a RAID-1 device /dev/md0 from /dev/sdf and /dev/sdg:

    # mdadm --create /dev/md0 --level=1 -raid-devices=2 /dev/sd[fg]

    Create a RAID-5 device /dev/md1 from /dev/sdb, /dev/sdc, and dev/sdd:

    # mdadm --create /dev/md1 --level=5 -raid-devices=3 /dev/sd[bcd]

    If you want to include spare devices that are available for expansion, reconfiguration, or replacing failed drives, use the --spare-devices option to specify their number, for example:

    # mdadm --create /dev/md1 --level=5 -raid-devices=3 --spare-devices=1 /dev/sd[bcde]
    Note

    The number of RAID and spare devices must equal the number of devices that you specify.

  2. Add the RAID configuration to /etc/mdadm.conf:

    # mdadm --examine --scan >> /etc/mdadm.conf
    Note

    This step is optional. It helps mdadm to assemble the arrays at boot time.

    For example, the following entries in /etc/mdadm.conf define the devices and arrays that correspond to /dev/md0 and /dev/md1:

    DEVICE /dev/sd[c-g]
    ARRAY /dev/md0 devices=/dev/sdf,/dev/sdg
    ARRAY /dev/md1 spares=1 devices=/dev/sdb,/dev/sdc,/dev/sdd,/dev/sde

    For more examples, see the sample configuration file /usr/share/doc/mdadm-3.2.1/mdadm.conf-example.

Having created an MD RAID device, you can configure and use it in the same way as you would a physical storage device. For example, you can configure it as an LVM physical volume, file system, swap partition, Automatic Storage Management (ASM) disk, or raw device.

You can view /proc/mdstat to check the status of the MD RAID devices, for example:

# cat /proc/mdstat
Personalities : [raid1]
mdo : active raid1 sdg[1] sdf[0]

To display summary and detailed information about MD RAID devices, you can use the --query and --detail options with mdadm.

For more information, see the md(4), mdadm(8), and mdadm.conf(5) manual pages.