Mdadm management software raid Array

Source: Internet
Author: User

The mdadm Program is an independent program that can complete all the software raid management functions. It mainly has seven usage modes:
Mode name Main Functions
Create creates a new Array Using idle devices. Each device has metadata blocks.
Assemble assembles each block device that originally belongs to an array into an array.
Build creates or assembles arrays without metadata. Each device has no metadata block.
Manage manages devices that have already stored arrays, such as adding a hot backup disk or setting a disk to fail, and then deleting the disk from the array.
Misc reports or modifies the information of related devices in the array, such as querying the status information of the array or device.
Grow changes the capacity used by each device in the array or the number of devices in the array
Monitor monitors one or more arrays and reports specified events.

 

 

 

Partitioning a disk
If the MD driver is compiled into the kernel, when the kernel calls the execution of the MD driver, it will automatically find the disk in the FD (Linux raid autodetect) format. Therefore, fdisk is usually used to partition the HD disk or SD disk, and then set the FD disk.
If the MD driver is loaded as a module, the user-layer script needs to control the raid array startup and running during system operation. Such as/etc/rc in the system. d/RC. the sysinit file contains commands to start the raid array. If the raid configuration file mdadm. if conf exists, call mdadm to check the first item in the configuration file and then start the raid array.

Create a new array
Mdadm uses the -- create (or its abbreviation-C) parameter to create a new array, and some important array identification information as metadata can be written in the specified interval of each underlying device.
-- Level (or its abbreviation-l) indicates the raid level of the array. -- chunk (or its abbreviation-C) indicates the size of each band unit, in KB. The default value is 64kb, the size of the stripe unit has a great impact on the array read/write performance under different loads. -- Raid-devices (or its abbreviation-N) indicates the number of active devices in the array, and -- spare-devices (or its abbreviation-x) indicates the number of hot spare disks in the array, once a disk in the array fails, the MD kernel driver automatically adds the hot backup disk to the array and reconstructs the lost data on the disk to the hot backup disk.

 

 

 

Create a raid0 Device
Mdadm -- create/dev/md0 -- level = 0 -- chunk = 32 -- raid-devices = 3/dev/SD [I-K] 1

 

 

Create a raid1 Device
Mdadm-C/dev/md0-L1-c128-N2-x1/dev/SD [I-K] 1

Create a RAID5 device:
Mdadm-C/dev/md0-L5-N5/dev/SD [C-G] 1-x1/dev/SDB

Create a raid10 Device
Mdadm-C/dev/md0-L10-N6/dev/SD [B-G]-x1/dev/sdh1

Create a raid0 + 1 Device
Mdadm-C/dev/md0-L1-N2/dev/sdb1/dev/sdc1
Mdadm-C/dev/md1-L1-N2/dev/sde1/dev/sdf1
Mdadm-C/dev/md2-L1-N2/dev/sde1/dev/sdg1
Mdadm-C/dev/md3-l0-N3/dev/md0/dev/md1/dev/md2

 

After RAID 1/5/10 is created successfully, you need to calculate the checksum information of each strip and write it to the corresponding disk. Therefore, the raid array has a redundant data synchronization initialization process (Resync ). However, after the MD device is created successfully, it can be read and written by the upper-layer primary application. Of course, the performance of data synchronization is reduced due to the upper-layer data reading and writing. The initialization duration is related to the disk array performance and read/write application load. You can use CAT/proc/mdstat to query the current reconstruction speed and expected completion time of the raid array.
If a block device is already in use by another MD device or file system, you cannot create a new MD device. The following situations may occur:
Mdadm-C/dev/md1-l0-N2/dev/sdh1/dev/sdi1
Mdadm: cannot open/dev/SDH: device or resource busy
Mdadm: Create aborted

The build mode can be used to create raid0/1 devices without metadata. You cannot create raid 4/5/6/10 or other MD devices with redundancy levels.
Mdadm-Br/dev/md0-l0-N6/dev/SD [B-G] 1
Mdamd-Br/dev/md0-L1-N2/dev/SD [B-c] 1

Use arrays and stop running Arrays
The MD device can be read and written as a normal device, or formatted as a file system.
# Mkfs. ext3/dev/md0
# Mkdir-P/mnt/MD-test # Mount/dev/md0/mnt/MD-test

If the array does not have a file system or other storage applications and advanced devices, you can use-stop (or its abbreviation-S) to stop the array. If the command returns an error of the busy type of the device or resource, note:/dev/md0 is being used by upper-layer applications and cannot be stopped temporarily. You must stop upper-layer applications first, so that data consistency on the array is also possible.
# Umount/dev/md0

# Mdadm-Stop/dev/md0

Assemble a previously created Array
Mode-assemble or its abbreviation (-a) mainly checks the metadata information of the underlying device and then assembles it into an active array. If we already know that the array is composed of those devices, we can specify those devices to start the array.
Mdadm-A/dev/md0/dev/SD [D-H] 1
If you have a configuration file (/etc/mdadm. conf), run the mdadm-as/dev/md0 command.

