Dennis Krul

Archive for June, 2007

Fixing a degraded Linux software RAID-1 mirror

A quick HOWTO on how to fix a degraded Linux software RAID-1 mirror, mostly a reminder for myself in case I run into this problem again.

First replace the faulty disk with a new drive of at least the same size.

Copy the MBR of the active disk (sda) to the new disk (sdb):

# dd if=/dev/sda of=/dev/sdb bs=512 count=1

Copy the partition table of the active disk to the new disk:

# sfdisk -d /dev/sda | sed s/sda/sdb/g > /tmp/ptable
# sfdisk /dev/sdb < /tmp/ptable

Inform MD about the new partitions:

# for MD in /dev/md?
> do
> NEWPART=$(mdadm --detail $MD | awk '/active sync/{ print $7}' | sed s/sda/sdb/)
> mdadm -a $MD $NEWPART
> done

(Disclaimer: Do not just blindly copy and paste these lines. Your setup might be different and you could break stuff if you don’t use mdadm wisely.)

I noticed this particular system wasn’t able to boot from the second disk. It seems that the GRUB bootloader isn’t very much RAID aware and didn’t install the bootloader on to the second disk. So I installed good ol’ LILO instead, which seems to be able to handle such a setup better. I added the following lines to /etc/lilo.conf:

boot=/dev/md0
root=/dev/md1
raid-extra-boot=/dev/sda,/dev/sdb

If you run the lilo command it writes the bootloader to both disks, so you should be able to boot from both, even in case of a failing disk.

4 comments

Drivel

Because the WordPress webinterface is a bit too slowish for me I’m giving Drivel a testdrive. It allows me to post to my weblog straight from my Gnome desktop.

In the past I’ve used gnome-blog but I had some issues with it (which I can’t remember). So far Drivel seems to be more mature.

Comments are off for this post