LinuxXVII · Software RAIDRAID operations
Degraded arrays and rebuilds - replacing a failed disk
What you'll learn
- Identify a degraded array and the failed device
- Replace a failed disk and rebuild the array
- Monitor rebuild progress and verify completion
- Avoid the common rebuild pitfalls
Prerequisites
Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09
A failed disk in a RAID array is a routine operational event. The array goes degraded, performance drops, and the operations team must replace the disk and rebuild. This lesson walks through the workflow.
Identifying a degraded array
$ cat /proc/mdstatPersonalities : [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid5 sdd[3] sdc[2] sdb[1]
6287424 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [_UUU]
bitmap: 1/1 pages [4KB], 65536KB chunkA degraded array shows:
/proc/mdstatwith[N/(N-1)]or similar.- A
_in the device layout line, at the position of the missing slot. State : clean, degradedinmdadm --detail.- Performance is reduced (reads from one disk, writes to all).
- The kernel log shows a mdadm event.
Reading the line properly
Both bracketed groups on the second line are per-slot, and they must agree with the device list above them. Learn to check that, because an array that does not add up means you have misread it.
md0 : active raid5 sdd[3] sdc[2] sdb[1]
6287424 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [_UUU]
| | |
raid-devices (slots) --------------------------------------' | |
in-sync devices ---------------------------------------------' |
per-slot state, slot 0 first ------------------------------------'
[4/3]- 4 slots exist, 3 hold an in-sync device.[_UUU]- slot 0 is the gap; slots 1, 2 and 3 are up. That matches the device list exactly:sdb[1],sdc[2],sdd[3], and nothing at 0.- The number in brackets after a device name is its slot,
not its position in the list. A device with an index at or
above the slot count -
sde[4]in a 4-slot array - is a spare, or a device currently rebuilding into a slot. It does not becomeUuntil recovery finishes; when it does, md re-reports it under its new slot number (sde[0]). (W)after a device marks a write-mostly member,(F)a faulty one,(S)a spare.
Identifying the physical disk
This is the highest-stakes step of the whole procedure. Pull the wrong drive from a degraded RAID5 and the array is gone.
$ lsblk -o NAME,SERIAL,WWN,MODEL /dev/sdc; sudo smartctl -i /dev/sdc | grep -E 'Serial Number|Device Model'NAME SERIAL WWN MODEL
sdc WD-WCC4N1234567 0x50014ee2b1234567 WDC WD40EFRX-68N32N0
Device Model: WDC WD40EFRX-68N32N0
Serial Number: WD-WCC4N1234567Replacing a failed disk
- Confirm the failure: cat /proc/mdstat; mdadm --detail /dev/md0
- Map the md member to a physical disk BEFORE touching anything: lsblk -o NAME,SERIAL,WWN,MODEL /dev/sdX; sudo smartctl -i /dev/sdX
- Mark the device faulty if md has not already done so: sudo mdadm /dev/md0 --fail /dev/sdX
- Remove it logically: sudo mdadm /dev/md0 --remove /dev/sdX
- Only now physically pull the drive and insert the replacement
- Re-check the new device name, because hot-swap renumbers devices: lsblk
- Add the replacement: sudo mdadm /dev/md0 --add /dev/sdY
- Monitor the rebuild: cat /proc/mdstat
- Verify completion: mdadm --detail /dev/md0 shows State : clean
Two ordering rules are load-bearing here.
Fail before remove. man mdadm says of --remove: “remove listed
devices. They must not be active. i.e. they should be failed or spare
devices.” In the common real case — a disk throwing media errors and
SMART warnings that md has not yet kicked out — --remove on its own
returns mdadm: hot remove failed for /dev/sdc: Device or resource busy
and you are stuck mid-incident. --fail is what makes the device
non-active so that --remove is legal.
Remove before you pull. Physically extracting a disk that md still
considers active drops a healthy array straight to degraded (or a
degraded array to failed), and the resulting hot-swap event renumbers
/dev/sdX, so the commands you had queued now point at the wrong disk.
$ sudo mdadm /dev/md0 --fail /dev/sdc; sudo mdadm /dev/md0 --remove /dev/sdc; sudo mdadm /dev/md0 --add /dev/sddmdadm: set /dev/sdc faulty in /dev/md0
mdadm: hot removed /dev/sdc from /dev/md0
mdadm: added /dev/sddMonitoring the rebuild
$ cat /proc/mdstatmd0 : active raid5 sde[4] sdd[3] sdc[2] sdb[1]
6287424 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [_UUU]
[==>..................] recovery = 12.5% (262144/2095808) finish=2.0min speed=14553K/sec
bitmap: 1/1 pages [4KB], 65536KB chunkSixty seconds later:
$ sleep 60; cat /proc/mdstatmd0 : active raid5 sde[4] sdd[3] sdc[2] sdb[1]
6287424 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [_UUU]
[=====>...............] recovery = 28.4% (595200/2095808) finish=1.5min speed=16673K/sec
bitmap: 1/1 pages [4KB], 65536KB chunkWhen rebuilds fail
$ mdadm --detail /dev/md0 | head -10---$ sudo mdadm --examine /dev/sdb | grep -E 'Array UUID|Device UUID|Device Role|Array State|Events' Array UUID : 9d2c1f5a:44b7e021:6c3f9a18:0e5d7b42
Device UUID : 1c7a4e93:2f80b5d6:a4917c30:88bde215
Device Role : Active device 1
Array State : AAA. ('A' == active, '.' == missing, 'R' == replacing)
Events : 18402If a rebuild fails (bad sectors on the replacement disk, second failure during rebuild), the array remains degraded. The operations team has three options: replace the new disk and retry, restore from backup, or live with the degraded array while planning a replacement.
Knowledge check
Knowledge check · 4 questions
Q1. How do you identify which physical disk to pull from the chassis?
Q2. A RAID5 rebuild on a 10 TB disk takes about 14 hours at 200 MB/s.
Q3. Which of the following are correct RAID rebuild practices? Select all that apply.
Q4. A monitoring alert reports SMART pending sectors on /dev/sdc, a member of a healthy 4-disk RAID5. The disk is still serving reads. A spare bay is free. What do you run?
Passing score: 75%. Answers are checked in this browser.