Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 37 ยท Storage and Filesystems

Software RAID with mdadm and Disk Health Monitoring

Understand RAID 0, 1, 5, 6 and 10, build and monitor mdadm arrays, replace failed disks and check drive health with SMART tools before data is lost.

Disks fail. RAID (Redundant Array of Independent Disks) combines several disks so the system survives some failures, or runs faster, or both. Linux implements software RAID with the md driver and manages it with mdadm. Pair it with health monitoring so you replace a dying disk before the array loses its redundancy.

RAID levels

Level Disks (min) Usable space Survives Notes
RAID 0 2 All Nothing Striping for speed; any failure loses everything
RAID 1 2 One disk's worth N-1 disks Mirror; simple and safe
RAID 5 3 N-1 disks 1 disk Striping with distributed parity
RAID 6 4 N-2 disks 2 disks Double parity, for large arrays
RAID 10 4 Half 1 per mirror pair (often more) Mirrors that are striped; fast and resilient

RAID is not a backup. It protects against disk failure only. Deleted files, corruption, ransomware and fire go to every copy. Keep real backups (backups).

With very large disks, rebuild time is long and a second failure during the rebuild is a real risk, so RAID 6 or RAID 10 is preferred over RAID 5 for big arrays.

Creating an array

Terminal
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
sudo mkfs.ext4 /dev/md0
cat /proc/mdstat                       # sync progress
sudo mdadm --detail /dev/md0

Save the array definition so it assembles at boot (the config path is /etc/mdadm/mdadm.conf on Debian, /etc/mdadm.conf on Red Hat):

Terminal
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u                # Debian family
sudo dracut --force                     # Red Hat family

Then mount by UUID in fstab. Arrays are usable while still syncing, just slower.

Reading /proc/mdstat

TEXT
md0 : active raid1 sdc1[1] sdb1[0]
      52395008 blocks super 1.2 [2/2] [UU]

[2/2] means two of two members active, and [UU] means both up. A failed disk shows [U_]. Look for that first when investigating.

Replacing a failed disk

Terminal
sudo mdadm /dev/md0 --fail /dev/sdc1       # mark failed (if not already)
sudo mdadm /dev/md0 --remove /dev/sdc1
# swap the physical disk, partition it like the old one
sudo mdadm /dev/md0 --add /dev/sdc1
watch cat /proc/mdstat                     # rebuild progress

Make sure the replacement has at least the same size. Also remember the bootloader: if the system boots from the array, install it on both disks.

Monitoring and e-mail alerts

mdadm --monitor or the packaged monitoring service sends mail when an array degrades. Set MAILADDR [email protected] in mdadm.conf and make sure the machine can send mail. An array running degraded and unnoticed for weeks is the usual way people lose data.

Terminal
sudo mdadm --monitor --scan --oneshot --test      # sends a test alert
echo check | sudo tee /sys/block/md0/md/sync_action   # scrub: read and verify

Many distributions schedule a monthly scrub.

Disk health with SMART

Drives report health data through SMART. The smartmontools package provides smartctl and the smartd daemon.

Terminal
sudo smartctl -H /dev/sda                 # overall health
sudo smartctl -a /dev/sda                 # all attributes
sudo smartctl -t short /dev/sda           # run a self-test
sudo smartctl -l selftest /dev/sda
sudo nvme smart-log /dev/nvme0            # NVMe

Watch attributes such as reallocated sectors (5), pending sectors (197) and uncorrectable errors (198). A rising count means the disk is failing; replace it even if the overall status says PASSED. For NVMe, watch "Percentage Used", "Media errors" and "Available Spare".

flowchart LR
    A["SMART warning or [U_]"] --> B["Order a spare"]
    B --> C["mdadm --fail, --remove"]
    C --> D["Swap and partition"]
    D --> E["mdadm --add"]
    E --> F["Wait for rebuild"]

A planned replacement beats an emergency.

A stand-in: capacity and fault tolerance

This model computes usable space for each RAID level. It follows the standard formulas.

Python Stand-in: RAID capacity calculator

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A stand-in: parse /proc/mdstat

This model reads a made-up /proc/mdstat and flags degraded arrays, as a monitoring script would.

Python Stand-in: detect a degraded array

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Common mistakes

  • Treating RAID as a backup.
  • Ignoring degraded arrays because everything still works.
  • Building RAID 5 from huge disks and a long rebuild window.
  • Not saving the array in mdadm.conf or not rebuilding the initramfs.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which RAID level survives any two disk failures?

    RAID 6 uses double parity.
  2. 2. What does [U_] in /proc/mdstat mean for a two-disk mirror?

    An underscore marks a member that is down, so the array is degraded.
  3. 3. Why is RAID not a backup?

    RAID protects against hardware failure, not human or software mistakes.
  4. 4. Which tool reads drive SMART data?

    smartctl from smartmontools reports health and attributes.

Summary

  • RAID 1, 5, 6 and 10 add redundancy; RAID 0 only adds speed.
  • mdadm creates and repairs arrays; /proc/mdstat shows state.
  • Monitor and alert on degraded arrays; replace disks promptly.
  • Use SMART to catch failing disks early, and keep separate backups.

Next: Quotas, Backups and Disk Usage