mdadm --create mddevice [options] memberdevices mdadm --build mddevice [options] memberdevices
The Create and Build modes are similar in that they are both used to create new arrays.
However, Build mode is used only for backward compatibility, to create legacy arrays without a RAID superblock. Never use Build mode to create a new array.
Options -C, --create
Creates a new array.
-B, --build
Creates an old-style array without a RAID superblock.
-c, --chunk=
Sets the arraychunk-sizein kilobytes. Thechunk-sizeis a power of two between 4 and 4096. For example, -c128 or --chunk=128 sets achunk-sizeof 128 KB. The default is 64 KB.
--rounding=
Sets the rounding factor, which linear mode uses to align I/O operations. The rounding factor is similar tochunk-size, with the exception that it does not distribute operations across multiple disks. The default value of 64 KB should be fine for most users. The same rules that apply tochunk-sizeapply to rounding (for example, --rounding=8 for 8 KB rounding).
-l, --level=
Specifies the RAID level: linear, RAID-0, RAID-1, RAID-4, or RAID-5. For Build mode, only linear and RAID-0 are supported. For example, type -l5 or --level=5 for RAID-5.
-p, --parity=, --layout=
Sets the parity algorithm for RAID-5. The parity algorithmoptions are left-asymmetric, right-asymmetric, left-symmetric, or right-symmetric. The best choice is left-symmetric (which is also the default). Choices may also be abbreviated as la, ra, ls, and rs. Exam-ples include -pls, --parity=left-symmetric, or --layout=left-symmetric.
-n, --raid-disks=
Defines the number of member disks in an array. This is equivalent tonr-raid-disks when working with /etc/raidtab and raidtools. Likenr-raid-disks, it does not include spare disks. For example, type -n5 or --raid-disks=5 for five member disks.
-x, --spare-disks=
Defines the number of spare disks in an array (equivalent to nr-spare-disksin /etc/
raidtab). For example, enter -x1 or --spare-disks=1 for a single spare disk.
-z, --size=
Manually sets the size in kilobytes of member disks in a RAID-1, RAID-4, or RAID-5.
By default, the size is automatically computed by mdadm. The --size must be a multiple of the --chunk-size and must leave at least 128 KB at the end of each device for the RAID superblock. This is useful when working with disks of varying sizes. It’s also useful if the sizes of your disks are incorrectly calculated. For example, with a chunk size of 64 KB, -z16000 or --size=16000 sets the size of each component disk to 1 GB (64 KB * 16,000).
-f, --force
Normally when a RAID-5 is created, mdadm builds the array with a missing disk and then inserts the remaining disk into the array. This induces recovery, instead of the slower resynchronization process. The --force option causes mdadm to create an array the traditional way, using resynchronization instead of recovery to initialize the array.
--run
Starts the array even if mdadm detects problems. Using --run will prevent mdadm from requiring confirmation for potentially dangerous operations. For example, if mdadm detects an existing filesystem or RAID superblock on a member disk, --run will none-theless force the array online, possibly destroying data.
--readonly
Starts the new array as read-only.
Example usage
All --create and --build operations must contain at least --raid-disks and --level options. The following creates a RAID-0 at /dev/md0 with a chunk-size of 128 KB and two member disks.
# mdadm --create /dev/md0 --level=0 --chunk=128 --raid-disks=2 /dev/sda1 /dev/sdb1 The following commands use the short form of mdadm to create a four-disk RAID-0 at /dev/
md1. We don’t need to specify thechunk-size because the defaultchunk-sizeof 64 K is what we want.
# mdadm -C /dev/md1 -l0 -n4 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1
The list of component disks can be abbreviated using standard shell expansions. Consult the manual pages for the particular shell you use to be sure you are using the proper semantics. I use the Bourne-again shell (bash).
# mdadm -C /dev/md1 -l0 -n4 /dev/sd[a-d]1
# mdadm -C /dev/md1 -l0 -n4 -c64 /dev/sd{a,b,c,d}1
The three previous examples are equivalent. The list of devices is expanded from left to right, so /dev/sda1 becomes the first member disk in the array and /dev/sdd1 becomes the last.
Linear mode uses a rounding factor instead of achunk-size. This command creates a linear mode array with two disks and a rounding factor of 128 KB:
# mdadm -C /dev/md0 -llinear -n2 --rounding=128 /dev/hd{a,b}1 RAID-1 does not require achunk-size:
# mdadm -C /dev/md0 -l1 -n2 /dev/sd{a,b}1
RAID-5 can take both both achunk-sizeand a parity algorithm. The following example creates a five-disk RAID-5 at /dev/md0, using achunk-sizeof 128 KB and the left-symmetric algorithm:
# mdadm -C /dev/md0 -l5 -c128 -pls -n5 /dev/sd[a-e]1
By default, RAID-5 will automatically choose the left-symmetric parity algorithm, and all levels that use striping default to a 64 KBchunk-size. So you don’t need to specify either option on the command line if the defaults meet your needs.
Use the -x option to specify spare disks for arrays that support redundancy. In this example, a RAID-1 is created at /dev/md0 with /dev/sda1 and /dev/sdb1 as its member disks.
/dev/sde1 is a spare disk. The last disk listed on the command line becomes the spare disk.
# mdadm -C /dev/md0 -l1 -n2 -x1 /dev/sd{a,b,e}1
RAID-5 can also use spare disks. Normally, the last disk listed on the command line becomes a spare disk (or the last two disks, if you specified -x2, and so on). However, because of the way that mdadm creates a RAID-5, this isn’t always the case. I mentioned in earlier chapters that resynchronization occurs when an array is initialized and that recovery occurs when an array rebuilds after being in degraded mode. Under RAID-5, recovery is faster than resynchronization, so mdadm attempts to force recovery mode to synchronize disks, rather than using the slower resynchronization process.
To facilitate this, mdadm creates an array with N-1 member disks and X+1 spare disks, as specified by the--raid-disks(-n) and--spare-disks(-x) options. The kernel then initiates recovery when it notices the array is degraded and inserts one of the spare disks into the array. In the following example, a five-disk RAID-5 with one spare disk is created at /dev/
md0. /dev/sdf1 becomes the spare disk because mdadm assembles the array using the first four disks and then inserts the last (/dev/sdf1) of the two spare disks. This induces recovery, and /dev/sde1 becomes the only remaining spare disk.
# mdadm -C /dev/md0 -l5 -n5 -x1 /dev/sd{a,b,c,d,e,f}1
To force mdadm to initialize a RAID-5 using resynchronization instead of recovery, while honoring the device order at it appears on the command line, use the --force or -f option:
# mdadm -C /dev/md0 -f -l5 -n5 -x1 /dev/sd{a,b,c,d,e,f}1 mdadm can also create hybrid arrays:
# mdadm -C /dev/md0 -l1 -n2 -x1 /dev/sd{a,b,c}1
# mdadm -C /dev/md1 -l1 -n2 -x1 /dev/sd{d,e,f}1
# mdadm -C /dev/md2 -l0 -c64 -n2 /dev/md{0,1}
This example creates two mirroring arrays, each with a spare disk (/dev/md0 and /dev/md1).
The third command combines both of these arrays into a RAID-0 with achunk-sizeof 64 KB.