Home / Alt manpages / mdadm(8)

  • mdadm(8)
  • Admin command
  • linux

Safely Inspect and Assemble Linux Software RAID with mdadm

mdadm is how you look inside a Linux software RAID array without touching it. This guide keeps to read-only inspection until the final, explicit assembly step, covering member identification, an active array's state, and assembling an existing array from known components, using mdadm 4.3, package version 4.3-1ubuntu2.1, on Ubuntu. Allow 15 minutes for inspection, longer if you need to identify disks from labels or serial numbers.

You need a shell, mdadm, and the device names for the array you are investigating. Inspection commands can usually run as an ordinary user; assembly, management and configuration changes need root and can change storage state.

1. Confirm the installed command

Start with the version and the mode list. These only read the program installation:

$ command -v mdadm
/usr/sbin/mdadm
$ mdadm --version
mdadm - v4.3 - 2024-02-15 - Ubuntu 4.3-1ubuntu2.1
$ mdadm --help | sed -n '1,20p'
Usage: mdadm --create device options...
            Create a new array from unused devices.
       mdadm --assemble device options...
            Assemble a previously created array.

The distinction that matters: --create writes new metadata and activates a new array, while --assemble activates an array that already has metadata. Do not use --create to "repair" an array you have just discovered.

2. Check the kernel's current arrays

/proc/mdstat reports the arrays the kernel currently knows about, ordinary read-only information:

$ cat /proc/mdstat
Personalities : [raid1] [raid0] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 ...
      ... blocks super 1.2 [2/2] [UU]
unused devices: <none>

The exact devices, sizes and personalities are host-specific. For a healthy two-device mirror, [UU] means both expected members are present. A missing position appears as an underscore, for example [U_]. Treat that as a prompt to investigate, not as permission to remove or recreate anything.

Checkpoint

Record the md device names and whether an array is active before you run a command that might change state.

3. Inspect a running array

For an active array, ask mdadm for its detailed state. This normally needs root because the kernel device is protected:

$ sudo mdadm --detail /dev/md0
/dev/md0:
           Version : 1.2
     Raid Level : raid1
     Raid Device : 2
     State : clean
      ...
    Number   Major   Minor   RaidDevice State
       0       ...       ...        0      active sync
       1       ...       ...        1      active sync

Do not copy the ellipses as values. Check the real output for the RAID level, state, expected number of devices and component paths. --detail --test is useful for automation: mdadm documents exit status 0 for a normally functioning array, 1 for at least one failed device, 2 for multiple failures that make it unusable, and 4 when it cannot get useful information.

$ sudo mdadm --detail --test /dev/md0
$ printf 'mdadm status: %s\n' "$?"
mdadm status: 0

4. Inspect an unassembled component safely

If an array is not active, examine a suspected member without assembling it:

$ sudo mdadm --examine --brief /dev/disk/by-id/ata-EXAMPLE_DISK-part1
/dev/disk/by-id/ata-EXAMPLE_DISK-part1: UUID=... DEVICE=... TYPE=... ARRAY=...

Use a stable /dev/disk/by-id path when available, and compare several members: the UUID, metadata version, array identity and role should all agree. A brief result suits reviewing a candidate configuration, but the punctuation and fields depend on the metadata and installed release.

To scan devices named by configuration, --examine --scan reads the configured device list. If you need to avoid the system configuration while testing, --config=partitions tells mdadm to use device numbers from /proc/partitions, though that does not make every device safe to use.

5. Assemble an existing array

Warning

Assembly activates storage. Confirm the UUID and member set first, make sure the filesystem is not already mounted elsewhere, and have a recovery plan. Do not guess a component path, substitute a different disk, or add --force just because an ordinary assembly failed.

When the identity and components are known, assemble the pre-existing array explicitly:

$ sudo mdadm --assemble /dev/md0 \
    /dev/disk/by-id/ata-EXAMPLE_DISK_A-part1 \
    /dev/disk/by-id/ata-EXAMPLE_DISK_B-part1

mdadm checks the superblocks against the array identity and normally starts the array after assembly. If you deliberately supply fewer members than expected, mdadm will not normally start it without --run, which is a safety check. A degraded start can expose data while another member is unavailable, but it also carries recovery and write risks: use it only after confirming the RAID level and failure state.

Checkpoint

Verify the result before mounting anything:

$ cat /proc/mdstat
$ sudo mdadm --detail /dev/md0

If the array is not the one you expected, stop. Do not mount it read/write and do not overwrite its members while you investigate.

6. Keep mdadm.conf focused

Configuration is a workflow aid, not a substitute for checking metadata. The default locations are /etc/mdadm.conf, its .d directory, or the alternative /etc/mdadm/mdadm.conf locations when the first file cannot be opened. Files in a configuration directory are read in lexical order.

A small configuration can name the devices to scan and one array by UUID:

DEVICE /dev/disk/by-id/ata-EXAMPLE_DISK_*
ARRAY /dev/md0 UUID=REPLACE-WITH-THE-VERIFIED-UUID

Replace the UUID with the value from --detail or --examine. DEVICE controls where mdadm looks; an ARRAY line identifies an array, and multiple identity fields must all match. Review generated output before installing it, because --detail --scan and --examine --scan can include unwanted device details.

After a configuration change, test the intended lookup explicitly:

$ sudo mdadm --assemble --scan --readonly
$ cat /proc/mdstat

Warning

Read-only assembly still changes which md device is active, so use a maintenance window and check that no duplicate host is using the same members. To undo a configuration-only change, restore the previous file. To deactivate an array, sudo mdadm --stop /dev/md0 requires that it is not in use and is a service-disrupting action, so unmount filesystems and stop dependent services first.

Common traps

  • --create on an existing array: it writes superblocks. Never use it to make an unknown existing array look healthy.
  • --zero-superblock, --fail, --remove and --grow: these change storage state. Take a verified backup and check the exact target before using them.
  • --force: overrides selected safety checks. It does not reconstruct missing data or make mismatched disks safe.
  • --scan: pulls missing information from configuration or kernel state, not a guarantee that every discovered array belongs to this host.
  • Active versus mounted: do not confuse an active array with a mounted filesystem. Check mounts separately before stopping or assembling anything.

Done means

  • Version confirmed: you confirmed mdadm 4.3 and recorded the current /proc/mdstat state.
  • State inspected: you checked the active array or member superblocks and verified the UUID and RAID level.
  • Paths explicit: you used explicit, stable component paths for assembly.
  • Config reviewed: you checked mdadm.conf instead of trusting generated scan output blindly.
  • Nothing destructive run: you did not create, grow, fail, remove or erase metadata while investigating.