Administration of RAID with MDADM
This article includes the general procedure of creating and administrating an array with MDADM.
MDAMD (multiple disk administration) is a program that helps with the administration of a Software RAID in Linux. With this program, RAID-arrays can be created, configured, monitored and deleted. MDADM is released as free software under the GNU General Public License (GPL).
MDADM creates so-called multiple devices (short MD) from different block devices (such as an entire hard drive, a single partition, or a USB flash drive)
MDADM is a practical software RAID solution that can be actively developed. It allows simultaneous, parallel access to all disks. In addition, the arrays created are hardware-independent, which significantly enhances data security.
Possible RAID levels
- Linear: Chaining of multiple parities
- Multipath: No RAID, but mapping of a file on two different paths on the same partition (mirroring).
- Faulty: Emulates a faulty RAID system for test cases.
- Level 0 (Block Level Striping): Chaining multiple small block devices together to form one large one.
- Level 1 (Mirror): Mirroring of a disk
- Level 4: Like level 0, but with an additional device for parity bit (increased reliability).
- Level 5: Like level 4, the parity bits are distributed across all devices.
- Level 6: However, like level 5, it uses two independent parity bits per segment (increased reliability).
- Level 10: Combination of level 0 and 1.
Installation of mdadm
If RAID was not set up during the Linux installation, you must install the mdadm package from the repositories.
:~$ sudo aptitude install mdadm
After the installation, there are no further steps required for the configuration and the tool can be used.
Commands for configuration and administration
Basic syntax
mdadm [mode] <raiddevice> [options] <component-devices>
Create array
mdadm --create /dev/md/<Label> --level=<RAID-Level> --raid-devices=<number of physical partitions in the array> /dev/sdX1 /dev/sdY1
Parameter:
--createAn optional parameter can be specified to set a label for the RAID. For example:/dev/md/md_1--level=: Specifies the desired RAID level. Valid entries arelinear, raid0, 0, stripe, raid1, 1, mirror, raid4, 4, raid5, 5, raid6, 6, raid10, 10, multipath, mp, faulty, container--raid-devices=: Specifies the number of physical partitions in the software RAID. In addition, the individual partitions must be stated. For example:--raid-devices=2 /dev/sda2 /dev/sdb3
RAID 0 with MDADM
To create a RAID 0 (Block Level Striping) array, at least 2 partitions are required. They should be the same size and located on different physical hard drives.
The RAID 0 array can be initialized with the following command: mdadm --create /dev/md/<Label> --level=0 --raid-devices=<Anzahl> /dev/sdX1 /dev/sdY1
Example (2 physical hard drives):
root@swraid:~# mdadm --create /dev/md/md_test --level=0 --raid-devices=2 /dev/sdb1 /dev/sdc1 mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md/md_test started.
RAID 1 with MDADM
To create a RAID 1 (Block Level Mirroring) array, at least two physical partitions are required. They should be the same size and located on different physical hard drives.
The RAID 1 array can be initialized with the following command: mdadm --create /dev/md/<Label> --level=1 --raid-devices=<number> /dev/sdX1 /dev/sdY1
Example (2 physical hard drives):
root@swraid:/dev# mdadm --create /dev/md/md_test --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
Continue creating array? yes
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md/md_test started.
Delete array
To remove a RAID array, the array must be unmounted (umount) and the command mdadm --stop /dev/md/<name of RAID> must be called up. Although this unmounts the array from the system, the RAID array remains physically in place.
To remove the array, the superblock of every hard drive, which determines the hard drive/partition as RAID-device, must be set to 0. This can be performed with the command mdadm --zero-superblock /dev/<physical partition>.
Example:
root@swraid:/dev# umount -l /mnt/test root@swraid:/dev# mdadm --stop /dev/md/md_test mdadm: stopped /dev/md/md_test root@swraid:/dev# mdadm --zero-superblock /dev/sdb1 root@swraid:/dev# mdadm --zero-superblock /dev/sdc1
Listing arrays/partitions
RAID-arrays can be listed with two kinds of commands. --detail refers to a completely active array, while --examine refers to the individual physical devices in a RAID array.
root@swraid:/mnt/test# mdadm --examine --brief --scan --config=partitions ARRAY /dev/md/md_test metadata=1.2 UUID=81c1d8e5:27f6f8b9:9cdc99e6:9d92a1cf name=swraid:md_test
This command can also be abbreviated with -Ebsc partitions.
root@swraid:/dev/md# mdadm --detail /dev/md/md_test
/dev/md/md_test:
Version : 1.2
Creation Time : Fri Jul 5 09:14:36 2013
Raid Level : raid0
Array Size : 16776192 (16.00 GiB 17.18 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Fri Jul 5 09:14:36 2013
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Chunk Size : 512K
Name : swraid:md_test (local to host swraid)
UUID : 81c1d8e5:27f6f8b9:9cdc99e6:9d92a1cf
Events : 0
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
Hotspare
Hotspare hard drives/partitions are hard drives/partitions that are not normally used. These are used when one of the active hard drives or partitions in the RAID array has an error or is defective. If no hot spare disk is defined in a software RAID, the rebuild of a failed RAID array must be started manually. If a Hotspare is available, it is automatically started with the rebuild. A Hotspare hard drive can be added with the command mdadm --add /dev/md/<RAID-name> /dev/sdX1, where the first parameter is the name of the RAID array and the second is the name of the hard drive to be added. If a Hotspare hard drive should be removed from the RAID array, the command mdadm --remove /dev/md/<RAID-name> /dev/sdX1 must be called up. Here, the first parameter is the name of the RAID array, and the second is the name of the hot spare hard drive.
Rebuild
If a partition or hard drive has a defect (software or hardware), the RAID array must be rebuilt. To do this, the defect device must be removed from the RAID. The command mdadm --manage /dev/md/<RAID-name> -r /dev/sdX1 is required for this. The first parameter refers to the RAID array. The second to the defect device. If there is no Hotspare hard drive available, a new hard drive must be partitioned. It is important that the new hard drive has the same partition as the defect one. The tools fdisk /dev/sdX, cfdisk /dev/sdX1 as well as parted /dev/sdX1 help with the partition of a hard drive.
If the new hard drive is partitioned correctly, it can be added to the RAID array. This can be made with mdadm --manage /dev/md/<RAID-Name> -a /dev/sdX1. If no errors occurred during this process, you can begin the actual rebuild. For this, the new partition must be set to "faulty" in the RAID array: mdadm --manage --set-faulty /dev/md/<RAID-name> /dev/sdX1. This triggers the rebuild of the RAID array.
With watch cat /proc/mdstat, the progress of the rebuild can be tracked.
Every 2.0s: cat /proc/mdstat Fri Jul 5 09:59:16 2013
root@swraid:/dev# watch cat /proc/mdstat
Personalities : [raid0] [raid1]
md127 : active raid1 sdc1[1] sdb1[0]
8384448 blocks super 1.2 [2/2] [UU]
[==============>......] check = 74.7% (6267520/8384448) finish=0.1min speed=202178K/sec
unused devices: <none>
As soon as the rebuild of the RAID compound has been completed, the partition must be removed from the RAID array and added again to remove the status "faulty". mdadm --manage /dev/md/<RAID-name> -r /dev/sdX1 for removing and mdadm --manage /dev/md/<RAID-name> -a /dev/sdX1 for adding.
With the command mdadm --detail /dev/md/<RAID-name> , the status of the RAID array can be verified again. This should now have the State: clean status.
Set up email address for array monitoring
To receive an email notification in the event of a failure, you can enter the desired email address in the mdadm configuration file (/etc/mdadm/mdadm.conf) under MAILADDR root instead of root.
For this, an email service (postfix, exim, ...) must be configured on the system.
Open /etc/mdadm/mdadm.conf with an editor and edit the following line:
Instead of MAILADDR root, enter an email address such as MAILADDR email@example.com and save it.
Verify array
The tool checkarray is required to conduct continuous monitoring. This can be added to the list of Cronjobs with crontab -e.
/usr/share/mdadm/checkarray --cron --all --quiet
|
Author: Sebastian Strassner Sebastian Strassner works in the Technical Support department at Thomas-Krenn. He takes care of typical support tasks such as setting up test systems or supporting customers with technical problems. He has specialized in Linux in particular. In his spare time Sebastian enjoys working with wood, flying a few rounds with his quadrocopter or also enjoys working with computers privately.
|
|
Translator: Alina Ranzinger Alina has been working at Thomas-Krenn.AG since 2024. After her training as multilingual business assistant, she got her job as assistant of the Product Management and is responsible for the translation of texts and for the organisation of the department.
|


