Mdadm uses the md driver. Because of its various modes and a single tool, it does not depend on all the settings files. It is a good tool to replace raidtools. Currently, this tool is used in almost all releases.
I. Installation and compilation
Download source code:
Http://www.cse.unsw.edu.au /~ Neilb/source/mdadm/
Compile:
Tar xzvf./mdadm-1.6.0.tgz
Cd mdadm-1.6.0
Make install
Rpm installation:
Rpm-ivh mdadm-1.6.0-3.rpm
※The latest source code version is 2.5. Because I use the 1.6.0 rpm package, this version is used as an example.
Ii. Mode
Mdadm has six modes, the first two modes: Create and Assemble are used to set and activate the array; Manage mode is used to operate the devices in the active array; in Follow or Monitor mode, Administrators are allowed to set event reminders and actions for the active array. In Build mode, the old version of the md driver is used for the old array. In addition, the Grow mode can be used to expand the array; the rest is the Misc mode, which includes operations on a variety of internal tasks and operations that do not specify a special mode.
System Platform: Red Hat AS4 for x86
Iii. Deployment
1. Prepare a disk
An array can only be composed of disks in Sofware RAID format. Therefore, we must first make the disk format ready. As mentioned above, apart from the system disk sda, we need to perform operations on sdb, sdc, and sdd.
A) Partition sdb
Fdisk/dev/sdb
N, partition:
P, partition:
W, write and exit:
2. Create an array
Mdadm supports array modes of LINEAR, RAID0 (striping), RAID1 (embedding ing), RAID4, RAID5, RAID6, and MULTIPATH.
The command creation format is as follows:
Mdadm [mode] [options]
For example, create a RAID 0 device:
Mdadm -- create -- verbose/dev/md0 -- level = 0 -- raid-devices = 3/dev/sdb1/dev/sdc1/dev/sdd1
-- Level indicates the created array mode, and -- raid-devices indicates the number of parameters and arrays.
It can also be expressed like this, meaning the same:
Mdadm-Cv/dev/md0-l0-n3/dev/sd [bcd] 1
You can also add the-c128 parameter to specify the chunk size as 128 K (64 K by default)
3. Set the file
Mdadm does not use/etc/mdadm. conf as the main setting file. It does not depend on the file and does not affect the normal operation of the array.
This setting file is mainly used to facilitate the tracking of Soft RAID settings. Setting the setting file is advantageous, but not necessary.We recommend that you set this file.
Generally, we can establish it like this:
Echo DEVICE/dev/sd [bcd] 1>/etc/mdadm. conf
Mdadm-Ds>/etc/mdadm. conf
Mdadm -- detail -- scan>/etc/mdadm. conf
4. format the Array
In the future, you only need to use/dev/md0 as an independent device for operations:
Mkfs. ext3/dev/md0
Mkdir/mnt/test
Mount/dev/md0/mnt/test
5. To enable automatic mounting, add it to/etc/fstab:
/Dev/md0/mnt/tes auto defaults 0 0
Iv. Monitoring and Management
Mdadm can easily monitor and manage the array, and also include common maintenance such as stopping and starting the array.
1. View
Cat/proc/mdstat
You can view the status of all arrays using the md DRIVER:
Mdadm -- detail/dev/md0
View detailed information of the specified array (-D ):
2. Stop
Mdadm-S/dev/md0
Stop the specified array and release the disk (-- stop ):
※Note: After the disk is stopped, the disk of the original array is idle. Once these disks are operated, the original array cannot be restarted.
3. Start
Mdadm-A/dev/md0/dev/sd [bcd] 1
To start a specified array, you can also consider assembling a new array into the system (-- assemble ):
If you have set the/etc/mdadm. conf file on it, you can also use-s to find it:
Mdadm-As/dev/md0
4. Test
If you have not set the/etc/mdadm. conf file and forget that a disk belongs to the array, you can use the detection: (-- examine)
Mdadm-E/dev/sdb1
After obtaining the UUID, the array can also be activated as follows:
Mdadm-Av/dev/md0 -- uuid = 8ba81579: e20fb0e8: e040da0e: f0b3fec8/dev/sd *
As you can see, as long as the disk is not damaged, the Assembly is very convenient:
5. add and delete Disks
In Manage mode, mdadm can add or delete disks to and from running arrays. It is often used to identify failed disks, add spare (redundant) disks, and replace disks.
For example, the original status is:
You can use -- fail to specify the bad disk, and -- remove:
Mdadm/dev/md0 -- fail/dev/sdc1 -- remove/dev/sdc1
※Note that -- fail and -- remove cannot be used for some array modes, such as RAID0.
Add a new array Disk
Mdadm/dev/md0 -- add/dev/sdc1
※Note that -- add cannot be used for some array modes, such as RAID0.
6. Monitoring
In the Follow or Monitor status, you can use mdadm to Monitor the array. For example, if an array is faulty, send an email to the Administrator; or, if the disk is faulty, replace the disk automatically.
Nohup mdadm -- monitor -- mail = sysadmin -- delay = 300/dev/md0 &
The preceding definition: if the monitoring time is not 300 seconds, an error occurs in the array and an email is sent to the sysadmin user. Since the monitor does not automatically exit after it is started, you need to add nohup and & to keep it running in the background.
In Follow mode, redundant disks can be shared.
For example, we have two Arrays:/dev/md0 and/dev/md1, And/dev/md0 has a spare disk. When we define something similar in/etc/mdadm. conf:
DEVICE/dev/sd *
ARRAY/dev/md0 level = raid1 num-devices = 3 spare-group = databa Se
UUID = 415a299e: 4cdd535e: 169d3df4: 48b7144a
ARRAY/dev/md1 level = raid1 num-device = 2 spare-group = databa Se
UUID = 59b6e564: 739d4d28: ae0aa308: 71147fe7
That is, to define a spare-group. And run the above monitor mode command. In this way, when one of the disks in/dev/md1 is faulty, mdadm will automatically remove the spare disk from/dev/md0 and add it to/dev/md1, without human intervention . (Note that this can be achieved only when the array supports redundancy, such as raid1 and raid5. Array modes such as raid0 are invalid)
V. Others
1. Add a spare disk.
You can specify a redundant disk when creating the disk:
Mdadm-Cv/dev/md0-l1-n2-x1/dev/sd [bcd] 1
The-x (-- spare-devices) parameter is used to specify the number of redundant disks. Result:
In addition, for full arrays (for example, RAID1 of two existing disks), The-add parameter is directly used, and mdadm automatically uses the redundant disk as the spare disk.
2. delete an array
Mdadm-S/dev/md0
Or
Rm/dev/md0
Modify/etc/mdadm. conf,/etc/fstab, and delete the related files;
Finally, use fdisk to repartition the disk.
3. Rebuild the Array
We can also use it without fdisk, but currently there are no disks belonging to all arrays into the new array: