Apr 02

Rebuilding a software RAID

Category: Linux   — Published by tengo on April 2, 2008 at 1:36 pm

The are numerous scenarios possible, where a RAID system can get out of sync. That means that the data on one disk is not exactly the same as on the other drive - although these two disks should be in perfect sync all the time. But don't panic, this is what RAID was actually made for. And there are easy procedures to resync drives that were seperated by hardware failure, unscheduled power loss, configuration problems and the like. You can actually simulate the failure of one drive like this:

mdadm --manage /dev/md0 --fail /dev/sdc

This removes drive "sdc" from the RAID system and immediately the system is out of sync, or "dirty".

Now, to resync the system you need to first remove the drive from the array and then add it back in:

mdadm --manage /dev/md0 --remove /dev/sdc
mdadm --manage /dev/md0 --add /dev/sdc

You can watch the resyncing with

watch -n 1 "cat /proc/mdstat"

Depending on your system, resyncing can bee slow. This is actually a design feature that should prevent the rebuilding to overload the system. On a system that is idle or not so busy, you can speed this temporarily up with

sudo -s -H

to get access to the file on ubuntu, and

echo 50000 >/proc/sys/dev/raid/speed_limit_min

Info about the status of your array:

$ cat /proc/mdstat
and:
$ sudo mdadm --detail /dev/md0

Further reading:

How-to setup a RAID 1 disk array system

How do I resync a "dirty" software raid1?

Failed rebuilding

Resizing a RAID 1

Software vs Hardware RAID