Mdadm first checks the device information in mdadm. conf, then reads the metadata information from each device, and checks whether the information is consistent with the array information. If the information is consistent, it starts the information. If/etc/mdadm is not configured. CONF file, and the array is composed of those disks, you can use the command -- examine (or its abbreviation-E) to check whether the current block device has the metadata information of the array.

Configuration File
/Etc/mdadm. conf is the default configuration file. It is mainly used to track RAID configurations, especially to configure monitoring and event reporting options. The Assemble command can also use -- config (or its abbreviation is-C) to specify the configuration file. You can run the following command to create a configuration file.
# Echo device/dev/SD [B-H] 1/dev/SD [I-K] 1>/etc/mdadm. conf
# Mdadm-DS>/etc/mdadm. conf
# Cat/etc/mdadm. conf
When an array is started using the configuration file, mdadm queries the device and array content in the configuration file, and then starts running all the raid arrays that can run. If the device name of the array is specified, only the corresponding array is started.

 

Query the array status
We can use CAT/proc/mdstat to view the status of all running raid arrays. We can also use the mdadm command to view the brief information of the specified array (using -- query or its abbreviation-Q) and details (use -- detail or its abbreviation-d) details include RAID version, creation time, raid level, array capacity, available space, data quantity, super block status, Update Time, UUID information, status of each device, raid Algorithm level type, layout mode, block size, and other information. Device status information includes active, sync, spare, faulty, rebuilding, and removing.
# Mdadm -- Query/dev/md0

Management Array
In manage mode, mdadm can add or delete disks to and from running arrays. It is often used to identify failed disks, add spare (hot backup) disks, and remove expired disks from the array. Use-faill (or its abbreviation-F) to specify that the disk is damaged.
# Mdadm/dev/md0-fail/dev/sdb1
When the disk is damaged, use the-removie (or its abbreviation-f) parameter to remove the disk from the disk array. However, if the device is still being used by the array, it cannot be removed from the array.
# Mdadm/dev/md0-Remove/dev/sdb1
If the array has a spare disk, the damaged data on the disk is automatically reconstructed to the new spare disk. If the array does not have a hot backup disk, you can use-add (or its abbreviation is-) add hot backup disk
Mdadm/dev/md0-Add/dev/SDH

Extended Array
If you do not want to use the entire block device when creating an array, you can specify the size of the device used to create a raid array for each block device.
Mdadm-Cr/dev/md0-L5-N6/dev/SD [B-G] 1x1/dev/SDH-size = 102400
Then, when the array needs to be extended, use the mode-grow (or its abbreviation-g) and-size parameters (or its abbreviation-Z) by adding a proper size value, you can expand the size of each device used by the array.
Mdadm also provides the ability to increase or decrease the number of devices in the array. The mode-grow and-raid-Disks (or its abbreviation-N) parameters are used with the appropriate number of devices. After expansion, the original hot spare disk in the array becomes an active disk, so the number of devices in the array increases and the size of the array increases accordingly.
# Mdadm-grow/dev/md0-raid-Disks = 7

 

Raid0
Add Hard Disk
The members of a RAID device are hard disk partitions. You must first partition the hard disk. the partitions cannot be on the same physical hard disk.
# Fdisk/dev/sdb n: Create a primary partition, T: partition type FD, W: Write: Save
# Fdisk/dev/SDC
# Mdadm-CV/dev/md0-l0-N2/dev/sdb1/dev/sdc1
-C, -- create creates a new array-V, verbose displays details
/Dev/md0 Array Device name-L, -- level = array level, for example, 0, 1, 4, 5, 6
-N, -- raid-devices = number of array activities
/Dev/SD [BC] 1 List of devices included in the array
# More/proc/mdstat view the array status
# Mkfs. ext3/dev/md0 create a file system
# Mount/dev/md0/mnt/raid
Enable automatic mounting, modify/etc/fstab, and add/dev/md0/mnt/raid ext3 defaults 0 0

RAID5 Fault Simulation
A raid 5 device md0 has been created.
# Mdadm-CV/dev/md0-L5-N3-x1-c128/dev/SD [B, c, d, e] 1
1. Mark/dev/sdb1 as a damaged device.
# Mdadm/dev/md0-F/dev/sdb1
At this time, the array begins to reconstruct and restore data.
View corrupt information CAT/proc/mdstat F indicates bad
2. Remove the damaged device.
# Mdadm/dev/md0-r/dev/sdb1
3. Add new devices to the array
Note: 1. Partition the hard disk correctly, and 2. Add the device name to be consistent with the removed device name, for example, sdb1.
# Mdadm/dev/md0-A/dev/sdb1
Generate the configuration file/etc/mdadm. conf
The format is as follows:
Device/dev/sdb1/dev/sdc1/dev/sdd1/dev/sde1
Array/dev/md10 level = raid10 num-devices = 4
UUID = 12334343 dkfj
The UUID information is obtained through # mdadm-D/dev/md10.
# Mdadm-Ds scan the File Information

 

 

 

