Managing RAID on Linux - Derek Vadala [78]
ARRAY /dev/md0 devices=/dev/sdb1,/dev/sdc1,/dev/sdd1
Identification methods can be combined to place multiple conditions on what is required to activate an array. For example, you can combine a UUID with a RAID level and the number of member disks to further narrow the scope of an ARRAY line:
ARRAY /dev/md0 level=raid5 num-devices=6 UUID=6055c0b4:c3ec7631:c069b1fc:695acc70
In the previous example, /dev/md0 is a RAID-5 with six member disks and a UUID of 6055c0b4:c3ec7631:c069b1fc:695acc70. When mdadm -As /dev/md0 is executed, all of these conditions must be true, or the array will not be started.
The following example might be appropriate on a system that has a two-member IDE array at /dev/md0 and a six-member SCSI array, with the UUID ea3cb40f:b0bb05c1:b6525f1c:bf21268e at /dev/md1.
ARRAY /dev/md0 spare-group=home_directories \
super-minor=0 devices=/dev/hda1,/dev/hdb1
ARRAY /dev/md1 spare-group=home_directories \
UUID=ea3cb40f:b0bb05c1:b6525f1c:bf21268e \
devices=/dev/sda1,/dev/sdb,/dev/sdc
The arrays in the previous example both belong to the spare group home_directories. So mdadm will share spare disks between the two arrays as needed. Don't forget that DEVICE lines listing the member disks for each of these arrays also need to be included in your /etc/mdadm.conf file. For example:
DEVICE /dev/sd[a-z]1 /dev/hda /dev/hd?1
ARRAY /dev/md0 spare-group=home_directories \
super-minor=0 devices=/dev/hda1,/dev/hdb1
ARRAY /dev/md1 spare-group=home_directories \
UUID=ea3cb40f:b0bb05c1:b6525f1c:bf21268e \
devices=/dev/sda1,/dev/sdb,/dev/sdc
Once you have created /etc/mdadm.conf, you can easily assemble arrays without providing detailed information on the command line. The following example starts /dev/md0 based on its ARRAY entry in /etc/mdadm.conf:
# mdadm -As /dev/md0
MAILADDR lines
/etc/mdadm.conf should have only one MAILADDR line, which should contain a single email address. The address listed will receive email alerts from mdadm when it is invoked in monitor mode. For example:
MAILADDR derek@azurance.com
If you need to send alerts to more than one user, set up aliases in your mail transport agent. Using a MAILADDR line in /etc/mdadm.conf is not necessary, but it does mean that you can omit the --mail option on the command line when using mdadm in Monitor mode.
PROGRAM lines
The PROGRAM line specifies the name of a program or script to execute when an event is detected in monitor mode. This eliminates the need to provide a program name on the command line with --program in monitor mode. /etc/mdadm.conf should have only one PROGRAM line, containing the full pathname to execute. For example:
PROGRAM /usr/local/sbin/mymdalert.pl
Maintaining /etc/mdadm.conf
You should create /etc/mdadm.conf after you have built your first array and should update any time you create a new array. Add the DEVICE, MAILADDR, and PROGRAM entries by hand. ARRAY lines, however, can be added automatically by invoking mdadm. Combining -scan with either the --detail or --examine options causes mdadm to scan /proc/mdstat and generate an ARRAY line for any array it finds there:
# mdadm --detail --scan
ARRAY /dev/md0 level=raid0 num-devices=4 UUID=6055c0b4:c3ec7631:c069b1fc:695acc70
ARRAY /dev/md1 level=raid0 num-devices=2 UUID=930c4aaa:08c1fe3a:5c436830:3f4c5daa
The --detail option is useful to create ARRAY lines from active arrays. If an array is not currently active, invoke mdadm with the --examine and --scan options to scan all devices in /etc/mdadm.conf for RAID superblocks and then use the information to organize member disks and create ARRAY lines.
mdadm can also generate an ARRAY entry for one array at a time. To do this, just combine the --brief option with --examine or --detail and specify an md device or member disk on the command line:
# mdadm --detail --brief /dev/md0
# mdadm --examine --brief /dev/sda1
The first command looks at an active array (/dev/md0, in this case) and generates an ARRAY entry. The second command queries member disk /dev/sda1 and generates