We will assume here that your sdb is failed while sda is still working.
1. Removing the HDD from the RAID1
Let's say you are with a "normal" configuration, with 2 RAID1 array, md0 and md1, using 2 partitions on each hard drives. First, you need to declare the HDD partitions failed so you can remove them. Here is how:
mdadm /dev/md0 -f /dev/sdb1
mdadm /dev/md1 -f /dev/sdb5
Then you can remove the partitions from the RAID1:
mdadm /dev/md0 --remove /dev/sdb1
mdadm /dev/md1 --remove /dev/sdb5
2. Powering down the hard drive before hotswap
You can check the current power status of a drive with:
hdparm -C /dev/sdb
To power off the drive, use:
hdparm -Y /dev/sdb
It is then best to put the bus in tristate mode (ready for another drive):
hdparm -b 2 /dev/sdb
3. Changing the physical drive
Remove the bay, change the HDD, plug it back. If you are using SATA and hotswap, you wont need to shutdown your server.
4. Powering the new hard drive
Once you put in the new drive, there still is a possibility that the drive won't be detected under 2.6.16.33, so you can try to attempt to do a rescan:
- find /sys -name scan
/sys/class/scsi_host/host3/scan
/sys/class/scsi_host/host2/scan
/sys/class/scsi_host/host1/scan
/sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scan
echo "- - -" > /sys/class/scsi_host/host3/scan
The other way would be to use scsidev or rescan-scsi-bus.sh script from
http://www.garloff.de/kurt/linux/scsidev/
5. Copying the partition table from sda to sdb
This is done with a single command:
sfdisk -d /dev/sda | sfdisk /dev/sdb
6. Reading the new HDD into the RAID1
Very easy to. Just do this:
mdadm /dev/md0 --add /dev/sdb1
mdadm /dev/md1 --add /dev/sdb5
7. Installtion GRUB on the new disk
This step is often forgot, which is VERY dangerous, because if then your sda fail, you are left with no boot possibilities, and you need to get a rescue CD and recover your GRUB. So here is how to add it again.
grub --no-floppy
Then you enter the grub prompt. Just to make sure, reinstall GRUB on both MBR:
root (hd0,0)
setup (hd0)
root (hd1,0)
setup (hd1)
Now you should be fine. Note that this step has to be done AFTER the 1st partition (the boot one) is in sync with the RAID1, otherwise grub wont be able to install itself correctly and will produce an error on the screen.
8. Some useful tools
If you need to rescan the partition table of a disk, you can use:
parprobe /dev/sda
This one is in the "parted" package.
Editing this page means accepting its license.