Storage Fundamentals Series

➕ A Top 1% Hands-On for Building RAID5 With mdadm and Confirming Parity-Based Data Recovery Yourself

Introduction

This article is part of the Top 1% Series Complete Article Guide, and the ninth article in the Storage Fundamentals Series. You can follow along with one of the Ubuntu Server environments set up in the Hands-On Prep Manual.

Prerequisite Knowledge

Getting the Big Picture

This hands-on covers four steps.

graph LR
    Step1["Step 1<br/>Build a RAID5 array<br/>across 3 virtual disks"]
    Step2["Step 2<br/>Deliberately mark<br/>one disk as failed"]
    Step3["Step 3<br/>Confirm data stays<br/>accurate, degraded"]
    Step4["Step 4<br/>Add a new disk, confirm<br/>a parity-based rebuild"]
    Step1 --> Step2 --> Step3 --> Step4

Hands-On Steps

Step 1: Build a RAID5 Array Across Three Virtual Disks

As in the RAID1 hands-on, treat files as loopback devices. This time, set up three virtual disks, RAID5’s minimum configuration.

sudo apt install -y mdadm
for i in 1 2 3; do
  sudo dd if=/dev/zero of=/disk$i.img bs=1M count=100
  sudo losetup /dev/loop$i /disk$i.img
done

Create a RAID5 array across your three virtual disks.

sudo mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/loop1 /dev/loop2 /dev/loop3

Check the array’s state.

sudo mdadm --detail /dev/md0

Output (relevant part):

Raid Level : raid5
Array Size : 204800 (200.00 MiB)
Active Devices : 3

You confirmed that despite having three disks, the Array Size (the array’s real usable capacity) only comes out to about two disks’ worth (200MiB), roughly twice one disk’s own capacity (about 100MiB). As covered in the lecture, this is because, of the three disks, one disk’s worth of capacity goes to parity. Create a filesystem and write some data.

sudo mkfs.ext4 /dev/md0
sudo mkdir -p /mnt/raid5
sudo mount /dev/md0 /mnt/raid5
echo "raid5 test data" | sudo tee /mnt/raid5/data.txt

Step 2: Deliberately Mark One Disk as Failed

sudo mdadm --manage /dev/md0 --fail /dev/loop2
sudo mdadm --detail /dev/md0

Output (relevant part):

State : clean, degraded
Active Devices : 2
Failed Devices : 1

Just as in the RAID1 hands-on, the array entered a degraded state.

Step 3: Confirm Data Stays Accurately Readable, Degraded

cat /mnt/raid5/data.txt
echo "still working with 1 disk failed" | sudo tee -a /mnt/raid5/data.txt
cat /mnt/raid5/data.txt

Output:

raid5 test data
raid5 test data
still working with 1 disk failed

You confirmed reads and writes continue accurately even after one disk got marked as failed, using the two remaining disks and the parity relationship computable from them. Thanks to the XOR property covered in the lecture, every read recomputes the lost disk’s data on the spot, from the remaining information.

How the Degraded State's Behavior Differs From RAID1

In the RAID1 hands-on, the degraded state was a simple one: “the other, complete duplicate still remains.” RAID5’s degraded state, by contrast, rests on a more complex process: recomputing the lost data on the spot, every time, from the remaining disks’ data and the parity relationship. Because of this, reads and writes in RAID5’s degraded state generally carry extra computational overhead compared to RAID1’s, tending toward lower performance.

Step 4: Add a New Disk and Confirm a Parity-Based Rebuild

sudo mdadm --manage /dev/md0 --remove /dev/loop2
sudo dd if=/dev/zero of=/disk4.img bs=1M count=100
sudo losetup /dev/loop4 /disk4.img
sudo mdadm --manage /dev/md0 --add /dev/loop4
cat /proc/mdstat

Output (relevant part):

md0 : active raid5 loop4[3] loop3[2] loop1[0]
      recovery = 38.1% (...) finish=0.1min speed=...

You confirmed the rebuild in progress. Once the rebuild finishes, mdadm --detail /dev/md0 confirms it’s back to Active Devices: 3 and State: clean. Internally, this rebuild process reconstructs the lost disk’s data onto the new disk, using the parity calculation, from the data on the two remaining disks. This is a fundamentally different process from RAID1’s rebuild, which simply copied the other disk’s content as-is.

What a Pro Sees Here (Top 1% Understanding)

RAID5’s “Tolerance for a Single Failure” Always Comes at the Cost of Computation

Through this hands-on, you confirmed that even though RAID5 achieves the same outcome as RAID1 — “tolerates a single failure” — what actually happens internally is entirely different. RAID1 simply “reads a duplicate,” while RAID5 “recomputes from the remaining data and parity, every time.” When multiple implementations exist satisfying the same functional requirement (tolerating a single failure), identifying exactly what cost each implementation actually pays (computational overhead, performance impact) is essential to evaluating a design. This shares the same underlying view as the token bucket versus the fixed window, achieving the same goal — “rate limiting” — at different implementation costs.

Common Misconceptions and Pitfalls

Troubleshooting Perspective

  1. RAID5’s degraded state shows significantly degraded performance: This is likely caused by RAID5’s own degraded-state-specific load — recomputing from parity on every operation — and is expected behavior.
  2. RAID5’s Array Size is smaller than expected: Since one disk’s worth of capacity goes to parity, (disk count - 1) × one disk's capacity is the correct real usable capacity.
  3. A second disk failed during the rebuild: RAID5 only tolerates a single failure, so data is lost in this case. RAID6 would tolerate a second failure too.

Summary

Takeaways to Apply Today

  1. When evaluating a RAID type, check not just “what it tolerates,” but “what internal process actually achieves that tolerance.”
  2. When you run into degraded performance during a degraded state or rebuild, first check whether it’s expected behavior, given that RAID type’s own mechanism.

References

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).