Other:

1. Add five new disks to the Virtual Machine
2. fdisk/dev/SDB, add three 1g partitions and set the type to FD (Linux raid autodetect)
3. dd If =/dev/SDB of =/dev/sdx BS = 1024 COUNT = 1 (copy the Partition Table of SDB to another disk)
Fdisk/dev/sdx and save it by W (otherwise, the device files in the/dev/sdxx partitions do not exist)
4. Create a raid0
Mdadm-C/dev/md0-l0-N2/dev/sdb1/dev/sdc1
Disable md0
Mdadm-S/dev/md0
Enable md0
Mdadm-A/dev/md0/dev/sdb1/dev/sdc1
5. Create raid1
Mdadm-C/dev/md1-L1-N2/dev/sdb2/dev/sdc2
CAT/proc/mdstat
Personalities: [raid0] [raid1]
Md1: Active raid1 sdc2 [1] sdb2 [0]
987904 blocks [2/2] [UU]
Md0: Active raid0 sdb1 [0] sdc1 [1]
1975680 blocks 64 K chunks
Unused devices: <none>
Format and mount. If/dev/md1 is mounted, change the disk.
Mdadm/dev/md0-F/dev/sdb2 (set sdb2 to fail)
Mdadm/dev/md0-r/dev/sdb2 (remove sdb2)
Mdadm/dev/md0-A/dev/sdb3 (add sdb3)
CAT/proc/mdstat
6. Create RAID5
Mdadm-C/dev/MD5-L5-N3/dev/sdd1/dev/sde1/dev/sdf1-x1/dev/sdc3
Mdadm/dev/MD5-F/dev/sdd1
Mdadm/dev/MD5-r/dev/sdd1
CAT/proc/mdstat (automatically add sdc3 to RAID5)
Mdadm/dev/MD5-A/dev/sdd1 (sdd1 becomes a hot backup disk)
7. Save all configurations
Echo device/dev/SD * [1-9]>/dev/mdadm. conf
Mdadm-d-s>/dev/mdadm. conf
Mdadm usage reference)
Mdadm is a tool for managing software raid in Linux.
The following content is from the manpage:
Basic Syntax: mdadm [mode] [Options]
There are 7 [mode] types:
Assemble: adds an array previously defined to an existing array.
Build: Build a legacy array. Each device has no superblocks
Create: Create a new array with each device having a superblocks
Manage: Manage arrays, such as add or remove
Misc: allows a device in the array to be used independently, for example, to erase superblocks or terminate an array in use.
Follow or monitor: monitors the status of RAID, and multipath
Grow: Change the raid capacity or the number of devices in the array
Available [Options]:
-A, -- assemble: adds a previously defined array
-B, -- Build: Build a legacy array without superblocks.
-C, -- create: Create a new array
-Q, -- Query: view a device and determine whether it is a MD device or a part of a MD array.
-D, -- detail: Print details of one or more MD Devices
-E, -- examine: print the content of the MD superblock on the device.
-F, -- follow, -- monitor: select the monitor mode.
-G, -- grow: changes the size or form of the array in use.
-H, -- help: help information. This option is displayed after the preceding options are used.
-- Help-Options
-V, -- version
-V, -- verbose: displays details
-B, -- Brief: less details. Used for -- detail and -- Examine options
-F, -- force
-C, -- Config =: Specifies the configuration file. The default value is/etc/mdadm. conf.
-S, -- Scan: scan the configuration file or/proc/mdstat to search for lost information. Configuration file/etc/mdadm. conf
Options used by create or build:
-C, -- chunk =: Specify chunk size of kibibytes. The default value is 64.
-- Rounding =: Specify rounding factor for Linear Array (= chunk size)
-L, -- level =: Set the raid level.
-- Create available: linear, raid0, 0, stripe, raid1, 1, mirror, raid4, 4, RAID5, 5, raid6, 6, multipath, MP.
-- Build available: linear, raid0, 0, stripe.
-P, -- parity =: Set the RAID 5 parity rules: eft-asypolicric, left-semi Ric, right-asypolicric, right-semi Ric, La, Ra, ls, Rs. the default value is left-semi Ric.
-- Layout =: similar to -- parity
-N, -- raid-devices =: specifies the number of available devices in the array. This number can only be modified by -- grow.
-X, -- spare-devices =: specify the number of surplus devices of the initial array.
-Z, -- size =: total space obtained from each device after raid1/0/6 is set
-- Assume-clean: currently only used for the -- Build Option
-R, -- run: when a part of the array appears in another array or file system, mdadm confirms the array. This option is not confirmed.
-F, -- force: Generally, mdadm does not allow creating arrays with only one device, and a device is used as missing drive when creating RAID 5. This option is the opposite.
-A, -- Auto {= No, yes, MD, MDP, part, p} {NN }:

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/nhczp/archive/2009/05/26/4216692.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.