LinuxCommandLibrary

mdadm

Manage Linux software RAID arrays

TLDR

Create array

$ sudo mdadm --create [/dev/md/MyRAID] --level [raid_level] --raid-devices [number_of_disks] [/dev/sdXN]
copy

Stop array
$ sudo mdadm --stop [/dev/md0]
copy

Mark disk as failed
$ sudo mdadm --fail [/dev/md0] [/dev/sdXN]
copy

Remove disk
$ sudo mdadm --remove [/dev/md0] [/dev/sdXN]
copy

Add disk to array
$ sudo mdadm --assemble [/dev/md0] [/dev/sdXN]
copy

Show RAID info
$ sudo mdadm --detail [/dev/md0]
copy

Reset disk by deleting RAID metadata
$ sudo mdadm --zero-superblock [/dev/sdXN]
copy

SYNOPSIS

mdadm [mode] <RAID-device> [options] <component-devices>

Common modes include:
mdadm --create <RAID-device> --level=<level> --raid-devices=<num> <component-devices>
mdadm --assemble <RAID-device> <component-devices>
mdadm --detail <RAID-device>
mdadm --examine <component-device>
mdadm --manage <RAID-device> --add <device>
mdadm --monitor [options]

PARAMETERS

--create or -C
    Create a new RAID array.

--assemble or -A
    Assemble a pre-existing array from its components.

--build or -B
    Create an array without a superblock (legacy, rarely used).

--manage or -M
    Manage an array (e.g., add, remove, fail, replace devices).

--monitor or -F
    Monitor one or more arrays for events (e.g., component failure).

--detail or -D
    Display detailed information about an array.

--examine or -E
    Examine a device for an md superblock.

--level=<level> or -l
    Specify the RAID level (e.g., 0, 1, 5, 6, 10).

--raid-devices=<num> or -n
    Specify the number of active devices in the array.

--spare-devices=<num> or -x
    Specify the number of spare devices.

--chunk=<size> or -c
    Specify the chunk size in kilobytes.

--add <device>
    Add a device to an array.

--remove <device>
    Remove a device from an array.

--fail <device>
    Mark a device as faulty within the array.

--replace <device>
    Replace a failed device with another.

--verbose or -v
    Provide more detailed output.

--force or -f
    Force an operation that might otherwise be rejected.

--uuid=<uuid> or -u
    Specify the UUID of an array or component.

--zero-superblock
    Overwrite existing md superblocks on devices. USE WITH EXTREME CAUTION!

DESCRIPTION

mdadm is a powerful and versatile utility designed for managing Linux software RAID (MD, or Multiple Device) arrays. It provides a comprehensive set of functions to create, assemble, monitor, manage, and remove RAID devices. Unlike hardware RAID solutions, software RAID leverages the system's CPU to perform RAID operations, making it a flexible and cost-effective solution for data redundancy and performance. mdadm supports various RAID levels, including RAID0 (striping), RAID1 (mirroring), RAID4, RAID5 (striping with distributed parity), RAID6 (striping with double distributed parity), and RAID10 (mirrored stripes). It integrates seamlessly with the Linux kernel's MD driver, allowing users to configure and maintain robust storage solutions. Key functionalities include adding/removing drives from an array, replacing failed drives, monitoring array health, and growing arrays. mdadm consolidates the functionality of older raidtools utilities into a single, unified command, making it the standard for software RAID management on Linux systems.

CAVEATS

Using mdadm incorrectly can lead to severe data loss. Always ensure you have backups before performing array modifications.
Requires root privileges to execute most operations.
Properly configuring mdadm.conf is crucial for arrays to be assembled automatically on boot. Without it, manual assembly might be required or arrays may not start.
Performance of software RAID is dependent on CPU resources and I/O bandwidth of the underlying disks.
Understanding RAID levels and disk partitioning is essential for effective use. Incorrect partitioning (e.g., not using type FD) can lead to issues.

MODES OF OPERATION

mdadm operates in distinct modes, which dictate its primary function:

  • Create Mode (--create): Used for building a new RAID array from scratch.
  • Assemble Mode (--assemble): Used to gather components and start an array that already exists but is not currently active.
  • Manage Mode (--manage): Used for performing administrative tasks on an active array, such as adding or removing disks, or marking disks as faulty.
  • Monitor Mode (--monitor): Runs as a daemon to constantly check the status of arrays and report events (e.g., disk failure, rebuild completion).
  • Detail Mode (--detail): Provides extensive information about a specific active RAID array.
  • Examine Mode (--examine): Inspects a potential RAID component device for an md superblock, showing details about the array it belongs to.

MD SUPERBLOCKS

mdadm arrays typically use metadata blocks called superblocks, which are stored on each component disk. These superblocks contain crucial information about the RAID array, including its level, UUID, number of devices, and position of the device within the array. This allows mdadm to identify and assemble arrays automatically, even after reboots or disk rearrangements, without relying solely on a central configuration file. The `--zero-superblock` option should be used with extreme care, as it can destroy this critical metadata.

CONFIGURATION FILE (`MDADM.CONF`)

The mdadm.conf file (typically located at /etc/mdadm/mdadm.conf or /etc/mdadm.conf) plays a vital role in persistent array management. It defines arrays that should be automatically assembled at boot time, provides aliases for array devices, and specifies monitoring parameters. While mdadm can examine disks to find and assemble arrays, the configuration file ensures reliable and consistent setup across reboots, especially for complex or multi-path arrays.

HISTORY

Linux software RAID has been an integral part of the kernel for many years, evolving significantly since its early days. The mdadm utility was developed to replace and consolidate the older collection of raidtools utilities (like mkraid, raidstart, raidstop) into a single, more robust, and user-friendly command. This transition occurred around the Linux kernel 2.4 era and became widely adopted for its efficiency and improved management capabilities, such as advanced monitoring and hot-swap support. Its continuous development ensures compatibility with new kernel features and modern storage requirements.

SEE ALSO

lsblk(8), fdisk(8), parted(8), mkfs(8), mount(8), lvm(8), mdadm.conf(5)

Copied to clipboard