Build RAID 1 and RAID 5 from loop devices, fail a member, and rebuild

short · 50 min · Objective 1.2

Task

Build a RAID 1 mirror and a RAID 5 array with Linux software RAID, write data with a known checksum, fail one member of each, confirm the data survives in the degraded state, then replace the member and watch the rebuild. The point is to see the three states -- optimal, degraded, rebuilding -- and to prove the data is unchanged through all of them.

Steps

  1. Create five 200 MB files with truncate -s 200M /srv/disk{1..5}.img and attach each with losetup -f --show, noting the loop device names.
  2. Build a RAID 1 array from two loop devices with mdadm --create /dev/md1 --level=1 --raid-devices=2 and a RAID 5 array from the other three as /dev/md5. mdadm builds RAID 5 by recovering its last member, so wait until /proc/mdstat shows [UUU] with no recovery line, then save it to lab/raid/optimal.txt.
  3. Create a file system on each with mkfs.ext4, mount them, copy the same test file to both, and save sha256sum of each copy to lab/raid/before.txt.
  4. Fail one member of each array with mdadm --fail and mdadm --remove. Save cat /proc/mdstat to lab/raid/degraded.txt and the checksums of both copies to lab/raid/degraded-sums.txt.
  5. Add a fresh loop device back to each array with mdadm --add, wait for the rebuild to finish (watch /proc/mdstat), then save it to lab/raid/rebuilt.txt and the checksums to lab/raid/after.txt.
  6. Record in lab/raid/levels.csv with header level,disks,usable_fraction,failures_survived the figures for RAID 0, 1, 5, 6 and 10 with four disks each.

Verify

These checks run in a POSIX shell: Terminal on macOS or Linux, and on Windows Git Bash (it comes with Git for Windows) or WSL. A stock Windows PowerShell or Command Prompt has no awk or grep, so there the first line fails.

grep -c 'UU' lab/raid/optimal.txt
grep -Ec '_U|U_' lab/raid/degraded.txt
awk '{print $1}' lab/raid/before.txt | sort -u | wc -l
diff <(awk '{print $1}' lab/raid/before.txt) <(awk '{print $1}' lab/raid/after.txt) && echo checksums unchanged
awk -F, 'NR>1 {n++} END {print n" level(s) recorded"}' lab/raid/levels.csv

The optimal capture shows all members up, the degraded one shows an underscore for the missing member, and the rebuilt checksums match the originals. One distinct checksum in the before file means both copies were identical to start with. RAID 0 in your table must survive zero failures; if it says anything else, reread the RAID lesson before the capstone.

Notes

mdadm --detail /dev/md5 shows the same states with more words, including rebuild progress as a percentage. On real disks the rebuild takes hours, which is the window the storage failure lesson warns about.

This is an independent study companion for CompTIA Server+ SK0-005 and is not produced by or endorsed by CompTIA.