Back to Blog
tutorialIntermediate5 min read

Backup and Restore MDADM Raid

A guide to backing up and restoring MDADM RAID arrays after an OS reinstall, including how to reassemble the array, add a spare drive, and mount via fstab.

Back up and Assemble MDADM Raid Array

Overview

This guide covers backing up and restoring MDADM RAID arrays after an OS reinstall. Planning for the worst, hoping for the best has saved a lot of potentially ruined days. Before any RAID operations, maintain a separate backup copy following the 3-2-1 backup rule.

Backup Process

Step 1: Scan and Save Configuration

Run the mdadm detail scan command:

sudo mdadm --detail --scan

Example output:

ARRAY /dev/md0 metadata=1.2 spares=1 UUID=576d6fe7:c8528a0a:2c0fd278:09a74e22

Save this output to a file for later reference during restoration.

Restoration Process

Step 1: Install mdadm

sudo apt install mdadm

Step 2: Assemble the Array

Add the backed-up scan data to the configuration file, then run:

sudo mdadm --assemble --scan

Step 3: Verify Array Status

sudo mdadm --detail /dev/md0

Check for proper device count, state (should be "clean"), and active devices.

Adding a Spare Drive

If no spare is configured, mark one device as failed, remove it, then re-add as spare:

sudo mdadm --fail /dev/md0 /dev/sdh
sudo mdadm --remove /dev/md0 /dev/sdh
sudo mdadm --add-spare /dev/md0 /dev/sdh

Update the boot configuration:

sudo update-initramfs -u

Mounting the Array

Create Mount Point

sudo mkdir /media/shared

Get UUID

sudo blkid /dev/md0

Example output:

/dev/md0: UUID="b8273bf2-9661-4006-a8d7-19710ead427d" BLOCK_SIZE="4096" TYPE="ext4"

Update fstab

Edit the fstab file:

sudo nano /etc/fstab

Add the entry:

UUID=b8273bf2-9661-4006-a8d7-19710ead427d       /media/shared   ext4 defaults,nofail    0       0

CTRL+X, then Y, then ENTER to save.

Mount the Array

sudo mount -av

Verify with:

df -h