oreilly.comSafari Books Online.Conferences.


mdadm: A New Tool For Linux Software RAID Management

by Derek Vadala, author of Managing RAID with Linux

raidtools has been the standard software RAID management package for Linux since the inception of the software RAID driver. Over the years, raidtools have proven cumbersome to use, mostly because they rely on a configuration file (/etc/raidtab) that is difficult to maintain, and partly because its features are limited. In August 2001, Neil Brown, a software engineer at the University of New South Wales and a kernel developer, released an alternative. His mdadm (multiple devices admin) package provides a simple, yet robust way to manage software arrays. mdadm is now at version 1.0.1 and has proved quite stable over its first year of development. There has been much positive response on the Linux-raid mailing list and mdadm is likely to become widespread in the future. This article assumes that you have at least some familiarity with software RAID on Linux and that you have had some exposure to the raidtools package.


Related Reading

Managing RAID on Linux
By Derek Vadala

Download the most recent mdadm tarball, issue make install to compile, and install mdadm and its documentation. In addition to the binary, some manual pages and example files are also installed.

# tar xvf ./mdadm-1.0.1.tgz
# cd mdadm-1.0.1.tgz
# make install

Alternatively, you can download and install the package file found under the RPM directory at the same URL (

# rpm -ihv mdadm-1.0.1-1.i386.rpm

mdadm has five major modes of operation. The first two modes, Create and Assemble, are used to configure and activate arrays. Manage mode is used to manipulate devices in an active array. Follow or Monitor mode allows administrators to configure event notification and actions for arrays. Build mode is used when working with legacy arrays that use an old version of the md driver. I will not cover build mode in this article. The remaining options are used for various housekeeping tasks and are not attached to a specific mode of operation, although the mdadm documentation calls these options Misc mode.

Creating an Array

Create (mdadm --create) mode is used to create a new array. In this example I use mdadm to create a RAID-0 at /dev/md0 made up of /dev/sdb1 and /dev/sdc1:

# mdadm --create --verbose /dev/md0 --level=0 
        --raid-devices=2  /dev/sdb1 /dev/sdc1
mdadm: chunk size defaults to 64K
mdadm: array /dev/md0 started.

The --level option specifies which type of RAID to create in the same way that raidtools uses the raid-level configuration line. Valid choices are 0,1,4 and 5 for RAID-0, RAID-1, RAID-4, RAID-5 respectively. Linear (--level=linear) is also a valid choice for linear mode. The --raid-devices option works the same as the nr-raid-disks option when using /etc/raidtab and raidtools.

In general, mdadm commands take the format:

mdadm [mode] <raiddevice> [options] <component disks>

Each of mdadm's options also has a short form that is less descriptive but shorter to type. For example, the following command uses the short form of each option but is identical to the example I showed above.

# mdadm -Cv /dev/md0 -l0 -n2 -c128 /dev/sdb1 /dev/sdc1

-C selects Create mode, and I have also included the -v option here to turn on verbose output. -l and -n specify the RAID level and number of member disks. Users of raidtools and /etc/raidtab can see how much easier it is to create arrays using mdadm. You can change the default chunk size (64KB) using the --chunk or -c option. In this previous example I changed the chunk size to 128KB. mdadm also supports shell expansions, so you don't have to type in the device name for every component disk if you are creating a large array. In this example, I'll create a RAID-5 with five member disks and a chunk size of 128KB:

# mdadm -Cv /dev/md0 -l5 -n5 -c128 /dev/sd{a,b,c,d,e}1
mdadm: layout defaults to left-symmetric
mdadm: array /dev/md0 started.

This example creates an array at /dev/md0 using SCSI disk partitions /dev/sda1, /dev/sdb1, /dev/sdc1, /dev/sdd1, and /dev/sde1. Notice that I have also set the chunk size to 128 KB using the -c128 option. When creating a RAID-5, mdadm will automatically choose the left-symmetric parity algorithm, which is the best choice.

Use the --stop or -S command to stop running array:

# mdadm -S /dev/md0


/etc/mdadm.conf is mdadms' primary configuration file. Unlike /etc/raidtab, mdadm does not rely on /etc/mdadm.conf to create or manage arrays. Rather, mdadm.conf is simply an extra way of keeping track of software RAIDs. Using a configuration file with mdadm is useful, but not required. Having one means you can quickly manage arrays without spending extra time figuring out what array properties are and where disks belong. For example, if an array wasn't running and there was no mdadm.conf file describing it, then the system administrator would need to spend time examining individual disks to determine array properties and member disks.

Unlike the configuration file for raidtools, mdadm.conf is concise and simply lists disks and arrays. The configuration file can contain two types of lines each starting with either the DEVICE or ARRAY keyword. Whitespace separates the keyword from the configuration information. DEVICE lines specify a list of devices that are potential member disks. ARRAY lines specify device entries for arrays as well as identifier information. This information can include lists of one or more UUIDs, md device minor numbers, or a listing of member devices.

A simple mdadm.conf file might look like this:

DEVICE		/dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1
ARRAY		/dev/md0 devices=/dev/sda1,/dev/sdb1
ARRAY		/dev/md1 devices=/dev/sdc1,/dev/sdd1

In general, it's best to create an /etc/mdadm.conf file after you have created an array and update the file when new arrays are created. Without an /etc/mdadm.conf file you'd need to specify more detailed information about an array on the command in order to activate it. That means you'd have to remember which devices belonged to which arrays, and that could easily become a hassle on systems with a lot of disks. mdadm even provides an easy way to generate ARRAY lines. The output is a single long line, but I have broken it here to fit the page:

# mdadm --detail --scan
ARRAY /dev/md0 level=raid0 num-devices=2   \

If there were multiple arrays running on the system, then mdadm would generate an array line for each one. So after you're done building arrays you could redirect the output of mdadm --detail --scan to /etc/mdadm.conf. Just make sure that you manually create a DEVICE entry as well. Using the example I've provided above we might have an /etc/mdadm.conf that looks like:

DEVICE	/dev/sdb1 /dev/sdc1
ARRAY 	/dev/md0 level=raid0 num-devices=2	\             		  

Pages: 1, 2

Next Pagearrow

Linux Online Certification

Linux/Unix System Administration Certificate Series
Linux/Unix System Administration Certificate Series — This course series targets both beginning and intermediate Linux/Unix users who want to acquire advanced system administration skills, and to back those skills up with a Certificate from the University of Illinois Office of Continuing Education.

Enroll today!

Linux Resources
  • Linux Online
  • The Linux FAQ
  • Linux Kernel Archives
  • Kernel Traffic

  • Sponsored by: