> For the complete documentation index, see [llms.txt](https://linux-tutorial-cli.gitbook.io/linux-cli-tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://linux-tutorial-cli.gitbook.io/linux-cli-tutorial/txt-files/file-systems-cocepts/lpic2-201/mdadm.md).

# mdadm

`mdadm` command, which is used for managing software RAID (Redundant Array of Independent Disks) configurations in Linux. Here’s an overview of its usage and functionality:

### `mdadm` Command

1. **Purpose**:
   * **RAID Management**: `mdadm` is used to create, manage, and monitor software RAID arrays in Linux.
   * **Device Administration**: It allows for various operations such as assembling, reassembling, and managing RAID devices and arrays.
2. **Basic Usage**:
   * **Create RAID Array**:

     ```
     mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
     ```

     * Creates a RAID 1 (mirror) array named `/dev/md0` using `/dev/sdb1` and `/dev/sdc1`.
   * **Assemble RAID Array**:

     ```
     mdadm --assemble /dev/md0 /dev/sdb1 /dev/sdc1
     ```

     * Assembles the RAID array `/dev/md0` using specified devices.
   * **Manage Arrays**:
     * `--detail`: Display detailed information about RAID arrays.
     * `--monitor`: Monitor RAID arrays for changes and events.
     * `--stop`: Stop (deactivate) a running RAID array.
     * `--fail` and `--remove`: Mark a device as failed and remove it from the array.
   * **Configuration**:
     * `--detail --scan`: Outputs configuration details suitable for `mdadm.conf`.
     * `--examine`: Examine RAID metadata on devices.
3. **Monitoring and Maintenance**:
   * **Monitoring**: Use `mdadm --monitor` to monitor arrays for failures or changes.
   * **Maintenance**: Replace failed disks with `--manage --replace`.
4. **Examples**:
   * **Create RAID 5 Array**:

     ```
     mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1
     ```

     * Creates a RAID 5 array named `/dev/md0` with three devices.
   * **Assemble All Arrays**:

     ```
     mdadm --assemble --scan
     ```

     * Assembles all RAID arrays listed in `mdadm.conf`.
5. **Additional Options**:
   * `-v, --verbose`: Provides detailed output.
   * `-Q, --brief`: Provides brief output suitable for scripting.
   * `-h, --help`: Displays help information.

### Conclusion

`mdadm` is a powerful command-line tool for managing software RAID arrays on Linux systems. It offers flexibility in creating different RAID levels (0, 1, 5, 10, etc.), monitoring array health, and handling device failures. Always refer to the `mdadm` documentation (`man mdadm`) for comprehensive details and advanced usage scenarios. This ensures efficient management and maintenance of RAID configurations to enhance data reliability and availability.
