Skip to content

Server notes

How to repair a degraded RAID array

A field guide to replacing a failed disk in an MD RAID1 array on Ubuntu, from the first smartctl reading to a finished rebuild and a final grub check.

By Jozsef 3 min read

This guide shows how I repair a degraded MD RAID1 array on an Ubuntu server. I assume other Linux distributions behave the same way, so the same steps should work elsewhere.

1. Identify the bad disk

Start with the array state:

bash
$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sdb1[2] sda1[0]
      960805696 blocks super 1.2 [2/2] [UU]

The array is up and running. Now check the disks with smartctl:

bash
smartctl --all /dev/sda
smartctl --all /dev/sdb

In my case /dev/sdb was the failed disk.

2. Remove the bad disk from the array

bash
$ mdadm --manage /dev/md0 --fail /dev/sdb1
$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sdb1[2](F) sda1[0]
      960805696 blocks super 1.2 [2/1] [U_]
$ mdadm --manage /dev/md0 --remove /dev/sdb1
$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sda1[0]
      960805696 blocks super 1.2 [2/1] [U_]

unused devices: <none>

3. Shut down and replace the disk

bash
sudo shutdown -h now

Fit the replacement drive, boot the server, and confirm that it appears under its expected device name.

4. Rebuild the RAID1 array

Copy the partition table from the healthy disk:

bash
sfdisk -d /dev/sda | sfdisk /dev/sdb

Add the new partition to the array:

bash
mdadm --manage /dev/md0 --add /dev/sdb1

5. Wait for the rebuild

bash
$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sdb1[2] sda1[0]
      960805696 blocks super 1.2 [2/1] [U_]
      [>....................]  recovery =  0.3% (3542720/960805696) finish=135.0min speed=118090K/sec

unused devices: <none>

Control the I/O load of the rebuild

The rebuild can saturate a busy server. Check the current ceiling:

bash
$ cat /sys/block/md0/md/sync_speed_max
200000 (system)

The value is in kibibytes per second. The system wide default lives in /proc/sys/dev/raid/speed_limit_max. To lower the ceiling to 30000, write the value to the array file:

bash
$ echo 30000 > /sys/block/md1/md/sync_speed_max

The minimum works the same way: replace max with min in sync_speed_min and speed_limit_min.

6. Confirm that the array is healthy

After a few hours the rebuild should finish:

bash
$ cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sdb1[2] sda1[0]
      960805696 blocks super 1.2 [2/2] [UU]

7. Make sure grub is installed on both disks

Reboot once the array is clean. Then tell grub that the new disk needs a boot loader:

bash
dpkg-reconfigure grub-pc

The installer shows a list of disks. Make sure the new disk is checked before you continue.

What to check next time

Record the serial numbers of both disks before the failure. It makes the replacement step far less stressful, and it prevents you from pulling the wrong drive from a live chassis.

Sources and further reading