old-www/LDP/LG/issue35/blanchard.html

312 lines
16 KiB
HTML

<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<title>Quick and Dirty RAID Information LG #35</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#A000A0"
ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Quick and Dirty RAID Information</font></H1>
<H4>By <a href="mailto:blanchas@cadvision.com">Eugene Blanchard</a></H4>
</center>
<P> <HR> <P>
If you are thinking about implementing a Linux software raid then here is the most important link that you should investigate before you start:
<P>
Linas Vepsta's raid page: <A HREF="http://linas.org/linux/raid.html">
http://linas.org/linux/raid.html</A>
<P>
The date of this posting is Oct 29/98 and the present raid documentation is incomplete and confusing. This posting is to clear up problems that you will encounter implementing raid0 and raid1.
<P>
I wanted to implement mirror over striping. The striping gives good read/write performance increases and the mirroring gives backup and read performance increases.
<P>
I started with kernel 2.0.30 and implemented raid0 (striping). Then I upgraded my kernel to 2.0.35 and the fun began. After struggling to get raid0 working with 2.0.35, I tackled raid1. Well, guess what, throw everything that you learned about raid out the window and start from scratch! A good idea is to start simple, get raid0 up and running then add raid1. The story begins:
<P>
<H3>Raid0 (striping) with kernel 2.0.30</H3>
<P>
Linear and raid0 (striping) are implemented in the kernel since 2.x. You have to recompile your kernel with multiple devices installed. I recommend installing it in the kernel to start. You will have enough problems without implementing it as a module.
<P>
To check if you have multiple devices installed. <tt>dmesg |more</tt> and look to see if you have the md dirver loaded and raid0 registered (can't remember the exact phrase - late at night ;-( )
<P>
Or type <tt>cat /proc/mdstat</tt> to see the status of your md devices. You should see /dev/md0 to /dev/md3 inactive.
<P>
Strangely, the kernel tools mdtools-0.35 are not usually supplied with distributions. These are the tools that are required for setting up the raid, running and stopping it.
<P>
You can find them on the Slackware distribution at (23k in size)
<P>
<A
HREF="http://sunsite.unc.edu/pub/Linux/distributions/slackware/slakware/ap1/md.tgz">http://sunsite.unc.edu/pub/Linux/distributions/slackware/slakware/ap1/md.tgz</A>
<P>
Download to /usr/local/src then:
<PRE>
cd /
tar -zxvf /usr/local/src/md.tgz
</PRE>
It will put the files in the correct place.
<PRE>
sbin/mdadd
sbin/mdcreate
usr/etc/mdtab
install/doinst.sh
usr/man/man5/mdtab.5.gz
usr/man/man8/mdadd.8.gz
usr/man/man8/mdcreate.8.gz
usr/doc/md/COPYING
usr/doc/md/ChangeLog
usr/doc/md/README
usr/doc/md/md_FAQ
</PRE>
Read through the README file (ignore warnings of course) The documentation is quite good for kernel 2.0.30 and linear /raid0 mode. The Linux Journal (June or July 98) has an excellent article on how to implement raid0 (striping). It was what spiked my interest.
<P>
The Linux Gazette has another article that helps:<BR>
<A HREF="http://www.ssc.com/lg/issue17/raid.html">
http://www.ssc.com/lg/issue17/raid.html</A>
<P>
You should start the raid array before <tt>fsck -a</tt>, usually located in /etc/rc.d/rc.s for slackware distributions and should stop the raid array in both /etc/rc.d/rc.0 and rc.6. (BTW since they are identical files in slackware, can't we just do a softlink from one to the other and modify only one?)
<P>
To check to see if it is working, type <tt>cat /proc/mdstat</tt>, it should indicate what states the md devices are (/dev/md0 raid0 using /dev/sda1 and /dev/sdb1).
<P>
Test, test, test your raid. Shutdown, power-up, see if it is working like you expected.
<P>
I did some fancy copying using <tt>cp -rap</tt> switches to copy complete directory structures to the raid arrays. Then modified /etc/fstab to include the new drives.
<P>
Swap partitions do not need to be striped. They are automatically striped if a priority is used. Check the Software-RAID-mini-HOWTO and the Bonehead question section for details. It is amazingly simple.
<P>
<H3>Implement UPS NOW!</H3>
<P>
If you lose power (AC line), you will lose your raid array and any data that is on it! You should implement a UPS backup power supply. The purpose of the UPS is to keep your system running for a short period of time during brownouts and power fails. The UPS should inform your system that the power has failed through a serial port. There is a daemon that runs in the background that monitors the serial port. When it is informed that there is a power failure, it will wait a preset period of time (usually 5 minutes) than perform a system shutdown. The idea is that after 5 minutes of no power, the power will be down for a long time.
<P>
Most Linux distributions come with the basic UPS daemon powerd. Check "man powerd" for more info. It is a simple daemon that is implemented in /etc/inittab under what happens when the power fails. Basically, a dumb UPS, just closes a relay contact that is connected to the serial port. powerd monitors to see if the contact has closed. If it does it shuts down the PC after a predetermined time, warns users and can send an email to root.
<P>
I used an APC smart UPS that communicates through the serial port. There is an excellent daemon called apcupsd that works like a charm. It is located here. Please read the notice and sympathize with the author, he has done an excellent job (kudos to the author!). The installation works like a charm and the documentation is excellent.
<P>
<A HREF="http://www.dyer.vanderbilt.edu/server/apcupsd/">
http://www.dyer.vanderbilt.edu/server/apcupsd/</A>
<P>
<H3>RAID0 and 2.0.31 to 2.0.34</H3>
<P>
Don't have a clue. I upgraded from 2.0.30 to 2.0.35 because 2.0.35 is the latest stable release.
<P>
<H3>RAID0 and Kernel 2.0.35</H3>
<P>
The mdtools compiled perfectly on my home machine (testbed running 2.0.30) but would not compile on my work machine (upgraded to 2.0.35). I kept getting an error about MD_Version (can't remember the exact name) not being defined. After a lot of head scratching and searching, I found that /usr/src/include/md.h contains the version number of the md driver. With version 2.0.30, it was ver 0.35, with 2.0.35 it is ver 0.36. If you "mdadd -V" it will indicate the version of md that mdadd will work with. So I had the wrong mdtools version. Here is the location of the correct version:
<P>
ftp://ftp.kernel.org/pub/linux/daemons/raid/raidtools-0.41.tar.gz
<P>
Download to /usr/local/src then
<PRE>
tar -zxvf raidtools-0.41.tar.gz
</PRE>
A new directory will be made /usr/local/src/raidtools-0.41
<P>
Change to the new directory and read the INSTALL file, then
<PRE>
./configure
</PRE>
I can't remember if I had to then <tt>make</tt> and <tt>make install</tt> after this. I can't duplicate this now that I've upgraded to a new raid patch.
<P>
You should have a new mkraid and mdadd binary. Type <tt>mdadd -V</tt> to
check if your binaries are updated. It should respond with something that
says something like <tt>mdadd 0.3d compiled for raidtools-0.41</tt>. Then read the QuickStart.RAID for the latest info. For raid0, not much has changed from the previous versions.
<P>
<H3>RAID1 and Kernel 2.0.35</H3>
<P>
You must patch the kernel to enable RAID 1, 4 and 5. The patch is located at
<P>
<A
HREF="ftp://ftp.kernel.org/pub/linux/daemons/raid/alpha/raid0145-19981005-c-2.0.35.tz">
ftp://ftp.kernel.org/pub/linux/daemons/raid/alpha/raid0145-19981005-c-2.0.35.tz</A>
<P>
Copy to /usr/src directory and uncompress the patch:
<PRE>
tar -zxvf raid0145-19981005-c-2.0.35.tz
</PRE>
Note the patch will be looking for /usr/src/linux-2.0.35 directory. If you
have your 2.0.35 source installed as /usr/src/linux, you should <tt>mv
/usr/src/linux /usr/src/linux-2.0.35</tt> and soft link /usr/src/linux to
it. <tt>ln -s /usr/src/linux-2.0.35 /usr/src/linux</tt>
<P>
To apply the patch, in /usr/src:
<PRE>
patch -p0 &lt;raid0145-19981005-C-2.0.35
</PRE>
(someplace the lowercase c got changed to an uppercase C in my system? Maybe after tar?)
<P>
You now get to recompile the kernel. When you select multiple devices, you will see options for raid 1, 4 and 5 available. So the steps are
<PRE>
make menuconfig (or config or xconfig)
make clean
make dep
make zImage
make modules (if you are using modules)
make modules_install
</PRE>
Copy the new kernel to wherever your distribution looks for it (/ or /boot). I suggest that you have a base kernel that works without raid and then a raid kernel. You can modify lilo.conf to allow you to select which kernel that you want to boot to. It's not difficult at all but at first glance it looks terrifying. Check /usr/lib/lilo for good examples and documentation.
<P>
Check <tt>dmesg | more</tt> to see if you have md drivers loaded and raid0
& 1 registered. Type <tt>cat /proc/mdstat</tt> to see if you have the new md driver. You should see 16 md devices instead of 4.
<P>
You will have to upgrade your raidtools. mdadd, /etc/mdtab and mdcreate are obsolete as well as a bunch of others. The new tools are raidstart, /etc/raidtab and mkraid. At this point the documentation is well out of date.
<P>
<A
HREF="ftp://ftp.kernel.org/pub/linux/daemons/raid/alpha/raidtools-19981005-B-0.90.tar.gz">
ftp://ftp.kernel.org/pub/linux/daemons/raid/alpha/raidtools-19981005-B-0.90.tar.gz</A>
<P>
Download to /usr/local/src then
<PRE>
tar -zxvf raidtools-19981005-B-0.90.tar.gz
</PRE>
This will make a new directory /usr/local/src/raidtools-0.90. Change to it and
<PRE>
./configure
</PRE>
Again, I can't remember if I had to then <tt>make</tt> and <tt>make install</tt> after this.
<P>
<H3>New Simpler Method for RAID0 and Kernel 2.0.35</H3>
<P>
Steps to make a raid0 array /dev/md0 using two scsi drives /dev/sda1 and /dev/sdb1:
<ol>
<li>Partition /dev/sda1 and /dev/sdb1 so that they have identical block sizes.
<li>Set the parition type to 0xfd. This is used by the new kernel to autodetect the raid on startup.
<li>Modify the /etc/raidtab file as per this example (the examples supplied with the raidtools are missing some important info):
<PRE>
# Striping example
# /dev/md0 using /dev/sda1 and /dev/sdb1
raiddev /dev/md0
raid-level 0
nr-raid-disks 2
persistent-superblocks 1
nr-spare-disks 0
chunk-size 32
device /dev/sda1
raid-disk 0
device /dev/sdb1
raid-disk 1
</PRE>
<li>Type <tt>mkraid -f /dev/md0</tt> IMPORTANT - Read the error message and FOLLOW the directions explicitly!
<li>cat /proc/mdstat to see if the md device was made correctly
<li>Format the new raid device by <tt>mke2fs -c /dev/md0</tt>
<li>Make a directory to mount to (like /raidtest) just to test if it works.
<li><tt>mount /dev/md0 /raidtest</tt>
<li>Copy a file to /raidtest to see if you can. If you have individual LEDs on your hard-drives, you should see both drives working.
<li>Reboot and see if the kernel autmatically shuts down the raid device md0. There should be some messges scroll past the screen. (anyone know how to read these shutdown messages like "dmesg"?)
<li>Check that on rebooting the computer that the kernel autodetects the raid devices and /dev/md0 comes up as a raid0 array. If not check that each of the previous steps have been followed especially step 2 and 4.
</ol>
<P>
<H3>New Method for RAID1 and Kernel 2.0.35</H3>
<P>
Steps to make a raid1 array /dev/md2 using two striped pairs /dev/md0 (/dev/sda1 + /dev/sdb1) and /dev/md1 (/dev/sdc1 + /dev/sdd1:
<ol>
<li>Follow the steps above for /dev/md0 and duplicate for /dev/md1. IMPORTANT - You don't mount or mke2fs /dev/md0 and /dev/md1. This was only to test if the raid0 worked!
<li>Modify the /etc/raidtab file as per this example (the examples supplied with the raidtools are missing some important info):
<PRE>
# Striping example
# /dev/md0 using /dev/sda1 and /dev/sdb1
raiddev /dev/md0
raid-level 0
nr-raid-disks 2
persistent-superblocks 1
nr-spare-disks 0
chunk-size 32
device /dev/sda1
raid-disk 0
device /dev/sdb1
raid-disk 1
# /dev/md1 using /dev/sdc1 and /dev/sdd1
raiddev /dev/md1
raid-level 0
nr-raid-disks 2
persistent-superblocks 1
nr-spare-disks 0
chunk-size 32
device /dev/sdc1
raid-disk 0
device /dev/sdd1
raid-disk 1
# Mirror example
# /dev/md2 using /dev/md0 and /dev/md1
raiddev /dev/md2
raid-level 1
nr-raid-disks 2
persistent-superblocks 1
nr-spare-disks 0
chunk-size 32
device /dev/md0
raid-disk 0
device /dev/md1
raid-disk 1
</PRE>
<li>Type "mkraid -f /dev/md2" IMPORTANT - Read the error message and FOLLOW the directions explicitly! This step will take a while as the disks are synced together (over 30 min)
<li><tt>cat /proc/mdstat</tt> to see if the md devices was made correctly
<li>Format the new raid device by <tt>mke2fs -c /dev/md2</tt>
<li>Make a directory to mount to (like /raidtest_mirror)
<li><tt>mount /dev/md0 /raidtest</tt>
<li>Copy a file to /raidtest to see if you can. If you have individual LEDs on your hard-drives, you should all drives working.
<li>Add <tt>raidstart /dev/md2</tt> to your /etc/rc.d/rc.s file just before
<tt>fsck -a</tt>. A good place is right after <tt>swapon -a</tt>. At this time, the kernel does not autodetect raid1. This will be added to the next patch.
<li>Modify /etc/fstab to mount /dev/md2 as /raidtest.
<pre>
/dev/md2 /raidtest ext2 defaults 1 1
</pre>
<li>Reboot and see if the kernel autmatically shuts down the raid device md0, md1 and md2. There should be some messges scroll past the screen. (anyone know how to read these shutdown messages like "dmesg"?)
<li>Check that on rebooting the computer that the kernel autodetects the raid devices /dev/md0 and /dev/md1 both come up as raid0 arrays. Check that /dev/md2 is detected as a raid1 array.
<li> cat /proc/mdstat to see if the md devices were made correctly.
</ol>
You should have raid1 over raid0 array running.
<P>
Other resources that you may want to look at if you run into trouble:
<ol>
<li>The linux raid archives:
<A HREF="http://www.linuxhq.com/lnxlists/linux-raid/">
http://www.linuxhq.com/lnxlists/linux-raid/</A>
<li>Post a news message to comp.os.linux.setup
<li>Search www.dejanews.com - archive site of the past 5 years of news postings
<li>Absolutely last if you are really stuck, e-mail the Linux RAID Mailing List.
To send an enquiry, e-mail <A HREF="mailto:linux-raid@vger.rutgers.edu">
linux-raid@vger.rutgers.edu</A><BR>
To join the kernel RAID list, e-mail <A
HREF="mailto:majordomo@vger.rutgers.edu">majordomo@vger.rutgers.edu</A> and put in the body of the message
<tt>subscribe linux-raid</tt>
<li>Don't e-mail me, everything I know is recorded here!
</ol>
<!--===================================================================-->
<P> <hr> <P>
<center><H5>Copyright &copy; 1998, Eugene Blanchard <BR>
Published in Issue 35 of <i>Linux Gazette</i>, December 1998</H5></center>
<!--===================================================================-->
<P> <hr> <P>
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="./marshall.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./lg_backpage35.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
<!--startcut ==========================================================-->
</BODY>
</HTML>
<!--endcut ============================================================-->