Dedicated servers usually come with two or more drives. Software RAID with mdadm combines them so that a failing disk doesn’t take your data or your uptime with it. Linux’s md RAID is mature, fast, and needs no special controller. This guide covers building arrays, monitoring them and replacing a failed disk.

RAID is not a backup

RAID protects against disk failure. It doesn’t protect against deletion, ransomware, filesystem corruption, a compromised server or the whole machine failing. Keep real backups off the server as well. See the 3-2-1 backup rule.

Choose a RAID level

Level Min disks Usable space Survives Notes
RAID 0 2 100% No failures Speed only, no redundancy: avoid for important data
RAID 1 2 50% 1 disk (per mirror) Simple, the most common choice on 2-disk servers
RAID 5 3 (n−1)/n 1 disk Slow rebuilds on big HDDs, with risk during the rebuild
RAID 6 4 (n−2)/n 2 disks Safer than 5 for large arrays
RAID 10 4 50% 1 per mirror pair Fast writes, good for databases

For a typical 2-disk dedicated server: RAID 1. For 4 disks running databases: RAID 10. For bulk storage on many HDDs: RAID 6.

Install mdadm

sudo apt install mdadm      # Debian/Ubuntu
sudo dnf install mdadm      # RHEL family

Many dedicated server install images can set up RAID 1 for the system disk during installation. Use that option if it’s offered. The steps below are for additional data disks.

Create a RAID 1 array

Prepare the disks with a RAID partition each (recommended over raw disks):

lsblk                                         # identify disks: sdb, sdc
sudo parted -s /dev/sdb mklabel gpt mkpart raid 1MiB 100% set 1 raid on
sudo parted -s /dev/sdc mklabel gpt mkpart raid 1MiB 100% set 1 raid on

Create the array:

sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1

RAID 10 with four disks:

sudo mdadm --create /dev/md0 --level=10 --raid-devices=4 /dev/sd[b-e]1

The array is usable immediately while it syncs in the background:

cat /proc/mdstat
md0 : active raid1 sdc1[1] sdb1[0]
      976630464 blocks super 1.2 [2/2] [UU]
      [=====>...............]  resync = 27.4% …

[UU] means both members are up. [U_] means one is missing.

Filesystem, mount and persistence

sudo mkfs.ext4 -L data /dev/md0
sudo mkdir -p /mnt/data
sudo mount /dev/md0 /mnt/data

Save the array definition so it assembles with the same name at boot:

sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf    # RHEL: /etc/mdadm.conf
sudo update-initramfs -u                                           # RHEL: sudo dracut -f

Add it to /etc/fstab by filesystem UUID (blkid /dev/md0), with nofail for data arrays. See fstab.

Check array health

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

Look for State : clean and every device shown as active sync. degraded means a disk has dropped out.

Get alerted

A degraded array that nobody notices is one disk failure away from data loss. Configure email alerts in mdadm.conf:

MAILADDR [email protected]

The mdmonitor service (mdadm --monitor) sends mail through the local MTA when an array degrades. Test it:

sudo mdadm --monitor --scan --test --oneshot

Also monitor the drives themselves with smartmontools (smartctl -a /dev/sdb, plus the smartd service). It often warns before a disk fails completely. Many monitoring tools (Netdata, Prometheus node_exporter) also track md status.

Replace a failed disk

  1. Identify the failed member:
sudo mdadm --detail /dev/md0      # shows "faulty" or "removed"
  1. If it’s still listed, mark it failed and remove it:
sudo mdadm /dev/md0 --fail /dev/sdc1 --remove /dev/sdc1
  1. Note the serial number (smartctl -i /dev/sdc or ls -l /dev/disk/by-id/), so the data centre swaps the right drive. On a dedicated server, open a support ticket with the serial number.

  2. After the replacement, copy the partition layout from the healthy disk and add the new disk:

sudo sfdisk -d /dev/sdb | sudo sfdisk /dev/sdc        # copy the partition table (GPT works too)
sudo sgdisk -G /dev/sdc                               # give the copy new GUIDs (GPT)
sudo mdadm /dev/md0 --add /dev/sdc1
watch cat /proc/mdstat                                # rebuild progress

If the array holds the boot disk, also install the bootloader on the new disk (grub-install /dev/sdc on BIOS systems), so the server can boot from either drive.

Other useful operations

sudo mdadm /dev/md0 --add /dev/sdd1                    # add a hot spare (RAID 1 with 2 active)
sudo mdadm --grow /dev/md0 --raid-devices=3 --add /dev/sdd1   # grow a mirror to 3 disks
echo check | sudo tee /sys/block/md0/md/sync_action    # data scrub (Debian runs this monthly)
sudo mdadm --stop /dev/md0                             # stop the array
sudo mdadm --zero-superblock /dev/sdb1                 # wipe RAID metadata before reusing a disk

mdadm vs hardware RAID vs ZFS

  • mdadm: no controller lock-in, disks readable on any Linux machine, good performance. A solid default.
  • Hardware RAID: offloads work and has a battery-backed cache, but ties you to the controller model, and monitoring needs vendor tools.
  • ZFS / Btrfs: RAID plus checksums that detect silent corruption, snapshots and compression. See ZFS on Linux.

Quick reference

Task Command
Status cat /proc/mdstat
Details mdadm --detail /dev/md0
Create RAID 1 mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
Save config mdadm --detail --scan >> /etc/mdadm/mdadm.conf
Fail and remove mdadm /dev/md0 --fail X --remove X
Add disk mdadm /dev/md0 --add /dev/sdc1
Scrub echo check > /sys/block/md0/md/sync_action

Related: LVM guide and mkfs.

  • Linux
  • Storage
  • Dedicated Server