Running Linux off Flash Drives |
Configuring a Linux Server with RAID-1Last updated: 2009 Sep 25 | Building Routers with Linux |
2002 account amd area array attached away bad boot call cat choose complete copyright course debian did docs existing faster feature field following further having hdc high howto https implementation install instead item loose lost menu minutes monitor names note ones recovery replacement return samba seconds smaller specify think times until updated whole |
See also:
Linux RAID Links
OverviewWhile rebuilding my Linux Samba file server (see: Replacing a Windows NT4 Server) I thought it might be time to investigate protecting its single drive by installing a second similar drive and configuring the system for RAID-1. I had initially thought about this, but in 2005 the state of the software RAID world was in a bit of flux so I filed the task for later. Well at the end of 2007 it looked like later might finally have arrived.I initially did some searching for information (see above) and eventually stumbled across this note on Debian's support area that talks about installing to a combination of RAID and crypto file systems. Ah ha, I thought! The Debian installer does include RAID support, I must have missed it somehow (in my Samba testing I had reinstalled Debian many times without seeing mention of RAID). Turns out they call it SataRaid and as I'm running parallel IDE I probably just skimmed by. Eventually I came across this Debian new installation software RAID1 HOWTO which is a pretty accurate account of how to install your Debian system to a software RAID-1 drive pair, and how to test that it really does work. I followed this guide and got a working system, then I tested it and rebuilt it a couple of times on different hardware to make sure I understood it correctly. Following this guide will enable you to install a Debian 4.0 (Etch) system to a pair of drives in RAID-1 mode, set up your system so that /boot, root and swap are all on RAID-1 devices, reconfigure grub to allow you to boot off either drive, or automatically boot of the good drive in the event one drive fails. The guide also goes through some simple tests that show you how to check the health of the drives, remove a drive from service, put a new drive into the array, partition the new drive and place it into service and how to monitor the rebuilding process. This howto was done on a SCSI system so the device names were a bit different from my system, so I went through some tests to make sure I understood what the commands would be on my system - and to practice in advance to make sure I knew what to do if a drive really did fail. Of course Murphy's Law will apply here and by having spent the time preparing I will never have to use this skill - something else will fail instead. There are a few points worth noting about the RAID install:
Test 1The server I configured had two drives, both set to master on the two IDE channels of the motherboard, so the drives were named: hda and hdc by Linux.For the first test I shutdown the system, disconnected hdc from the IDE cable and started the system up again. The system was still able to boot using hda as expected. Next I shutdown the system and rebooted it using DBAN (Darik's Boot and Nuke), I then proceeded to wipe out the first 4GB of hda (remember hdc was still disconnected so it was safe). I then shutdown the system and reconnected hdc (so now a bad hda and a good hdc are attached). I then rebooted and the system came up running off hdc as expected. The cat /proc/mdstat shows the md0, md1 and md2 devices running in degraded mode using partitions from hdc only. Now it was time to try rebuilding the system (simulating a new, empty disk, having been attached in hda's position). The first command is: sfdisk -d /dev/hdc | sfdisk /dev/hdawhich is a pretty dangerous one, it copies the partition table from the good disk (hdc) over to the new disk (hda). The next thing you do is to use mdadm to add the partitions from the new disk into the raid disks: mdadm --add /dev/md0 /dev/hda1 mdadm --add /dev/md1 /dev/hda2 mdadm --add /dev/md2 /dev/hda3As soon as you do this the rebuilding will start, since md0 and md1 (boot and swap) are pretty small they will rebuild in seconds to minutes, but md2 will probably take some time. You can cat /proc/mdstat to monitor the rebuild progress or try mdadm -D /dev/md2 for more detailed information. Once the rebuild is done you should run grub again: grub root (hd0,0) setup (hd0) root (hd1,0) setup (hd1) quitand at this point you are complete and you can reboot and check that the system can boot off either drive again. Test 2For my second test I repeated the first test, but just swapped the role of the drives. I did this so that I could make certain all the drive letters were documented correctly.In the second test I shutdown the system, disconnected hda from the IDE cable and started the system up again. The system was still able to boot using hdc as expected. Next I shutdown the system and rebooted it using DBAN (Darik's Boot and Nuke), I then proceeded to wipe out the first 4GB of hdc (remember hda was still disconnected so it was safe). I then shutdown the system and reconnected hda (so now a bad hdc and a good hda are attached). I then rebooted and the system came up running off hda as expected. The cat /proc/mdstat shows the md0, md1 and md2 devices running in degraded mode using partitions from hda only. Now it was time to try rebuilding the system (simulating a new, empty disk, having been attached in hdc's position). The first command is: sfdisk -d /dev/hda | sfdisk /dev/hdcwhich is a pretty dangerous one, it copies the partition table from the good disk (hda) over to the new disk (hdc). The next thing you do is to use mdadm to add the partitions from the new disk into the raid disks: mdadm --add /dev/md0 /dev/hdc1 mdadm --add /dev/md1 /dev/hdc2 mdadm --add /dev/md2 /dev/hdc3As soon as you do this the rebuilding will start, since md0 and md1 (boot and swap) are pretty small they will rebuild in seconds to minutes, but md2 will probably take some time. You can cat /proc/mdstat to monitor the rebuild progress or try mdadm -D /dev/md2 for more detailed information. Once the rebuild is done you should run grub again: grub root (hd0,0) setup (hd0) root (hd1,0) setup (hd1) quitand at this point you are complete and you can reboot and check that the system can boot off either drive again. |