Updated May 29, 2023
Introduction to Linux mdadm
MDADM command is used to monitor and manage software RAID devices. RAID is nothing but a technique used for Performance management and Reduce data redundancy.
- RAID: Redundant Array of Independent Disk
Data is distributed across multiple levels known as RAID levels (RAID0, RAID1…) with some level of redundancy and performance. The idea behind having the redundancy is to survive some degree of device failure. As the name suggests MDADM – Multiple Disk and Device Management, the command is used to implement array formation and management on the Linux platform.
- Mdadm: Multiple Disk and Device Management.
Currently, Linux supports linear md device network i.e. combination of one or more devices into a single large network.
How to Use the Linux mdadm?
The main purpose of mdadm command is to combine one or more physical disk drive components into one or more logical units.
Mdadm command can be used in the below way:
mdadm [mode] <raiddevice> [options] <component-devices>
There are several modes in which mdadm command can be used. Some of the important ones are listed below:
|Create||It is used to create a new array with pre-defined superblocks.
|Assemble||Assembles the components obtained by the previously created array into an active array.|
|Build||Builds an array that does not hold a pre-defined superblock. Must be used with a complete understanding of it as the mdadm command in build mode cannot distinguish between initial creation and assembly of the array. No check is performed to validate the request.|
|Follow or monitor||Monitors one or more md devices. RAID0 or Linear does not have anything to monitor. They never have any missing, spare, or failed drive so this option is mostly used in RAID1,4,5,6,10 or multipath array.|
|Grow||To reshape an array (grow or shrink). It can be used to change the active size of components or to change the number of active devices in linear and RAID 0/1/4/5/6.|
|Manage||Managing the specific component of an array such as adding a new spare or removing faulty device etc.|
|Misc||“Everything Else” mode. Supports the operation on the active array and also the operation on components.|
|Incremental Assembly||Adds a single device to the given array. The array gets triggered if the addition of the device makes the array runnable.|
|Auto-Detect||This mode requests the Linux terminal to activate any auto-detected array. This mode does not require an array of their own.|
Along with the various modes, there are multiple options available with mdadm commands. Some of which are general and some are mode-specific options. Some of the major options are listed below
|-h , –help||Display general help.|
|–help-options||Display help specific to the mode.|
|-V,–version||Print the version information of mdadm.|
|-v , –verbose||Be more verbose about what is happening.|
|-q, –quiet||stop printing information by mdadm command unless it is really important.|
|-b, –brief||Gives an intermediate level of verbosity. Makes the command less verbose.|
|-c,–config||Specify the config file. The default configuration file is /etc/mdadm.confin case that is missing then /etc/mdadm/mdadm.configs used.|
|-s, –scan||Scans the configuration file. Generally, it gives mdadm command the permission to get any missing information|
|-e,–metadata||Can be used to define the type of the superblock. With the help of –metadata, the default type of superblock can be changed.|
Examples to Implement Linux mdadm
Let us try to understand the mdadm command in more detail with the help of some examples.
1. Install mdadm
- To use mdadm you must have it installed on your system.
sudo apt-get install mdadm
2. Create RAID
mdadm - -create/dev/md0- -level=1 –raid-devices=2 /dev/sdc1/dev/sdb1
- –create à specifies the mode of the command.
- /dev/md0 àname of the array to be formed by mdadm.
- /dev/sdc1/dev/sdb1àComponent names used to form RAID.
- –level àspecifies the level of the RAID. Here level =1 since we are forming a RAID one array
3. Check RAID
- Check the details about the newly created RAID. – -detailed option is used.
sudo mdadm - -detail /dev/md0
4. Add RAID to configuration
- To add the array to a mdadm configuration file
sudo mdadm - -detail - -scan>>/etc/mdadm/mdadm.conf
5. Description of Array
- To get a brief description of the array.
sudo mdadm - -query /dev/name-of-device
- This will display if the given device name(name-of-device) is the part of the RAID array or the part of RAID device
- To get help on any of the modes.
sudo mdadm - -create - -help
- This will provide us help on create mode.
sudo mdadm - -config - -help
- This will provide us help on the configuration file.
sudo mdadm - -help
- This will provide us with general help.
- To start the array.
sudo mdadm - -assemble - -scan
- The command will go to the system configuration file. It will assemble and start all the array which are the part of that configuration file.
- To stop the array.
mdadm - -stop - -scan
- this will shut down all the array which are currently not being used. Typically it goes to a system shutdown script.
- Status of the array.
mdadm - -follow - -scan - -delay=120
- This will send the status of the array by polling them after the time specified (every 2 min).
- The failed once.
mdadm /dev/md0 - -fail detached –remove detached
- Any device which is not part of the system is marked as failed. And with the help of remove all the failed devices are removed from the array
Storage is one of the most important parts of fault tolerance. Any disk failure will result in data loss and indeed a loss for the company. One of the best ways to avoid data loss is RAID which can be achieved in a modern Linux system using mdadm command replacing the older software utilities such as raid tools and raidtools2.
We hope that this EDUCBA information on “Linux mdadm” was beneficial to you. You can view EDUCBA’s recommended articles for more information.