Creating Software RAID Devices using mdadm
-
Run the mdadm command to create the MD RAID device as follows:
sudo mdadm --create md_device --level=RAID_level [options] --raid-devices=Ndevices
- md_device
-
Name of the RAID device, for example,
/dev/md0
. - RAID_level
-
Level number of the RAID to create, for example,
5
for a RAID-5 configuration. - --raid-devices=N
-
Number of devices to become part of the RAID configuration.
- devices
-
Devices to be configured as RAID, for example,
/dev/sd[bcd]
for 3 devices for the RAID configuration.The devices you list must total to the number you specified for
--raid-devices
.
This example creates a RAID-5 device
/dev/md1
from/dev/sdb
,/dev/sdc
, anddev/sdd
:sudo mdadm --create /dev/md1 --level=5 --raid-devices=3 /dev/sd[bcd]
The previous example creates a RAID-5 device
/dev/md1
out of 3 devices. We can use 4 devices where one device is configured as a spare for expansion, reconfiguration, or replacement of failed drives:sudo mdadm --create /dev/md1 --level=5 -raid-devices=3 --spare-devices=1 /dev/sd[bcde]
-
(Optional) Add the RAID configuration to
/etc/mdadm.conf
:sudo mdadm --examine --scan | sudo tee -a /etc/mdadm.conf
Based on the configuration file, mdadm assembles the arrays at boot time.
For example, the following entries 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/mdadm.conf-example
.
An MD RAID device is used in the same way as any physical storage device. For example, the RAID device can be configured as an LVM physical volume, a file system, a swap partition, an Automatic Storage Management (ASM) disk, or a raw device.
To check the status of the MD RAID devices, view
/proc/mdstat
:
cat /proc/mdstat
Personalities : [raid1] mdo : active raid1 sdg[1] sdf[0]
To display a summary or detailed information about MD RAID devices, use the --query or --detail option, respectively, with mdadm.
For more information, see the md(4)
,
mdadm(8)
, and
mdadm.conf(5)
manual pages.