Tutorial
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.
This post contains paid links (affiliate) — how that works.
Contents
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 --scanExample output:
ARRAY /dev/md0 metadata=1.2 spares=1 UUID=576d6fe7:c8528a0a:2c0fd278:09a74e22Save this output to a file for later reference during restoration.
Restoration Process
Step 1: Install mdadm
sudo apt install mdadmStep 2: Assemble the Array
Add the backed-up scan data to the configuration file, then run:
sudo mdadm --assemble --scanStep 3: Verify Array Status
sudo mdadm --detail /dev/md0Check 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/sdhsudo mdadm --remove /dev/md0 /dev/sdhsudo mdadm --add-spare /dev/md0 /dev/sdhUpdate the boot configuration:
sudo update-initramfs -uMounting the Array
Create Mount Point
sudo mkdir /media/sharedGet UUID
sudo blkid /dev/md0Example output:
/dev/md0: UUID="b8273bf2-9661-4006-a8d7-19710ead427d" BLOCK_SIZE="4096" TYPE="ext4"Update fstab
sudo nano /etc/fstabAdd the entry:
UUID=b8273bf2-9661-4006-a8d7-19710ead427d /media/shared ext4 defaults,nofail 0 0Save with Ctrl+X, Y, Enter.
Mount the Array
sudo mount -avVerify with:
df -h