
mdassemble Command in Linux
The mdassemble command in Linux is a powerful utility used to assemble and manage RAID (Redundant Array of Independent Disks) arrays. RAID arrays are used to combine multiple physical disks into a single logical unit to improve performance, redundancy, or both.
The mdassemble command is part of the mdadm toolset, which provides comprehensive management capabilities for RAID arrays.
Table of Contents
Here is a comprehensive guide to the options available with the mdassemble command −
- Understanding mdassemble Command
- Syntax of mdassemble Command
- Examples of mdassemble Command in Linux
Understanding mdassemble Command
RAID is a technology that combines multiple physical disks into a single logical unit to achieve various goals, such as increased performance, redundancy, or both. There are different RAID levels, each offering a unique combination of these benefits. This command is used to assemble existing RAID arrays, making them available for use by the system.
Installing the mdadm Package
Before using the mdassemble command, you need to ensure that the mdadm package is installed on your system.
For example, on Debian-based systems like Ubuntu, you can use the following command
sudo apt-get install mdadm

On Red Hat-based systems like CentOS, you can use −
sudo yum install mdadm
Syntax of mdassemble Command
The basic syntax of the mdassemble command is as follows −
mdadm --assemble [options] device [component-devices]
Here,
- --assemble − Specifies that the command is used to assemble an existing RAID array.
- options − Various options that modify the behavior of the command.
- device − The RAID device to be assembled (e.g., /dev/md0).
- component-devices − The component devices that make up the RAID array (e.g., /dev/sda1 /dev/sdb1).
Examples of mdassemble Command in Linux
The mdassemble command is used to assemble existing RAID arrays, making them available for use by the operating system. Here are some common use cases and examples −
Assembling a RAID Array
To assemble an existing RAID array, you can use the following command −
sudo mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1

In this example, the mdassemble command assembles the RAID array /dev/md0 using the component devices /dev/sda1 and /dev/sdb1.
Assembling a RAID Array with Auto-Detection
If you do not specify the component devices, the mdassemble command can automatically detect and assemble the RAID array −
sudo mdadm --assemble /dev/md0

In this example, the mdassemble command assembles the RAID array /dev/md0 by automatically detecting the component devices.
Assembling All RAID Arrays
To assemble all RAID arrays defined in the configuration file, you can use the --scan option −
sudo mdadm --assemble --scan

In this example, the mdassemble command scans the configuration file (usually /etc/mdadm/mdadm.conf) and assembles all defined RAID arrays.
Assembling a RAID 1 Array
RAID 1 provides redundancy by mirroring data across multiple disks. To assemble a RAID 1 array, you can use the following command −
sudo mdadm --assemble /dev/md1 /dev/sdc1 /dev/sdd1

In this example, the mdassemble command assembles the RAID 1 array /dev/md1 using the component devices /dev/sdc1 and /dev/sdd1.
Assembling a RAID 5 Array
RAID 5 provides both performance and redundancy by distributing parity information across multiple disks. To assemble a RAID 5 array, you can use the following command −
sudo mdadm --assemble /dev/md5 /dev/sde1 /dev/sdf1 /dev/sdg1

In this example, the mdassemble command assembles the RAID 5 array /dev/md5 using the component devices /dev/sde1, /dev/sdf1, and /dev/sdg1.
Assembling a RAID 10 Array
RAID 10 combines the benefits of RAID 1 and RAID 0 by providing both redundancy and performance. To assemble a RAID 10 array, you can use the following command −
sudo mdadm --assemble /dev/md10 /dev/sdh1 /dev/sdi1 /dev/sdj1 /dev/sdk1

In this example, the mdassemble command assembles the RAID 10 array /dev/md10 using the component devices /dev/sdh1, /dev/sdi1, /dev/sdj1, and /dev/sdk1.
Assembling and Starting a RAID Array
To assemble and start a RAID array, you can use the --run option −
sudo mdadm --assemble --run /dev/md0 /dev/sda1 /dev/sdb1

In this example, the mdassemble command assembles and starts the RAID array /dev/md0 using the component devices /dev/sda1 and /dev/sdb1.
Forcing the Assembly of a RAID Array
If some component devices are missing or degraded, you can use the --force option to force the assembly of the array −
sudo mdadm --assemble --force /dev/md0 /dev/sda1 /dev/sdb1

In this example, the mdassemble command forces the assembly of the RAID array /dev/md0 using the component devices /dev/sda1 and /dev/sdb1.
Assembling a RAID Array by UUID
To assemble a RAID array by specifying its UUID, you can use the --uuid option −
sudo mdadm --assemble --uuid=12345678:9abcdef0:12345678:9abcdef0 /dev/md0

In this example, the mdassemble command assembles the RAID array /dev/md0 using the specified UUID.
Assembling a RAID Array by Name
To assemble a RAID array by specifying its name, you can use the --name option −
sudo mdadm --assemble --name=myraid /dev/md0

In this example, the mdassemble command assembles the RAID array /dev/md0 using the specified name myraid.
Displaying Detailed Information
To display detailed information about a RAID array, you can use the --detail option −
sudo mdadm --detail /dev/md0

In this example, the mdadm command displays detailed information about the RAID array /dev/md0, including its status, component devices, and configuration.
Stopping a RAID Array
To stop a RAID array, you can use the --stop option −
sudo mdadm --stop /dev/md0

In this example, the mdadm command stops the RAID array /dev/md0.
Removing a RAID Array
To remove a RAID array, you can use the --remove option −
sudo mdadm --remove /dev/md0

In this example, the mdadm command removes the RAID array /dev/md0.
Conclusion
The mdassemble command is part of the mdadm toolset, which provides a comprehensive set of utilities for managing RAID arrays. The mdadm toolset includes commands for creating, assembling, monitoring, and managing RAID arrays.