How to Create and Manage a Software RAID 1 Array in Linux Using mdadm

Protecting critical Linux server environments against individual storage drive hardware failures is a fundamental operational requirement. While hardware RAID controllers depend on dedicated proprietary hardware cards, Linux includes a robust, kernel-level software RAID framework managed through the mdadm (Multiple Device administrator) utility.

A RAID 1 (mirroring) configuration duplicates identical data across two or more physical storage drives simultaneously. If one drive develops bad sectors or suffers total electrical failure, the storage array remains fully online and operational without data loss or system downtime.

Prerequisites and Identifying Storage Disks

Before assembling a software RAID 1 array, ensure you have two separate physical drives or unformatted disk partitions of matching capacity (e.g. /dev/sdb and /dev/sdc):

  1. Open your Linux terminal and install the mdadm package if it is not already present on your distribution:
    sudo apt update && sudo apt install mdadm -y
  2. Inspect all attached block devices and verify their device identifiers:
    lsblk
  3. Ensure the target disks do not contain active filesystems or stale partition tables by running:
    sudo wipefs -a /dev/sdb
    sudo wipefs -a /dev/sdc

For partition table safety and backup procedures prior to provisioning storage, review our guide on how to backup and restore GPT partition tables in Linux using sgdisk.

Creating the RAID 1 Array with mdadm

To create a new mirrored array assigned to virtual device /dev/md0:

  1. Execute the creation command specifying RAID level 1 and the two member disks:
    sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
  2. If prompted to confirm array creation across the drives, type y and press Enter.
  3. Monitor initial synchronization progress by reading the kernel’s RAID status file:
    cat /proc/mdstat
    The kernel displays the active mirror status, recovery percentage, and estimated time remaining until initial sync completes.

Formatting and Mounting the RAID Device

Once the virtual device /dev/md0 is created, treat it like any standard storage block device:

  1. Format the array with a modern filesystem such as Ext4:
    sudo mkfs.ext4 /dev/md0
  2. Create a designated mount directory:
    sudo mkdir -p /mnt/raid1
  3. Mount the array:
    sudo mount /dev/md0 /mnt/raid1
  4. Verify that the new storage volume mounts cleanly and displays appropriate capacity:
    df -h /mnt/raid1

Configuring Persistent Auto-Assembly on Boot

To ensure Linux automatically detects and mounts your RAID 1 volume across system reboots, you must save its UUID into the configuration files:

  1. Append the array definition to the mdadm.conf configuration file:
    sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
  2. Update your initial RAM filesystem (initramfs) so the early boot environment recognises the array:
    sudo update-initramfs -u
  3. Retrieve the filesystem UUID of the formatted array:
    sudo blkid /dev/md0
  4. Open /etc/fstab in a text editor and add a permanent mount entry:
    UUID=[your-md0-uuid]  /mnt/raid1  ext4  defaults,nofail  0  2

Handling Drive Failures and Replacing Disks

If a hard drive fails, mdadm marks it as degraded. To safely swap and rebuild a failed disk:

  • Check array health: Run sudo mdadm --detail /dev/md0 to identify the faulty drive.
  • Mark and remove disk: Mark the damaged drive as failed and remove it from the array:
    sudo mdadm /dev/md0 --fail /dev/sdb
    sudo mdadm /dev/md0 --remove /dev/sdb
  • Insert replacement disk: Power off or hot-swap the hardware, connect the replacement disk, and add it into the array:
    sudo mdadm /dev/md0 --add /dev/sdb

The Linux kernel automatically begins background resynchronisation, restoring full fault-tolerant redundancy without interrupting user access or data availability.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.