home *** CD-ROM | disk | FTP | other *** search
/ PC World 1999 August / PCWorld_1999-08_cd.bin / doc / HOWTO / mini / Software-RAID < prev    next >
Text File  |  1998-11-29  |  108KB  |  2,971 lines

  1.   Software-RAID HOWTO
  2.   Linas Vepstas, linas@linas.org
  3.   v0.54, 21 November 1998
  4.  
  5.   RAID stands for ''Redundant Array of Inexpensive Disks'', and is meant
  6.   to be a way of creating a fast and reliable disk-drive subsystem out
  7.   of individual disks.  RAID can guard against disk failure, and can
  8.   also improve performance over that of a single disk drive.  This docu¡
  9.   ment is a tutorial/HOWTO/FAQ for users of the Linux MD kernel exten¡
  10.   sion, the associated tools, and their use.  The MD extension imple¡
  11.   ments RAID-0 (striping), RAID-1 (mirroring), RAID-4 and RAID-5 in
  12.   software. That is, with MD, no special hardware or disk controllers
  13.   are required to get many of the benefits of RAID.
  14.   ______________________________________________________________________
  15.  
  16.   Table of Contents
  17.  
  18.  
  19.   1. Introduction
  20.  
  21.   2. Understanding RAID
  22.  
  23.   3. Setup & Installation Considerations
  24.  
  25.   4. Error Recovery
  26.  
  27.   5. Troubleshooting Install Problems
  28.  
  29.   6. Supported Hardware & Software
  30.  
  31.   7. Modifying an Existing Installation
  32.  
  33.   8. Performance, Tools & General Bone-headed Questions
  34.  
  35.   9. High Availability RAID
  36.  
  37.   10. Questions Waiting for Answers
  38.  
  39.   11. Wish List of Enhancements to MD and Related Software
  40.  
  41.  
  42.  
  43.   ______________________________________________________________________
  44.  
  45.  
  46.      Preamble
  47.         This document is copyrighted and GPL'ed by Linas Vepstas
  48.         (linas@linas.org).  Permission to use, copy, distribute this
  49.         document for any purpose is hereby granted, provided that the
  50.         author's / editor's name and this notice appear in all copies
  51.         and/or supporting documents; and that an unmodified version of
  52.         this document is made freely available.  This document is
  53.         distributed in the hope that it will be useful, but WITHOUT ANY
  54.         WARRANTY, either expressed or implied.  While every effort has
  55.         been taken to ensure the accuracy of the information documented
  56.         herein, the author / editor / maintainer assumes NO
  57.         RESPONSIBILITY for any errors, or for any damages, direct or
  58.         consequential, as a result of the use of the information
  59.         documented herein.
  60.  
  61.  
  62.         RAID, although designed to improve system reliability by adding
  63.         redundancy, can also lead to a false sense of security and
  64.         confidence when used improperly.  This false confidence can lead
  65.         to even greater disasters.  In particular, note that RAID is
  66.         designed to protect against *disk* failures, and not against
  67.         *power* failures or *operator* mistakes.  Power failures, buggy
  68.         development kernels, or operator/admin errors can lead to
  69.         damaged data that it is not recoverable!  RAID is *not* a
  70.         substitute for proper backup of your system.  Know what you are
  71.         doing, test, be knowledgeable and aware!
  72.  
  73.   1.  Introduction
  74.  
  75.  
  76.   1. Q: What is RAID?
  77.  
  78.        A: RAID stands for "Redundant Array of Inexpensive Disks",
  79.        and is meant to be a way of creating a fast and reliable
  80.        disk-drive subsystem out of individual disks.  In the PC
  81.        world, "I" has come to stand for "Independent", where mar¡
  82.        keting forces continue to differentiate IDE and SCSI.  In
  83.        it's original meaning, "I" meant "Inexpensive as compared to
  84.        refrigerator-sized mainframe 3380 DASD", monster drives
  85.        which made nice houses look cheap, and diamond rings look
  86.        like trinkets.
  87.  
  88.  
  89.  
  90.   2. Q: What is this document?
  91.  
  92.        A: This document is a tutorial/HOWTO/FAQ for users of the
  93.        Linux MD kernel extension, the associated tools, and their
  94.        use.  The MD extension implements RAID-0 (striping), RAID-1
  95.        (mirroring), RAID-4 and RAID-5 in software.   That is, with
  96.        MD, no special hardware or disk controllers are required to
  97.        get many of the benefits of RAID.
  98.  
  99.  
  100.        This document is NOT an introduction to RAID; you must find
  101.        this elsewhere.
  102.  
  103.  
  104.  
  105.  
  106.   3. Q: What levels of RAID does the Linux kernel implement?
  107.  
  108.        A: Striping (RAID-0) and linear concatenation are a part of
  109.        the stock 2.x series of kernels.  This code is of production
  110.        quality; it is well understood and well maintained.  It is
  111.        being used in some very large USENET news servers.
  112.  
  113.  
  114.        RAID-1, RAID-4 & RAID-5 are a part of the 2.1.63 and greater
  115.        kernels.  For earlier 2.0.x and 2.1.x kernels, patches exist
  116.        that will provide this function.  Don't feel obligated to
  117.        upgrade to 2.1.63; upgrading the kernel is hard; it is
  118.        *much* easier to patch an earlier kernel.  Most of the RAID
  119.        user community is running 2.0.x kernels, and that's where
  120.        most of the historic RAID development has focused.   The
  121.        current snapshots should be considered near-production
  122.        quality; that is, there are no known bugs but there are some
  123.        rough edges and untested system setups.  There are a large
  124.        number of people using Software RAID in a production
  125.        environment.
  126.  
  127.  
  128.        RAID-1 hot reconstruction has been recently introduced
  129.        (August 1997) and should be considered alpha quality.
  130.        RAID-5 hot reconstruction will be alpha quality any day now.
  131.  
  132.  
  133.   A word of caution about the 2.1.x development kernels: these
  134.   are less than stable in a variety of ways.  Some of the
  135.   newer disk controllers (e.g. the Promise Ultra's) are
  136.   supported only in the 2.1.x kernels.  However, the 2.1.x
  137.   kernels have seen frequent changes in the block device
  138.   driver, in the DMA and interrupt code, in the PCI, IDE and
  139.   SCSI code, and in the disk controller drivers.  The
  140.   combination of these factors, coupled to cheapo hard drives
  141.   and/or low-quality ribbon cables can lead to considerable
  142.   heartbreak.   The ckraid tool, as well as fsck and mount put
  143.   considerable stress on the RAID subsystem.  This can lead to
  144.   hard lockups during boot, where even the magic alt-SysReq
  145.   key sequence won't save the day.  Use caution with the 2.1.x
  146.   kernels, and expect trouble.  Or stick to the 2.0.34 kernel.
  147.  
  148.  
  149.  
  150.  
  151.   4. Q: I'm running an older kernel. Where do I get patches?
  152.  
  153.        A: Software RAID-0 and linear mode are a stock part of all
  154.        current Linux kernels.  Patches for Software RAID-1,4,5 are
  155.        available from
  156.        <http://luthien.nuclecu.unam.mx/~miguel/raid>.  See also the
  157.        quasi-mirror <ftp://linux.kernel.org/pub/linux/dae¡
  158.        mons/raid/> for patches, tools and other goodies.
  159.  
  160.  
  161.  
  162.   5. Q: Are there other Linux RAID references?
  163.  
  164.        A:
  165.  
  166.        ╖  Generic RAID overview:
  167.           <http://www.dpt.com/uraiddoc.html>.
  168.  
  169.        ╖  General Linux RAID options:
  170.           <http://linas.org/linux/raid.html>.
  171.  
  172.        ╖  Latest version of this document:
  173.           <http://linas.org/linux/Software-RAID/Software-
  174.           RAID.html>.
  175.  
  176.        ╖  Linux-RAID mailing list archive:
  177.           <http://www.linuxhq.com/lnxlists/>.
  178.  
  179.        ╖  Linux Software RAID Home Page:
  180.           <http://luthien.nuclecu.unam.mx/~miguel/raid>.
  181.  
  182.        ╖  Linux Software RAID tools:
  183.           <ftp://linux.kernel.org/pub/linux/daemons/raid/>.
  184.  
  185.        ╖  How to setting up linear/stripped Software RAID:
  186.           <http://www.ssc.com/lg/issue17/raid.html>.
  187.  
  188.        ╖  Bootable RAID mini-HOWTO:
  189.           <ftp://ftp.bizsystems.com/pub/raid/bootable-raid>.
  190.  
  191.        ╖  Root RAID HOWTO: <ftp://ftp.bizsystems.com/pub/raid/Root-
  192.           RAID-HOWTO>.
  193.  
  194.        ╖  Linux RAID-Geschichten:
  195.           <http://www.infodrom.north.de/~joey/Linux/raid/>.
  196.  
  197.  
  198.  
  199.   6. Q: Who do I blame for this document?
  200.  
  201.        A: Linas Vepstas slapped this thing together.  However, most
  202.        of the information, and some of the words were supplied by
  203.  
  204.        ╖  Bradley Ward Allen <ulmo@Q.Net>
  205.  
  206.        ╖  Luca Berra <bluca@comedia.it>
  207.  
  208.        ╖  Brian Candler <B.Candler@pobox.com>
  209.  
  210.        ╖  Bohumil Chalupa <bochal@apollo.karlov.mff.cuni.cz>
  211.  
  212.        ╖  Rob Hagopian <hagopiar@vu.union.edu>
  213.  
  214.        ╖  Anton Hristozov <anton@intransco.com>
  215.  
  216.        ╖  Miguel de Icaza <miguel@luthien.nuclecu.unam.mx>
  217.  
  218.        ╖  Marco Meloni <tonno@stud.unipg.it>
  219.  
  220.        ╖  Ingo Molnar <mingo@pc7537.hil.siemens.at>
  221.  
  222.        ╖  Alvin Oga <alvin@planet.fef.com>
  223.  
  224.        ╖  Gadi Oxman <gadio@netvision.net.il>
  225.  
  226.        ╖  Vaughan Pratt <pratt@cs.Stanford.EDU>
  227.  
  228.        ╖  Steven A. Reisman <sar@pressenter.com>
  229.  
  230.        ╖  Michael Robinton <michael@bzs.org>
  231.  
  232.        ╖  Martin Schulze <joey@finlandia.infodrom.north.de>
  233.  
  234.        ╖  Geoff Thompson <geofft@cs.waikato.ac.nz>
  235.  
  236.        ╖  Edward Welbon <welbon@bga.com>
  237.  
  238.        ╖  Rod Wilkens <rwilkens@border.net>
  239.  
  240.        ╖  Johan Wiltink <j.m.wiltink@pi.net>
  241.  
  242.        ╖  Leonard N. Zubkoff <lnz@dandelion.com>
  243.  
  244.        ╖  Marc ZYNGIER <zyngier@ufr-info-p7.ibp.fr>
  245.  
  246.  
  247.           Copyrights
  248.  
  249.        ╖  Copyright (C) 1994-96 Marc ZYNGIER
  250.  
  251.        ╖  Copyright (C) 1997 Gadi Oxman, Ingo Molnar, Miguel de
  252.           Icaza
  253.  
  254.        ╖  Copyright (C) 1997, 1998 Linas Vepstas
  255.  
  256.        ╖  By copyright law, additional copyrights are implicitly
  257.           held by the contributors listed above.
  258.  
  259.           Thanks all for being there!
  260.  
  261.  
  262.  
  263.  
  264.  
  265.   2.  Understanding RAID
  266.  
  267.  
  268.   1. Q: What is RAID?  Why would I ever use it?
  269.  
  270.        A: RAID is a way of combining multiple disk drives into a
  271.        single entity to improve performance and/or reliability.
  272.        There are a variety of different types and implementations
  273.        of RAID, each with its own advantages and disadvantages.
  274.        For example, by putting a copy of the same data on two disks
  275.        (called disk mirroring, or RAID level 1), read performance
  276.        can be improved by reading alternately from each disk in the
  277.        mirror.  On average, each disk is less busy, as it is han¡
  278.        dling only 1/2 the reads (for two disks), or 1/3 (for three
  279.        disks), etc.  In addition, a mirror can improve reliability:
  280.        if one disk fails, the other disk(s) have a copy of the
  281.        data.  Different ways of combining the disks into one,
  282.        referred to as RAID levels,  can provide greater storage
  283.        efficiency than simple mirroring, or can alter latency
  284.        (access-time) performance, or throughput (transfer rate)
  285.        performance, for reading or writing, while still retaining
  286.        redundancy that is useful for guarding against failures.
  287.  
  288.        Although RAID can protect against disk failure, it does not
  289.        protect against operator and administrator (human) error, or
  290.        against loss due to programming bugs (possibly due to bugs
  291.        in the RAID software itself).  The net abounds with tragic
  292.        tales of system administrators who have bungled a RAID
  293.        installation, and have lost all of their data.  RAID is not
  294.        a substitute for frequent, regularly scheduled backup.
  295.  
  296.        RAID can be implemented in hardware, in the form of special
  297.        disk controllers, or in software, as a kernel module that is
  298.        layered in between the low-level disk driver, and the file
  299.        system which sits above it.  RAID hardware is always a "disk
  300.        controller", that is, a device to which one can cable up the
  301.        disk drives. Usually it comes in the form of an adapter card
  302.        that will plug into a ISA/EISA/PCI/S-Bus/MicroChannel slot.
  303.        However, some RAID controllers are in the form of a box that
  304.        connects into the cable in between the usual system disk
  305.        controller, and the disk drives.  Small ones may fit into a
  306.        drive bay; large ones may be built into a storage cabinet
  307.        with its own drive bays and power supply.  The latest RAID
  308.        hardware used with the latest & fastest CPU will usually
  309.        provide the best overall performance, although at a
  310.        significant price.  This is because most RAID controllers
  311.        come with on-board DSP's and memory cache that can off-load
  312.        a considerable amount of processing from the main CPU, as
  313.        well as allow high transfer rates into the large controller
  314.        cache.  Old RAID hardware can act as a "de-accelerator" when
  315.        used with newer CPU's: yesterday's fancy DSP and cache can
  316.        act as a bottleneck, and it's performance is often beaten by
  317.        pure-software RAID and new but otherwise plain, run-of-the-
  318.        mill disk controllers.  RAID hardware can offer an advantage
  319.        over pure-software RAID, if it can makes use of disk-spindle
  320.        synchronization and its knowledge of the disk-platter
  321.        position with regard to the disk head, and the desired disk-
  322.        block.  However, most modern (low-cost) disk drives do not
  323.        offer this information and level of control anyway, and
  324.        thus, most RAID hardware does not take advantage of it.
  325.        RAID hardware is usually not compatible across different
  326.        brands, makes and models: if a RAID controller fails, it
  327.        must be replaced by another controller of the same type.  As
  328.        of this writing (June 1998), a broad variety of hardware
  329.        controllers will operate under Linux; however, none of them
  330.        currently come with configuration and management utilities
  331.   that run under Linux.
  332.  
  333.   Software-RAID is a set of kernel modules, together with
  334.   management utilities that implement RAID purely in software,
  335.   and require no extraordinary hardware.  The Linux RAID
  336.   subsystem is implemented as a layer in the kernel that sits
  337.   above the low-level disk drivers (for IDE, SCSI and Paraport
  338.   drives), and the block-device interface.  The filesystem, be
  339.   it ext2fs, DOS-FAT, or other, sits above the block-device
  340.   interface.  Software-RAID, by its very software nature,
  341.   tends to be more flexible than a hardware solution.  The
  342.   downside is that it of course requires more CPU cycles and
  343.   power to run well than a comparable hardware system.  Of
  344.   course, the cost can't be beat.  Software RAID has one
  345.   further important distinguishing feature: it operates on a
  346.   partition-by-partition basis, where a number of individual
  347.   disk partitions are ganged together to create a RAID
  348.   partition.  This is in contrast to most hardware RAID
  349.   solutions, which gang together entire disk drives into an
  350.   array.  With hardware, the fact that there is a RAID array
  351.   is transparent to the operating system, which tends to
  352.   simplify management.  With software, there are far more
  353.   configuration options and choices, tending to complicate
  354.   matters.
  355.  
  356.   As of this writing (June 1998), the administration of RAID
  357.   under Linux is far from trivial, and is best attempted by
  358.   experienced system administrators.  The theory of operation
  359.   is complex.  The system tools require modification to
  360.   startup scripts.  And recovery from disk failure is non-
  361.   trivial, and prone to human error.   RAID is not for the
  362.   novice, and any benefits it may bring to reliability and
  363.   performance can be easily outweighed by the extra
  364.   complexity.  Indeed, modern disk drives are incredibly
  365.   reliable and modern CPU's and controllers are quite
  366.   powerful.  You might more easily obtain the desired
  367.   reliability and performance levels by purchasing higher-
  368.   quality and/or faster hardware.
  369.  
  370.  
  371.  
  372.   2. Q: What are RAID levels?  Why so many? What distinguishes them?
  373.  
  374.        A: The different RAID levels have different performance,
  375.        redundancy, storage capacity, reliability and cost charac¡
  376.        teristics.   Most, but not all levels of RAID offer redun¡
  377.        dancy against disk failure.  Of those that offer redundancy,
  378.        RAID-1 and RAID-5 are the most popular.  RAID-1 offers bet¡
  379.        ter performance, while RAID-5 provides for more efficient
  380.        use of the available storage space.  However, tuning for
  381.        performance is an entirely different matter, as performance
  382.        depends strongly on a large variety of factors, from the
  383.        type of application, to the sizes of stripes, blocks, and
  384.        files.  The more difficult aspects of performance tuning are
  385.        deferred to a later section of this HOWTO.
  386.  
  387.        The following describes the different RAID levels in the
  388.        context of the Linux software RAID implementation.
  389.  
  390.  
  391.        ╖  RAID-linear is a simple concatenation of partitions to
  392.           create a larger virtual partition.  It is handy if you
  393.           have a number small drives, and wish to create a single,
  394.           large partition.  This concatenation offers no
  395.           redundancy, and in fact decreases the overall
  396.           reliability: if any one disk fails, the combined
  397.      partition will fail.
  398.  
  399.  
  400.  
  401.   ╖  RAID-1 is also referred to as "mirroring".  Two (or more)
  402.      partitions, all of the same size, each store an exact
  403.      copy of all data, disk-block by disk-block.  Mirroring
  404.      gives strong protection against disk failure: if one disk
  405.      fails, there is another with the an exact copy of the
  406.      same data. Mirroring can also help improve performance in
  407.      I/O-laden systems, as read requests can be divided up
  408.      between several disks.   Unfortunately, mirroring is also
  409.      the least efficient in terms of storage: two mirrored
  410.      partitions can store no more data than a single
  411.      partition.
  412.  
  413.  
  414.  
  415.   ╖  Striping is the underlying concept behind all of the
  416.      other RAID levels.  A stripe is a contiguous sequence of
  417.      disk blocks.  A stripe may be as short as a single disk
  418.      block, or may consist of thousands.  The RAID drivers
  419.      split up their component disk partitions into stripes;
  420.      the different RAID levels differ in how they organize the
  421.      stripes, and what data they put in them. The interplay
  422.      between the size of the stripes, the typical size of
  423.      files in the file system, and their location on the disk
  424.      is what determines the overall performance of the RAID
  425.      subsystem.
  426.  
  427.  
  428.  
  429.   ╖  RAID-0 is much like RAID-linear, except that the
  430.      component partitions are divided into stripes and then
  431.      interleaved.  Like RAID-linear, the result is a single
  432.      larger virtual partition.  Also like RAID-linear, it
  433.      offers no redundancy, and therefore decreases overall
  434.      reliability: a single disk failure will knock out the
  435.      whole thing.  RAID-0 is often claimed to improve
  436.      performance over the simpler RAID-linear.  However, this
  437.      may or may not be true, depending on the characteristics
  438.      to the file system, the typical size of the file as
  439.      compared to the size of the stripe, and the type of
  440.      workload.  The ext2fs file system already scatters files
  441.      throughout a partition, in an effort to minimize
  442.      fragmentation. Thus, at the simplest level, any given
  443.      access may go to one of several disks, and thus, the
  444.      interleaving of stripes across multiple disks offers no
  445.      apparent additional advantage. However, there are
  446.      performance differences, and they are data, workload, and
  447.      stripe-size dependent.
  448.  
  449.  
  450.  
  451.   ╖  RAID-4 interleaves stripes like RAID-0, but it requires
  452.      an additional partition to store parity information.  The
  453.      parity is used to offer redundancy: if any one of the
  454.      disks fail, the data on the remaining disks can be used
  455.      to reconstruct the data that was on the failed disk.
  456.      Given N data disks, and one parity disk, the parity
  457.      stripe is computed by taking one stripe from each of the
  458.      data disks, and XOR'ing them together.  Thus, the storage
  459.      capacity of a an (N+1)-disk RAID-4 array is N, which is a
  460.      lot better than mirroring (N+1) drives, and is almost as
  461.      good as a RAID-0 setup for large N.  Note that for N=1,
  462.      where there is one data drive, and one parity drive,
  463.      RAID-4 is a lot like mirroring, in that each of the two
  464.      disks is a copy of each other.  However, RAID-4 does NOT
  465.      offer the read-performance of mirroring, and offers
  466.      considerably degraded write performance. In brief, this
  467.      is because updating the parity requires a read of the old
  468.      parity, before the new parity can be calculated and
  469.      written out.  In an environment with lots of writes, the
  470.      parity disk can become a bottleneck, as each write must
  471.      access the parity disk.
  472.  
  473.  
  474.  
  475.   ╖  RAID-5 avoids the write-bottleneck of RAID-4 by
  476.      alternately storing the parity stripe on each of the
  477.      drives.  However, write performance is still not as good
  478.      as for mirroring, as the parity stripe must still be read
  479.      and XOR'ed before it is written.  Read performance is
  480.      also not as good as it is for mirroring, as, after all,
  481.      there is only one copy of the data, not two or more.
  482.      RAID-5's principle advantage over mirroring is that it
  483.      offers redundancy and protection against single-drive
  484.      failure, while offering far more storage capacity  when
  485.      used with three or more drives.
  486.  
  487.  
  488.  
  489.   ╖  RAID-2 and RAID-3 are seldom used anymore, and to some
  490.      degree are have been made obsolete by modern disk
  491.      technology.  RAID-2 is similar to RAID-4, but stores ECC
  492.      information instead of parity.  Since all modern disk
  493.      drives incorporate ECC under the covers, this offers
  494.      little additional protection.  RAID-2 can offer greater
  495.      data consistency if power is lost during a write;
  496.      however, battery backup and a clean shutdown can offer
  497.      the same benefits.  RAID-3 is similar to RAID-4, except
  498.      that it uses the smallest possible stripe size. As a
  499.      result, any given read will involve all disks, making
  500.      overlapping I/O requests difficult/impossible. In order
  501.      to avoid delay due to rotational latency, RAID-3 requires
  502.      that all disk drive spindles be synchronized. Most modern
  503.      disk drives lack spindle-synchronization ability, or, if
  504.      capable of it, lack the needed connectors, cables, and
  505.      manufacturer documentation.  Neither RAID-2 nor RAID-3
  506.      are supported by the Linux Software-RAID drivers.
  507.  
  508.  
  509.  
  510.   ╖  Other RAID levels have been defined by various
  511.      researchers and vendors.  Many of these represent the
  512.      layering of one type of raid on top of another.  Some
  513.      require special hardware, and others are protected by
  514.      patent. There is no commonly accepted naming scheme for
  515.      these other levels. Sometime the advantages of these
  516.      other systems are minor, or at least not apparent until
  517.      the system is highly stressed.  Except for the layering
  518.      of RAID-1 over RAID-0/linear, Linux Software RAID does
  519.      not support any of the other variations.
  520.  
  521.  
  522.  
  523.   3.  Setup & Installation Considerations
  524.  
  525.  
  526.   1. Q: What is the best way to configure Software RAID?
  527.  
  528.  
  529.   A: I keep rediscovering that file-system planning is one of
  530.   the more difficult Unix configuration tasks.  To answer your
  531.   question, I can describe what we did.
  532.  
  533.   We planned the following setup:
  534.  
  535.   ╖  two EIDE disks, 2.1.gig each.
  536.  
  537.  
  538.        disk partition mount pt.  size    device
  539.          1      1       /        300M   /dev/hda1
  540.          1      2       swap      64M   /dev/hda2
  541.          1      3       /home    800M   /dev/hda3
  542.          1      4       /var     900M   /dev/hda4
  543.  
  544.          2      1       /root    300M   /dev/hdc1
  545.          2      2       swap      64M   /dev/hdc2
  546.          2      3       /home    800M   /dev/hdc3
  547.          2      4       /var     900M   /dev/hdc4
  548.  
  549.  
  550.  
  551.  
  552.  
  553.   ╖  Each disk is on a separate controller (& ribbon cable).
  554.      The theory is that a controller failure and/or ribbon
  555.      failure won't disable both disks.  Also, we might
  556.      possibly get a performance boost from parallel operations
  557.      over two controllers/cables.
  558.  
  559.   ╖  Install the Linux kernel on the root (/) partition
  560.      /dev/hda1.  Mark this partition as bootable.
  561.  
  562.   ╖  /dev/hdc1 will contain a ``cold'' copy of /dev/hda1. This
  563.      is NOT a raid copy, just a plain old copy-copy. It's
  564.      there just in case the first disk fails; we can use a
  565.      rescue disk, mark /dev/hdc1 as bootable, and use that to
  566.      keep going without having to reinstall the system.  You
  567.      may even want to put /dev/hdc1's copy of the kernel into
  568.      LILO to simplify booting in case of failure.
  569.  
  570.      The theory here is that in case of severe failure, I can
  571.      still boot the system without worrying about raid
  572.      superblock-corruption or other raid failure modes &
  573.      gotchas that I don't understand.
  574.  
  575.   ╖  /dev/hda3 and /dev/hdc3 will be mirrors /dev/md0.
  576.  
  577.   ╖  /dev/hda4 and /dev/hdc4 will be mirrors /dev/md1.
  578.  
  579.   ╖  we picked /var and /home to be mirrored, and in separate
  580.      partitions, using the following logic:
  581.  
  582.   ╖  / (the root partition) will contain relatively static,
  583.      non-changing data: for all practical purposes, it will be
  584.      read-only without actually being marked & mounted read-
  585.      only.
  586.  
  587.   ╖  /home will contain ''slowly'' changing data.
  588.  
  589.   ╖  /var will contain rapidly changing data, including mail
  590.      spools, database contents and web server logs.
  591.  
  592.      The idea behind using multiple, distinct partitions is
  593.      that if, for some bizarre reason, whether it is human
  594.      error, power loss, or an operating system gone wild,
  595.      corruption is limited to one partition.  In one typical
  596.      case, power is lost while the system is writing to disk.
  597.      This will almost certainly lead to a corrupted
  598.      filesystem, which will be repaired by fsck during the
  599.      next boot.  Although fsck does it's best to make the
  600.      repairs without creating additional damage during those
  601.      repairs, it can be comforting to know that any such
  602.      damage has been limited to one partition.  In another
  603.      typical case, the sysadmin makes a mistake during rescue
  604.      operations, leading to erased or destroyed data.
  605.      Partitions can help limit the repercussions of the
  606.      operator's errors.
  607.  
  608.   ╖  Other reasonable choices for partitions might be /usr or
  609.      /opt.  In fact, /opt and /home make great choices for
  610.      RAID-5 partitions, if we had more disks.  A word of
  611.      caution: DO NOT put /usr in a RAID-5 partition.  If a
  612.      serious fault occurs, you may find that you cannot mount
  613.      /usr, and that you want some of the tools on it (e.g. the
  614.      networking tools, or the compiler.)  With RAID-1, if a
  615.      fault has occurred, and you can't get RAID to work, you
  616.      can at least mount one of the two mirrors.  You can't do
  617.      this with any of the other RAID levels (RAID-5, striping,
  618.      or linear append).
  619.  
  620.  
  621.  
  622.      So, to complete the answer to the question:
  623.  
  624.   ╖  install the OS on disk 1, partition 1.  do NOT mount any
  625.      of the other partitions.
  626.  
  627.   ╖  install RAID per instructions.
  628.  
  629.   ╖  configure md0 and md1.
  630.  
  631.   ╖  convince yourself that you know what to do in case of a
  632.      disk failure!  Discover sysadmin mistakes now, and not
  633.      during an actual crisis.  Experiment!  (we turned off
  634.      power during disk activity -- this proved to be ugly but
  635.      informative).
  636.  
  637.   ╖  do some ugly mount/copy/unmount/rename/reboot scheme to
  638.      move /var over to the /dev/md1.  Done carefully, this is
  639.      not dangerous.
  640.  
  641.   ╖  enjoy!
  642.  
  643.  
  644.  
  645.  
  646.   2. Q: What is the difference between the mdadd, mdrun, etc. commands,
  647.      and the raidadd, raidrun commands?
  648.  
  649.        A: The names of the tools have changed as of the 0.5 release
  650.        of the raidtools package.  The md naming convention was used
  651.        in the 0.43 and older versions, while raid is used in 0.5
  652.        and newer versions.
  653.  
  654.  
  655.  
  656.   3. Q: I want to run RAID-linear/RAID-0 in the stock 2.0.34 kernel.  I
  657.      don't want to apply the raid patches, since these are not needed
  658.      for RAID-0/linear.  Where can I get the raid-tools to manage this?
  659.  
  660.  
  661.   A: This is a tough question, indeed, as the newest raid
  662.   tools package needs to have the RAID-1,4,5 kernel patches
  663.   installed in order to compile.  I am not aware of any pre-
  664.   compiled, binary version of the raid tools that is available
  665.   at this time.  However, experiments show that the raid-tools
  666.   binaries, when compiled against kernel 2.1.100, seem to work
  667.   just fine in creating a RAID-0/linear partition under
  668.   2.0.34.  A brave soul has asked for these, and I've tem¡
  669.   porarily placed the binaries mdadd, mdcreate, etc.  at
  670.   http://linas.org/linux/Software-RAID/ You must get the man
  671.   pages, etc. from the usual raid-tools package.
  672.  
  673.  
  674.  
  675.  
  676.   4. Q: Can I strip/mirror the root partition (/)?  Why can't I boot
  677.      Linux directly from the md disks?
  678.  
  679.  
  680.        A: Both LILO and Loadlin need an non-stripped/mirrored par¡
  681.        tition to read the kernel image from. If you want to
  682.        strip/mirror the root partition (/), then you'll want to
  683.        create an unstriped/mirrored partition to hold the ker¡
  684.        nel(s).  Typically, this partition is named /boot.  Then you
  685.        either use the initial ramdisk support (initrd), or patches
  686.        from Harald Hoyer <HarryH@Royal.Net> that allow a stripped
  687.        partition to be used as the root device.  (These patches are
  688.        now a standard part of recent 2.1.x kernels)
  689.  
  690.  
  691.        There are several approaches that can be used.  One approach
  692.        is documented in detail in the Bootable RAID mini-HOWTO:
  693.        <ftp://ftp.bizsystems.com/pub/raid/bootable-raid>.
  694.  
  695.  
  696.        Alternately, use mkinitrd to build the ramdisk image, see
  697.        below.
  698.  
  699.  
  700.        Edward Welbon <welbon@bga.com> writes:
  701.  
  702.        ╖  ... all that is needed is a script to manage the boot
  703.           setup.  To mount an md filesystem as root, the main thing
  704.           is to build an initial file system image that has the
  705.           needed modules and md tools to start md.  I have a simple
  706.           script that does this.
  707.  
  708.  
  709.        ╖  For boot media, I have a small cheap SCSI disk (170MB I
  710.           got it used for $20).  This disk runs on a AHA1452, but
  711.           it could just as well be an inexpensive IDE disk on the
  712.           native IDE.  The disk need not be very fast since it is
  713.           mainly for boot.
  714.  
  715.  
  716.        ╖  This disk has a small file system which contains the
  717.           kernel and the file system image for initrd.  The initial
  718.           file system image has just enough stuff to allow me to
  719.           load the raid SCSI device driver module and start the
  720.           raid partition that will become root.  I then do an
  721.  
  722.  
  723.        echo 0x900 > /proc/sys/kernel/real-root-dev
  724.  
  725.  
  726.  
  727.   (0x900 is for /dev/md0) and exit linuxrc.  The boot proceeds
  728.   normally from there.
  729.  
  730.  
  731.   ╖  I have built most support as a module except for the
  732.      AHA1452 driver that brings in the initrd filesystem.  So
  733.      I have a fairly small kernel. The method is perfectly
  734.      reliable, I have been doing this since before 2.1.26 and
  735.      have never had a problem that I could not easily recover
  736.      from.  The file systems even survived several 2.1.4[45]
  737.      hard crashes with no real problems.
  738.  
  739.  
  740.   ╖  At one time I had partitioned the raid disks so that the
  741.      initial cylinders of the first raid disk held the kernel
  742.      and the initial cylinders of the second raid disk hold
  743.      the initial file system image, instead I made the initial
  744.      cylinders of the raid disks swap since they are the
  745.      fastest cylinders (why waste them on boot?).
  746.  
  747.  
  748.   ╖  The nice thing about having an inexpensive device
  749.      dedicated to boot is that it is easy to boot from and can
  750.      also serve as a rescue disk if necessary. If you are
  751.      interested, you can take a look at the script that builds
  752.      my initial ram disk image and then runs LILO.
  753.  
  754.        <http://www.realtime.net/~welbon/initrd.md.tar.gz>
  755.  
  756.  
  757.   It is current enough to show the picture.  It isn't espe¡
  758.   cially pretty and it could certainly build a much smaller
  759.   filesystem image for the initial ram disk.  It would be easy
  760.   to a make it more efficient.  But it uses LILO as is.  If
  761.   you make any improvements, please forward a copy to me. 8-)
  762.  
  763.  
  764.  
  765.   5. Q: I have heard that I can run mirroring over striping. Is this
  766.      true?  Can I run mirroring over the loopback device?
  767.  
  768.        A: Yes, but not the reverse.  That is, you can put a stripe
  769.        over several disks, and then build a mirror on top of this.
  770.        However, striping cannot be put on top of mirroring.
  771.  
  772.  
  773.        A brief technical explanation is that the linear and stripe
  774.        personalities use the ll_rw_blk routine for access.  The
  775.        ll_rw_blk routine maps disk devices and  sectors, not
  776.        blocks.  Block devices can be layered one on top of the
  777.        other; but devices that do raw, low-level disk accesses,
  778.        such as ll_rw_blk, cannot.
  779.  
  780.  
  781.        Currently (November 1997) RAID cannot be run over the
  782.        loopback devices, although this should be fixed shortly.
  783.  
  784.  
  785.  
  786.   6. Q: I have two small disks and three larger disks.  Can I
  787.      concatenate the two smaller disks with RAID-0, and then create a
  788.      RAID-5 out of that and the larger disks?
  789.  
  790.        A: Currently (November 1997), for a RAID-5 array, no.  Cur¡
  791.        rently, one can do this only for a RAID-1 on top of the con¡
  792.        catenated drives.
  793.   7. Q: What is the difference between RAID-1 and RAID-5 for a two-disk
  794.      configuration (i.e. the difference between a RAID-1 array  built
  795.      out of two disks, and a RAID-5 array built out of two disks)?
  796.  
  797.  
  798.        A: There is no difference in storage capacity.  Nor can
  799.        disks be added to either array to increase capacity (see the
  800.        question below for details).
  801.  
  802.  
  803.        RAID-1 offers a performance advantage for reads: the RAID-1
  804.        driver uses distributed-read technology to simultaneously
  805.        read two sectors, one from each drive, thus doubling read
  806.        performance.
  807.  
  808.  
  809.        The RAID-5 driver, although it contains many optimizations,
  810.        does not currently (September 1997) realize that the parity
  811.        disk is actually a mirrored copy of the data disk.  Thus, it
  812.        serializes data reads.
  813.  
  814.  
  815.  
  816.  
  817.   8. Q: How can I guard against a two-disk failure?
  818.  
  819.  
  820.        A: Some of the RAID algorithms do guard against multiple
  821.        disk failures, but these are not currently implemented for
  822.        Linux.  However, the Linux Software RAID can guard against
  823.        multiple disk failures by layering an array on top of an
  824.        array.  For example, nine disks can be used to create three
  825.        raid-5 arrays.  Then these three arrays can in turn be
  826.        hooked together into a single RAID-5 array on top.  In fact,
  827.        this kind of a configuration will guard against a three-disk
  828.        failure.  Note that a large amount of disk space is
  829.        ''wasted'' on the redundancy information.
  830.  
  831.  
  832.  
  833.            For an NxN raid-5 array,
  834.            N=3, 5 out of 9 disks are used for parity (=55%)
  835.            N=4, 7 out of 16 disks
  836.            N=5, 9 out of 25 disks
  837.            ...
  838.            N=9, 17 out of 81 disks (=~20%)
  839.  
  840.  
  841.  
  842.  
  843.  
  844.   In general, an MxN array will use M+N-1 disks for parity.
  845.   The least amount of space is "wasted" when M=N.
  846.  
  847.  
  848.   Another alternative is to create a RAID-1 array with three
  849.   disks.  Note that since all three disks contain identical
  850.   data, that 2/3's of the space is ''wasted''.
  851.  
  852.  
  853.  
  854.  
  855.   9. Q: I'd like to understand  how it'd be possible to have something
  856.      like fsck: if the partition hasn't been cleanly unmounted, fsck
  857.      runs and fixes the filesystem by itself more than 90% of the time.
  858.      Since the machine is capable of fixing it by itself with ckraid
  859.      --fix, why not make it automatic?
  860.  
  861.  
  862.  
  863.        A: This can be done by adding lines like the following to
  864.        /etc/rc.d/rc.sysinit:
  865.  
  866.            mdadd /dev/md0 /dev/hda1 /dev/hdc1 || {
  867.                ckraid --fix /etc/raid.usr.conf
  868.                mdadd /dev/md0 /dev/hda1 /dev/hdc1
  869.            }
  870.  
  871.  
  872.  
  873.        or
  874.  
  875.            mdrun -p1 /dev/md0
  876.            if [ $? -gt 0 ] ; then
  877.                    ckraid --fix /etc/raid1.conf
  878.                    mdrun -p1 /dev/md0
  879.            fi
  880.  
  881.  
  882.  
  883.        Before presenting a more complete and reliable script, lets
  884.        review the theory of operation.
  885.  
  886.        Gadi Oxman writes: In an unclean shutdown, Linux might be in
  887.        one of the following states:
  888.  
  889.        ╖  The in-memory disk cache was in sync with the RAID set
  890.           when the unclean shutdown occurred; no data was lost.
  891.  
  892.        ╖  The in-memory disk cache was newer than the RAID set
  893.           contents when the crash occurred; this results in a
  894.           corrupted filesystem and potentially in data loss.
  895.  
  896.           This state can be further divided to the following two
  897.           states:
  898.  
  899.  
  900.        ╖  Linux was writing data when the unclean shutdown
  901.           occurred.
  902.  
  903.        ╖  Linux was not writing data when the crash occurred.
  904.  
  905.  
  906.           Suppose we were using a RAID-1 array. In (2a), it might
  907.           happen that before the crash, a small number of data
  908.           blocks were successfully written only to some of the
  909.           mirrors, so that on the next reboot, the mirrors will no
  910.           longer contain the same data.
  911.  
  912.           If we were to ignore the mirror differences, the
  913.           raidtools-0.36.3 read-balancing code might choose to read
  914.           the above data blocks from any of the mirrors, which will
  915.           result in inconsistent behavior (for example, the output
  916.           of e2fsck -n /dev/md0 can differ from run to run).
  917.  
  918.  
  919.           Since RAID doesn't protect against unclean shutdowns,
  920.           usually there isn't any ''obviously correct'' way to fix
  921.           the mirror differences and the filesystem corruption.
  922.  
  923.           For example, by default ckraid --fix will choose the
  924.           first operational mirror and update the other mirrors
  925.      with its contents.  However, depending on the exact
  926.      timing at the crash, the data on another mirror might be
  927.      more recent, and we might want to use it as the source
  928.      mirror instead, or perhaps use another method for
  929.      recovery.
  930.  
  931.      The following script provides one of the more robust
  932.      boot-up sequences.  In particular, it guards against
  933.      long, repeated ckraid's in the presence of uncooperative
  934.      disks, controllers, or controller device drivers.  Modify
  935.      it to reflect your config, and copy it to rc.raid.init.
  936.      Then invoke rc.raid.init after the root partition has
  937.      been fsck'ed and mounted rw, but before the remaining
  938.      partitions are fsck'ed.  Make sure the current directory
  939.      is in the search path.
  940.  
  941.          mdadd /dev/md0 /dev/hda1 /dev/hdc1 || {
  942.              rm -f /fastboot             # force an fsck to occur
  943.              ckraid --fix /etc/raid.usr.conf
  944.              mdadd /dev/md0 /dev/hda1 /dev/hdc1
  945.          }
  946.          # if a crash occurs later in the boot process,
  947.          # we at least want to leave this md in a clean state.
  948.          /sbin/mdstop /dev/md0
  949.  
  950.          mdadd /dev/md1 /dev/hda2 /dev/hdc2 || {
  951.              rm -f /fastboot             # force an fsck to occur
  952.              ckraid --fix /etc/raid.home.conf
  953.              mdadd /dev/md1 /dev/hda2 /dev/hdc2
  954.          }
  955.          # if a crash occurs later in the boot process,
  956.          # we at least want to leave this md in a clean state.
  957.          /sbin/mdstop /dev/md1
  958.  
  959.          mdadd /dev/md0 /dev/hda1 /dev/hdc1
  960.          mdrun -p1 /dev/md0
  961.          if [ $? -gt 0 ] ; then
  962.              rm -f /fastboot             # force an fsck to occur
  963.              ckraid --fix /etc/raid.usr.conf
  964.              mdrun -p1 /dev/md0
  965.          fi
  966.          # if a crash occurs later in the boot process,
  967.          # we at least want to leave this md in a clean state.
  968.          /sbin/mdstop /dev/md0
  969.  
  970.          mdadd /dev/md1 /dev/hda2 /dev/hdc2
  971.          mdrun -p1 /dev/md1
  972.          if [ $? -gt 0 ] ; then
  973.              rm -f /fastboot             # force an fsck to occur
  974.              ckraid --fix /etc/raid.home.conf
  975.              mdrun -p1 /dev/md1
  976.          fi
  977.          # if a crash occurs later in the boot process,
  978.          # we at least want to leave this md in a clean state.
  979.          /sbin/mdstop /dev/md1
  980.  
  981.          # OK, just blast through the md commands now.  If there were
  982.          # errors, the above checks should have fixed things up.
  983.          /sbin/mdadd /dev/md0 /dev/hda1 /dev/hdc1
  984.          /sbin/mdrun -p1 /dev/md0
  985.  
  986.          /sbin/mdadd /dev/md12 /dev/hda2 /dev/hdc2
  987.          /sbin/mdrun -p1 /dev/md1
  988.  
  989.  
  990.  
  991.   In addition to the above, you'll want to create a
  992.   rc.raid.halt which should look like the following:
  993.  
  994.       /sbin/mdstop /dev/md0
  995.       /sbin/mdstop /dev/md1
  996.  
  997.  
  998.  
  999.   Be sure to modify both rc.sysinit and init.d/halt to include
  1000.   this everywhere that filesystems get unmounted before a
  1001.   halt/reboot.  (Note that rc.sysinit unmounts and reboots if
  1002.   fsck returned with an error.)
  1003.  
  1004.  
  1005.  
  1006.  
  1007.   10.
  1008.      Q: Can I set up one-half of a RAID-1 mirror with the one disk I
  1009.      have now, and then later get the other disk and just drop it in?
  1010.  
  1011.  
  1012.        A: With the current tools, no, not in any easy way.  In par¡
  1013.        ticular, you cannot just copy the contents of one disk onto
  1014.        another, and then pair them up.  This is because the RAID
  1015.        drivers use glob of space at the end of the partition to
  1016.        store the superblock.  This decreases the amount of space
  1017.        available to the file system slightly; if you just naively
  1018.        try to force a RAID-1 arrangement onto a partition with an
  1019.        existing filesystem, the raid superblock will overwrite a
  1020.        portion of the file system and mangle data.  Since the
  1021.        ext2fs filesystem scatters files randomly throughput the
  1022.        partition (in order to avoid fragmentation), there is a very
  1023.        good chance that some file will land at the very end of a
  1024.        partition long before the disk is full.
  1025.  
  1026.  
  1027.        If you are clever, I suppose you can calculate how much room
  1028.        the RAID superblock will need, and make your filesystem
  1029.        slightly smaller, leaving room for it when you add it later.
  1030.        But then, if you are this clever, you should also be able to
  1031.        modify the tools to do this automatically for you.  (The
  1032.        tools are not terribly complex).
  1033.  
  1034.  
  1035.        Note:A careful reader has pointed out that the following
  1036.        trick may work; I have not tried or verified this: Do the
  1037.        mkraid with /dev/null as one of the devices.  Then mdadd -r
  1038.        with only the single, true disk (do not mdadd /dev/null).
  1039.        The mkraid should have successfully built the raid array,
  1040.        while the mdadd step just forces the system to run in
  1041.        "degraded" mode, as if one of the disks had failed.
  1042.  
  1043.  
  1044.  
  1045.   4.  Error Recovery
  1046.  
  1047.  
  1048.   1. Q: I have a RAID-1 (mirroring) setup, and lost power while there
  1049.      was disk activity.  Now what do I do?
  1050.  
  1051.  
  1052.        A: The redundancy of RAID levels is designed to protect
  1053.        against a disk failure, not against a power failure.
  1054.  
  1055.        There are several ways to recover from this situation.
  1056.  
  1057.   ╖  Method (1): Use the raid tools.  These can be used to
  1058.      sync the raid arrays.  They do not fix file-system
  1059.      damage; after the raid arrays are sync'ed, then the file-
  1060.      system still has to be fixed with fsck.  Raid arrays can
  1061.      be checked with ckraid /etc/raid1.conf (for RAID-1, else,
  1062.      /etc/raid5.conf, etc.)
  1063.  
  1064.      Calling ckraid /etc/raid1.conf --fix will pick one of the
  1065.      disks in the array (usually the first), and use that as
  1066.      the master copy, and copy its blocks to the others in the
  1067.      mirror.
  1068.  
  1069.      To designate which of the disks should be used as the
  1070.      master, you can use the --force-source flag: for example,
  1071.      ckraid /etc/raid1.conf --fix --force-source /dev/hdc3
  1072.  
  1073.      The ckraid command can be safely run without the --fix
  1074.      option to verify the inactive RAID array without making
  1075.      any changes.  When you are comfortable with the proposed
  1076.      changes, supply the --fix  option.
  1077.  
  1078.  
  1079.   ╖  Method (2): Paranoid, time-consuming, not much better
  1080.      than the first way.  Lets assume a two-disk RAID-1 array,
  1081.      consisting of partitions /dev/hda3 and /dev/hdc3.  You
  1082.      can try the following:
  1083.  
  1084.      a. fsck /dev/hda3
  1085.  
  1086.      b. fsck /dev/hdc3
  1087.  
  1088.      c. decide which of the two partitions had fewer errors,
  1089.         or were more easily recovered, or recovered the data
  1090.         that you wanted.  Pick one, either one, to be your new
  1091.         ``master'' copy.  Say you picked /dev/hdc3.
  1092.  
  1093.      d. dd if=/dev/hdc3 of=/dev/hda3
  1094.  
  1095.      e. mkraid raid1.conf -f --only-superblock
  1096.  
  1097.  
  1098.      Instead of the last two steps, you can instead run ckraid
  1099.      /etc/raid1.conf --fix --force-source /dev/hdc3 which
  1100.      should be a bit faster.
  1101.  
  1102.   ╖  Method (3): Lazy man's version of above.  If you don't
  1103.      want to wait for long fsck's to complete, it is perfectly
  1104.      fine to skip the first three steps above, and move
  1105.      directly to the last two steps.  Just be sure to run fsck
  1106.      /dev/md0 after you are done.  Method (3) is actually just
  1107.      method (1) in disguise.
  1108.  
  1109.  
  1110.      In any case, the above steps will only sync up the raid
  1111.      arrays.  The file system probably needs fixing as well:
  1112.      for this, fsck needs to be run on the active, unmounted
  1113.      md device.
  1114.  
  1115.  
  1116.      With a three-disk RAID-1 array, there are more
  1117.      possibilities, such as using two disks to ''vote'' a
  1118.      majority answer.  Tools to automate this do not currently
  1119.      (September 97) exist.
  1120.  
  1121.  
  1122.  
  1123.   2. Q: I have a RAID-4 or a RAID-5 (parity) setup, and lost power while
  1124.      there was disk activity.  Now what do I do?
  1125.  
  1126.  
  1127.        A: The redundancy of RAID levels is designed to protect
  1128.        against a disk failure, not against a power failure.
  1129.  
  1130.        Since the disks in a RAID-4 or RAID-5 array do not contain a
  1131.        file system that fsck can read, there are fewer repair
  1132.        options.  You cannot use fsck to do preliminary checking
  1133.        and/or repair; you must use ckraid first.
  1134.  
  1135.  
  1136.        The ckraid command can be safely run without the --fix
  1137.        option to verify the inactive RAID array without making any
  1138.        changes.  When you are comfortable with the proposed
  1139.        changes, supply the --fix option.
  1140.  
  1141.  
  1142.        If you wish, you can try designating one of the disks as a
  1143.        ''failed disk''.  Do this with the --suggest-failed-disk-
  1144.        mask flag.
  1145.  
  1146.        Only one bit should be set in the flag: RAID-5 cannot
  1147.        recover two failed disks.  The mask is a binary bit mask:
  1148.        thus:
  1149.  
  1150.            0x1 == first disk
  1151.            0x2 == second disk
  1152.            0x4 == third disk
  1153.            0x8 == fourth disk, etc.
  1154.  
  1155.  
  1156.  
  1157.  
  1158.        Alternately, you can choose to modify the parity sectors, by
  1159.        using the --suggest-fix-parity flag.  This will recompute
  1160.        the parity from the other sectors.
  1161.  
  1162.  
  1163.        The flags --suggest-failed-dsk-mask and --suggest-fix-parity
  1164.        can be safely used for verification. No changes are made if
  1165.        the --fix flag is not specified.  Thus, you can experiment
  1166.        with different possible repair schemes.
  1167.  
  1168.  
  1169.  
  1170.  
  1171.   3. Q: My RAID-1 device, /dev/md0 consists of two hard drive
  1172.      partitions: /dev/hda3 and /dev/hdc3.  Recently, the disk with
  1173.      /dev/hdc3 failed, and was replaced with a new disk.  My best
  1174.      friend, who doesn't understand RAID, said that the correct thing to
  1175.      do now is to ''dd if=/dev/hda3 of=/dev/hdc3''.  I tried this, but
  1176.      things still don't work.
  1177.  
  1178.  
  1179.        A: You should keep your best friend away from you computer.
  1180.        Fortunately, no serious damage has been done.  You can
  1181.        recover from this by running:
  1182.  
  1183.  
  1184.        mkraid raid1.conf -f --only-superblock
  1185.  
  1186.  
  1187.  
  1188.  
  1189.   By using dd, two identical copies of the partition were cre¡
  1190.   ated. This is almost correct, except that the RAID-1 kernel
  1191.   extension expects the RAID superblocks to be different.
  1192.   Thus, when you try to reactivate RAID, the software will
  1193.   notice the problem, and deactivate one of the two parti¡
  1194.   tions.  By re-creating the superblock, you should have a
  1195.   fully usable system.
  1196.  
  1197.  
  1198.  
  1199.   4. Q: My version of mkraid doesn't have a --only-superblock flag.
  1200.      What do I do?
  1201.  
  1202.        A: The newer tools drop support for this flag, replacing it
  1203.        with the --force-resync flag.  It has been reported that the
  1204.        following sequence appears to work with the latest tools and
  1205.        software:
  1206.  
  1207.  
  1208.          umount /web (where /dev/md0 was mounted on)
  1209.          raidstop /dev/md0
  1210.          mkraid /dev/md0 --force-resync --really-force
  1211.          raidstart /dev/md0
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.   After doing this, a cat /proc/mdstat should report resync in
  1218.   progress, and one should be able to mount /dev/md0 at this
  1219.   point.
  1220.  
  1221.  
  1222.  
  1223.   5. Q: My RAID-1 device, /dev/md0 consists of two hard drive
  1224.      partitions: /dev/hda3 and /dev/hdc3.  My best (girl?)friend, who
  1225.      doesn't understand RAID, ran fsck on /dev/hda3 while I wasn't
  1226.      looking, and now the RAID won't work. What should I do?
  1227.  
  1228.  
  1229.        A: You should re-examine your concept of ``best friend''.
  1230.        In general, fsck should never be run on the individual par¡
  1231.        titions that compose a RAID array.  Assuming that neither of
  1232.        the partitions are/were heavily damaged, no data loss has
  1233.        occurred, and the RAID-1 device can be recovered as follows:
  1234.  
  1235.           a. make a backup of the file system on /dev/hda3
  1236.  
  1237.           b. dd if=/dev/hda3 of=/dev/hdc3
  1238.  
  1239.           c. mkraid raid1.conf -f --only-superblock
  1240.  
  1241.        This should leave you with a working disk mirror.
  1242.  
  1243.  
  1244.  
  1245.   6. Q: Why does the above work as a recovery procedure?
  1246.  
  1247.        A: Because each of the component partitions in a RAID-1 mir¡
  1248.        ror is a perfectly valid copy of the file system.  In a
  1249.        pinch, mirroring can be disabled, and one of the partitions
  1250.        can be mounted and safely run as an ordinary, non-RAID file
  1251.        system.  When you are ready to restart using RAID-1, then
  1252.        unmount the partition, and follow the above instructions to
  1253.        restore the mirror.   Note that the above works ONLY for
  1254.        RAID-1, and not for any of the other levels.
  1255.   It may make you feel more comfortable to reverse the
  1256.   direction of the copy above: copy from the disk that was
  1257.   untouched to the one that was.  Just be sure to fsck the
  1258.   final md.
  1259.  
  1260.  
  1261.  
  1262.   7. Q: I am confused by the above questions, but am not yet bailing
  1263.      out.  Is it safe to run fsck /dev/md0 ?
  1264.  
  1265.  
  1266.        A: Yes, it is safe to run fsck on the md devices.  In fact,
  1267.        this is the only safe place to run fsck.
  1268.  
  1269.  
  1270.  
  1271.   8. Q: If a disk is slowly failing, will it be obvious which one it is?
  1272.      I am concerned that it won't be, and this confusion could lead to
  1273.      some dangerous decisions by a sysadmin.
  1274.  
  1275.  
  1276.        A: Once a disk fails, an error code will be returned from
  1277.        the low level driver to the RAID driver.  The RAID driver
  1278.        will mark it as ``bad'' in the RAID superblocks of the
  1279.        ``good'' disks (so we will later know which mirrors are good
  1280.        and which aren't), and continue RAID operation on the
  1281.        remaining operational mirrors.
  1282.  
  1283.  
  1284.        This, of course, assumes that the disk and the low level
  1285.        driver can detect a read/write error, and will not silently
  1286.        corrupt data, for example. This is true of current drives
  1287.        (error detection schemes are being used internally), and is
  1288.        the basis of RAID operation.
  1289.  
  1290.  
  1291.  
  1292.   9. Q: What about hot-repair?
  1293.  
  1294.  
  1295.        A: Work is underway to complete ``hot reconstruction''.
  1296.        With this feature, one can add several ``spare'' disks to
  1297.        the RAID set (be it level 1 or 4/5), and once a disk fails,
  1298.        it will be reconstructed on one of the spare disks in run
  1299.        time, without ever needing to shut down the array.
  1300.  
  1301.  
  1302.        However, to use this feature, the spare disk must have been
  1303.        declared at boot time, or it must be hot-added, which
  1304.        requires the use of special cabinets and connectors that
  1305.        allow a disk to be added while the electrical power is on.
  1306.  
  1307.  
  1308.        As of October 97, there is a beta version of MD that allows:
  1309.  
  1310.        ╖  RAID 1 and 5 reconstruction on spare drives
  1311.  
  1312.        ╖  RAID-5 parity reconstruction after an unclean shutdown
  1313.  
  1314.        ╖  spare disk to be hot-added to an already running RAID 1
  1315.           or 4/5 array
  1316.  
  1317.           By default, automatic reconstruction is (Dec 97)
  1318.           currently disabled by default, due to the preliminary
  1319.           nature of this work.  It can be enabled by changing the
  1320.           value of SUPPORT_RECONSTRUCTION in include/linux/md.h.
  1321.      If spare drives were configured into the array when it
  1322.      was created and kernel-based reconstruction is enabled,
  1323.      the spare drive will already contain a RAID superblock
  1324.      (written by mkraid), and the kernel will reconstruct its
  1325.      contents automatically (without needing the usual mdstop,
  1326.      replace drive, ckraid, mdrun steps).
  1327.  
  1328.  
  1329.      If you are not running automatic reconstruction, and have
  1330.      not configured a hot-spare disk, the procedure described
  1331.      by Gadi Oxman <gadio@netvision.net.il> is recommended:
  1332.  
  1333.   ╖  Currently, once the first disk is removed, the RAID set
  1334.      will be running in degraded mode. To restore full
  1335.      operation mode, you need to:
  1336.  
  1337.   ╖  stop the array (mdstop /dev/md0)
  1338.  
  1339.   ╖  replace the failed drive
  1340.  
  1341.   ╖  run ckraid raid.conf to reconstruct its contents
  1342.  
  1343.   ╖  run the array again (mdadd, mdrun).
  1344.  
  1345.      At this point, the array will be running with all the
  1346.      drives, and again protects against a failure of a single
  1347.      drive.
  1348.  
  1349.      Currently, it is not possible to assign single hot-spare
  1350.      disk to several arrays.   Each array requires it's own
  1351.      hot-spare.
  1352.  
  1353.  
  1354.  
  1355.   10.
  1356.      Q: I would like to have an audible alarm for ``you schmuck, one
  1357.      disk in the mirror is down'', so that the novice sysadmin knows
  1358.      that there is a problem.
  1359.  
  1360.  
  1361.        A: The kernel is logging the event with a ``KERN_ALERT''
  1362.        priority in syslog.  There are several software packages
  1363.        that will monitor the syslog files, and beep the PC speaker,
  1364.        call a pager, send e-mail, etc. automatically.
  1365.  
  1366.  
  1367.  
  1368.   11.
  1369.      Q: How do I run RAID-5 in degraded mode (with one disk failed, and
  1370.      not yet replaced)?
  1371.  
  1372.  
  1373.        A: Gadi Oxman <gadio@netvision.net.il> writes: Normally, to
  1374.        run a RAID-5 set of n drives you have to:
  1375.  
  1376.  
  1377.        mdadd /dev/md0 /dev/disk1 ... /dev/disk(n)
  1378.        mdrun -p5 /dev/md0
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.   Even if one of the disks has failed, you still have to mdadd
  1385.   it as you would in a normal setup.  (?? try using /dev/null
  1386.   in place of the failed disk ???  watch out) Then,
  1387.   The array will be active in degraded mode with (n - 1)
  1388.   drives.  If ``mdrun'' fails, the kernel has noticed an error
  1389.   (for example, several faulty drives, or an unclean shut¡
  1390.   down).  Use ``dmesg'' to display the kernel error messages
  1391.   from ``mdrun''.  If the raid-5 set is corrupted due to a
  1392.   power loss, rather than a disk crash, one can try to recover
  1393.   by creating a new RAID superblock:
  1394.  
  1395.  
  1396.        mkraid -f --only-superblock raid5.conf
  1397.  
  1398.  
  1399.  
  1400.  
  1401.  
  1402.   A RAID array doesn't provide protection against a power
  1403.   failure or a kernel crash, and can't guarantee correct
  1404.   recovery.  Rebuilding the superblock will simply cause the
  1405.   system to ignore the condition by marking all the drives as
  1406.   ``OK'', as if nothing happened.
  1407.  
  1408.  
  1409.  
  1410.   12.
  1411.      Q: How does RAID-5 work when a disk fails?
  1412.  
  1413.  
  1414.        A: The typical operating scenario is as follows:
  1415.  
  1416.        ╖  A RAID-5 array is active.
  1417.  
  1418.        ╖  One drive fails while the array is active.
  1419.  
  1420.        ╖  The drive firmware and the low-level Linux
  1421.           disk/controller drivers detect the failure and report an
  1422.           error code to the MD driver.
  1423.  
  1424.        ╖  The MD driver continues to provide an error-free /dev/md0
  1425.           device to the higher levels of the kernel (with a
  1426.           performance degradation) by using the remaining
  1427.           operational drives.
  1428.  
  1429.        ╖  The sysadmin can umount /dev/md0 and mdstop /dev/md0 as
  1430.           usual.
  1431.  
  1432.        ╖  If the failed drive is not replaced, the sysadmin can
  1433.           still start the array in degraded mode as usual, by
  1434.           running mdadd and mdrun.
  1435.  
  1436.  
  1437.  
  1438.   13.
  1439.      Q:
  1440.  
  1441.        A:
  1442.  
  1443.  
  1444.  
  1445.   14.
  1446.      Q: Why is there no question 13?
  1447.  
  1448.  
  1449.        A: If you are concerned about RAID, High Availability, and
  1450.        UPS, then its probably a good idea to be superstitious as
  1451.        well.  It can't hurt, can it?
  1452.  
  1453.   15.
  1454.      Q: I just replaced a failed disk in a RAID-5 array.  After
  1455.      rebuilding the array, fsck is reporting many, many errors.  Is this
  1456.      normal?
  1457.  
  1458.  
  1459.        A: No. And, unless you ran fsck in "verify only; do not
  1460.        update" mode, its quite possible that you have corrupted
  1461.        your data.  Unfortunately, a not-uncommon scenario is one of
  1462.        accidentally changing the disk order in a RAID-5 array,
  1463.        after replacing a hard drive.  Although the RAID superblock
  1464.        stores the proper order, not all tools use this information.
  1465.        In particular, the current version of ckraid will use the
  1466.        information specified with the -f flag (typically, the file
  1467.        /etc/raid5.conf) instead of the data in the superblock.  If
  1468.        the specified order is incorrect, then the replaced disk
  1469.        will be reconstructed incorrectly.   The symptom of this
  1470.        kind of mistake seems to be heavy & numerous fsck errors.
  1471.  
  1472.  
  1473.        And, in case you are wondering, yes, someone lost all of
  1474.        their data by making this mistake.   Making a tape backup of
  1475.        all data before reconfiguring a RAID array is strongly
  1476.        recommended.
  1477.  
  1478.  
  1479.  
  1480.   16.
  1481.      Q: The QuickStart says that mdstop is just to make sure that the
  1482.      disks are sync'ed. Is this REALLY necessary? Isn't unmounting the
  1483.      file systems enough?
  1484.  
  1485.  
  1486.        A: The command mdstop /dev/md0 will:
  1487.  
  1488.        ╖  mark it ''clean''. This allows us to detect unclean
  1489.           shutdowns, for example due to a power failure or a kernel
  1490.           crash.
  1491.  
  1492.        ╖  sync the array. This is less important after unmounting a
  1493.           filesystem, but is important if the /dev/md0 is accessed
  1494.           directly rather than through a filesystem (for example,
  1495.           by e2fsck).
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.   5.  Troubleshooting Install Problems
  1502.  
  1503.  
  1504.   1. Q: What is the current best known-stable patch for RAID in the
  1505.      2.0.x series kernels?
  1506.  
  1507.  
  1508.        A: As of 18 Sept 1997, it is "2.0.30 + pre-9 2.0.31 + Werner
  1509.        Fink's swapping patch + the alpha RAID patch".  As of Novem¡
  1510.        ber 1997, it is 2.0.31 + ... !?
  1511.  
  1512.  
  1513.  
  1514.   2. Q: The RAID patches will not install cleanly for me.  What's wrong?
  1515.  
  1516.        A: Make sure that /usr/include/linux is a symbolic link to
  1517.        /usr/src/linux/include/linux.
  1518.  
  1519.   Make sure that the new files raid5.c, etc.  have been copied
  1520.   to their correct locations.  Sometimes the patch command
  1521.   will not create new files.  Try the -f flag on patch.
  1522.  
  1523.  
  1524.  
  1525.   3. Q: While compiling raidtools 0.42, compilation stops trying to
  1526.      include <pthread.h> but it doesn't exist in my system.  How do I
  1527.      fix this?
  1528.  
  1529.  
  1530.        A: raidtools-0.42 requires linuxthreads-0.6 from:
  1531.        <ftp://ftp.inria.fr/INRIA/Projects/cristal/Xavier.Leroy>
  1532.        Alternately, use glibc v2.0.
  1533.  
  1534.  
  1535.  
  1536.   4. Q: I get the message: mdrun -a /dev/md0: Invalid argument
  1537.  
  1538.  
  1539.        A: Use mkraid to initialize the RAID set prior to the first
  1540.        use.  mkraid ensures that the RAID array is initially in a
  1541.        consistent state by erasing the RAID partitions. In addi¡
  1542.        tion, mkraid will create the RAID superblocks.
  1543.  
  1544.  
  1545.  
  1546.   5. Q: I get the message: mdrun -a /dev/md0: Invalid argument The setup
  1547.      was:
  1548.  
  1549.   ╖  raid build as a kernel module
  1550.  
  1551.   ╖  normal install procedure followed ... mdcreate, mdadd, etc.
  1552.  
  1553.   ╖  cat /proc/mdstat shows
  1554.  
  1555.          Personalities :
  1556.          read_ahead not set
  1557.          md0 : inactive sda1 sdb1 6313482 blocks
  1558.          md1 : inactive
  1559.          md2 : inactive
  1560.          md3 : inactive
  1561.  
  1562.  
  1563.  
  1564.  
  1565.   ╖  mdrun -a generates the error message /dev/md0: Invalid argument
  1566.  
  1567.  
  1568.  
  1569.        A: Try lsmod (or, alternately, cat /proc/modules) to see if
  1570.        the raid modules are loaded.  If they are not, you can load
  1571.        them explicitly with the modprobe raid1 or modprobe raid5
  1572.        command.  Alternately,  if you are using the autoloader, and
  1573.        expected kerneld to load them and it didn't this is probably
  1574.        because your loader is missing the info to load the modules.
  1575.        Edit /etc/conf.modules and add the following lines:
  1576.  
  1577.  
  1578.            alias md-personality-3 raid1
  1579.            alias md-personality-4 raid5
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.   6. Q: While doing mdadd -a I get the error: /dev/md0: No such file or
  1586.      directory.  Indeed, there seems to be no /dev/md0 anywhere.  Now
  1587.      what do I do?
  1588.  
  1589.  
  1590.        A: The raid-tools package will create these devices when you
  1591.        run make install as root.  Alternately, you can do the fol¡
  1592.        lowing:
  1593.  
  1594.            cd /dev
  1595.            ./MAKEDEV md
  1596.  
  1597.  
  1598.  
  1599.  
  1600.  
  1601.  
  1602.  
  1603.   7. Q: After creating a raid array on /dev/md0, I try to mount it and
  1604.      get the following error:
  1605.       mount: wrong fs type, bad option, bad superblock on /dev/md0, or
  1606.      too many mounted file systems. What's wrong?
  1607.  
  1608.        A: You need to create a file system on /dev/md0 before you
  1609.        can mount it.  Use mke2fs.
  1610.  
  1611.  
  1612.  
  1613.  
  1614.   8. Q: Truxton Fulton wrote:
  1615.  
  1616.        On my Linux 2.0.30 system, while doing a mkraid for a RAID-1
  1617.        device, during the clearing of the two individual parti¡
  1618.        tions, I got "Cannot allocate free page" errors appearing on
  1619.        the console, and "Unable to handle kernel paging request at
  1620.        virtual address ..." errors in the system log.  At this
  1621.        time, the system became quite unusable, but it appears to
  1622.        recover after a while.  The operation appears to have com¡
  1623.        pleted with no other errors, and I am successfully using my
  1624.        RAID-1 device.  The errors are disconcerting though.  Any
  1625.        ideas?
  1626.  
  1627.  
  1628.  
  1629.  
  1630.        A: This was a well-known bug in the 2.0.30 kernels.  It is
  1631.        fixed in the 2.0.31 kernel; alternately, fall back to
  1632.        2.0.29.
  1633.  
  1634.  
  1635.  
  1636.   9. Q: I'm not able to mdrun a RAID-1, RAID-4 or RAID-5 device.  If I
  1637.      try to mdrun a mdadd'ed device I get the message ''invalid raid
  1638.      superblock magic''.
  1639.  
  1640.  
  1641.        A: Make sure that you've run the mkraid part of the install
  1642.        procedure.
  1643.  
  1644.  
  1645.  
  1646.   10.
  1647.      Q: When I access /dev/md0, the kernel spits out a lot of errors
  1648.      like md0: device not running, giving up !  and I/O error.... I've
  1649.      successfully added my devices to the virtual device.
  1650.  
  1651.        A: To be usable, the device must be running. Use mdrun -px
  1652.        /dev/md0 where x is l for linear, 0 for RAID-0 or 1 for
  1653.        RAID-1, etc.
  1654.  
  1655.  
  1656.  
  1657.   11.
  1658.      Q: I've created a linear md-dev with 2 devices.  cat /proc/mdstat
  1659.      shows the total size of the device, but df only shows the size of
  1660.      the first physical device.
  1661.  
  1662.  
  1663.        A: You must mkfs your new md-dev before using it the first
  1664.        time, so that the filesystem will cover the whole device.
  1665.  
  1666.  
  1667.  
  1668.   12.
  1669.      Q: I've set up /etc/mdtab using mdcreate, I've mdadd'ed, mdrun and
  1670.      fsck'ed my two /dev/mdX partitions.  Everything looks okay before a
  1671.      reboot.  As soon as I reboot, I get an fsck error on both
  1672.      partitions: fsck.ext2: Attempt to read block from filesystem
  1673.      resulted in short read while trying too open /dev/md0.  Why?! How
  1674.      do I fix it?!
  1675.  
  1676.  
  1677.        A: During the boot process, the RAID partitions must be
  1678.        started before they can be fsck'ed.  This must be done in
  1679.        one of the boot scripts.  For some distributions, fsck is
  1680.        called from /etc/rc.d/rc.S, for others, it is called from
  1681.        /etc/rc.d/rc.sysinit. Change this file to mdadd -ar *before*
  1682.        fsck -A is executed.  Better yet, it is suggested that
  1683.        ckraid be run if mdadd returns with an error.  How do do
  1684.        this is discussed in greater detail in question 14 of the
  1685.        section ''Error Recovery''.
  1686.  
  1687.  
  1688.  
  1689.   13.
  1690.      Q: I get the message invalid raid superblock magic while trying to
  1691.      run an array which consists of partitions which are bigger than
  1692.      4GB.
  1693.  
  1694.  
  1695.        A: This bug is now fixed. (September 97)  Make sure you have
  1696.        the latest raid code.
  1697.  
  1698.  
  1699.  
  1700.   14.
  1701.      Q: I get the message Warning: could not write 8 blocks in inode
  1702.      table starting at 2097175 while trying to run mke2fs on a partition
  1703.      which is larger than 2GB.
  1704.  
  1705.  
  1706.        A: This seems to be a problem with mke2fs (November 97).  A
  1707.        temporary work-around is to get the mke2fs code, and add
  1708.        #undef HAVE_LLSEEK to e2fsprogs-1.10/lib/ext2fs/llseek.c
  1709.        just before the first #ifdef HAVE_LLSEEK and recompile
  1710.        mke2fs.
  1711.  
  1712.  
  1713.  
  1714.   15.
  1715.      Q: ckraid currently isn't able to read /etc/mdtab
  1716.  
  1717.        A: The RAID0/linear configuration file format used in
  1718.        /etc/mdtab is obsolete, although it will be supported for a
  1719.        while more.  The current, up-to-date config files are cur¡
  1720.        rently named /etc/raid1.conf, etc.
  1721.  
  1722.  
  1723.  
  1724.   16.
  1725.      Q: The personality modules (raid1.o) are not loaded automatically;
  1726.      they have to be manually modprobe'd before mdrun. How can this be
  1727.      fixed?
  1728.  
  1729.  
  1730.        A: To autoload the modules, we can add the following to
  1731.        /etc/conf.modules:
  1732.  
  1733.            alias md-personality-3 raid1
  1734.            alias md-personality-4 raid5
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.  
  1741.   17.
  1742.      Q: I've mdadd'ed 13 devices, and now I'm trying to mdrun -p5
  1743.      /dev/md0 and get the message: /dev/md0: Invalid argument
  1744.  
  1745.  
  1746.        A: The default configuration for software RAID is 8 real
  1747.        devices. Edit linux/md.h, change #define MAX_REAL=8 to a
  1748.        larger number, and rebuild the kernel.
  1749.  
  1750.  
  1751.  
  1752.   18.
  1753.      Q: I can't make md work with partitions on our latest SPARCstation
  1754.      5.  I suspect that this has something to do with disk-labels.
  1755.  
  1756.  
  1757.        A: Sun disk-labels sit in the first 1K of a partition.  For
  1758.        RAID-1, the Sun disk-label is not an issue since ext2fs will
  1759.        skip the label on every mirror.  For other raid levels (0,
  1760.        linear and 4/5), this appears to be a problem; it has not
  1761.        yet (Dec 97) been addressed.
  1762.  
  1763.  
  1764.  
  1765.   6.  Supported Hardware & Software
  1766.  
  1767.  
  1768.   1. Q: I have SCSI adapter brand XYZ (with or without several
  1769.      channels), and disk brand(s) PQR and LMN, will these work with md
  1770.      to create a linear/stripped/mirrored personality?
  1771.  
  1772.  
  1773.        A: Yes!  Software RAID will work with any disk controller
  1774.        (IDE or SCSI) and any disks.  The disks do not have to be
  1775.        identical, nor do the controllers.  For example, a RAID mir¡
  1776.        ror can be created with one half the mirror being a SCSI
  1777.        disk, and the other an IDE disk.  The disks do not even have
  1778.        to be the same size.  There are no restrictions on the mix¡
  1779.        ing & matching of disks and controllers.
  1780.  
  1781.  
  1782.        This is because Software RAID works with disk partitions,
  1783.   not with the raw disks themselves.  The only recommendation
  1784.   is that for RAID levels 1 and 5, the disk partitions that
  1785.   are used as part of the same set be the same size. If the
  1786.   partitions used to make up the RAID 1 or 5 array are not the
  1787.   same size, then the excess space in the larger partitions is
  1788.   wasted (not used).
  1789.  
  1790.  
  1791.  
  1792.   2. Q: I have a twin channel BT-952, and the box states that it
  1793.      supports hardware RAID 0, 1 and 0+1.   I have made a RAID set with
  1794.      two drives, the card apparently recognizes them when it's doing
  1795.      it's BIOS startup routine. I've been reading in the driver source
  1796.      code, but found no reference to the hardware RAID support.  Anybody
  1797.      out there working on that?
  1798.  
  1799.  
  1800.        A: The Mylex/BusLogic FlashPoint boards with RAIDPlus are
  1801.        actually software RAID, not hardware RAID at all.  RAIDPlus
  1802.        is only supported on Windows 95 and Windows NT, not on Net¡
  1803.        ware or any of the Unix platforms.  Aside from booting and
  1804.        configuration, the RAID support is actually in the OS
  1805.        drivers.
  1806.  
  1807.  
  1808.        While in theory Linux support for RAIDPlus is possible, the
  1809.        implementation of RAID-0/1/4/5 in the Linux kernel is much
  1810.        more flexible and should have superior performance, so
  1811.        there's little reason to support RAIDPlus directly.
  1812.  
  1813.  
  1814.  
  1815.   3. Q: I want to run RAID with an SMP box.  Is  RAID SMP-safe?
  1816.  
  1817.        A: "I think so" is the best answer available at the time I
  1818.        write this (April 98).  A number of users report that they
  1819.        have been using RAID with SMP for nearly a year, without
  1820.        problems.  However, as of April 98 (circa kernel 2.1.9x),
  1821.        the following problems have been noted on the mailing list:
  1822.  
  1823.        ╖  Adaptec AIC7xxx SCSI drivers are not SMP safe (General
  1824.           note: Adaptec adapters have a long & lengthly history of
  1825.           problems & flakiness in general.  Although they seem to
  1826.           be the most easily available, widespread and cheapest
  1827.           SCSI adapters, they should be avoided.  After factoring
  1828.           for time lost, frustration, and corrupted data, Adaptec's
  1829.           will prove to be the costliest mistake you'll ever make.
  1830.           That said, if you have SMP problems with 2.1.88, try the
  1831.           patch ftp://ftp.bero-
  1832.           online.ml.org/pub/linux/aic7xxx-5.0.7-linux21.tar.gz I am
  1833.           not sure if this patch has been pulled into later 2.1.x
  1834.           kernels.  For further info, take a look at the mail
  1835.           archives for March 98 at
  1836.           http://www.linuxhq.com/lnxlists/linux-raid/lr_9803_01/ As
  1837.           usual, due to the rapidly changing nature of the latest
  1838.           experimental 2.1.x kernels, the problems described in
  1839.           these mailing lists may or may not have been fixed by the
  1840.           time your read this. Caveat Emptor.  )
  1841.  
  1842.  
  1843.  
  1844.        ╖  IO-APIC with RAID-0 on SMP has been reported to crash in
  1845.           2.1.90
  1846.  
  1847.  
  1848.  
  1849.   7.  Modifying an Existing Installation
  1850.  
  1851.  
  1852.   1. Q: Are linear MD's expandable?  Can a new hard-drive/partition be
  1853.      added, and the size of the existing file system expanded?
  1854.  
  1855.  
  1856.        A: Miguel de Icaza <miguel@luthien.nuclecu.unam.mx> writes:
  1857.  
  1858.        I changed the ext2fs code to be aware of multiple-devices
  1859.        instead of the regular one device per file system assump¡
  1860.        tion.
  1861.  
  1862.  
  1863.        So, when you want to extend a file system, you run a utility
  1864.        program that makes the appropriate changes on the new device
  1865.        (your extra partition) and then you just tell the system to
  1866.        extend the fs using the specified device.
  1867.  
  1868.  
  1869.        You can extend a file system with new devices at system
  1870.        operation time, no need to bring the system down (and
  1871.        whenever I get some extra time, you will be able to remove
  1872.        devices from the ext2 volume set, again without even having
  1873.        to go to single-user mode or any hack like that).
  1874.  
  1875.  
  1876.        You can get the patch for 2.1.x kernel from my web page:
  1877.  
  1878.        <http://www.nuclecu.unam.mx/~miguel/ext2-volume>
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.   2. Q: Can I add disks to a RAID-5 array?
  1885.  
  1886.  
  1887.        A: Currently, (September 1997) no, not without erasing all
  1888.        data. A conversion utility to allow this does not yet exist.
  1889.        The problem is that the actual structure and layout of a
  1890.        RAID-5 array depends on the number of disks in the array.
  1891.  
  1892.        Of course, one can add drives by backing up the array to
  1893.        tape, deleting all data, creating a new array, and restoring
  1894.        from tape.
  1895.  
  1896.  
  1897.  
  1898.   3. Q: What would happen to my RAID1/RAID0 sets if I shift one of the
  1899.      drives from being /dev/hdb to /dev/hdc?
  1900.  
  1901.      Because of cabling/case size/stupidity issues, I had to make my
  1902.      RAID sets on the same IDE controller (/dev/hda and /dev/hdb). Now
  1903.      that I've fixed some stuff, I want to move /dev/hdb to /dev/hdc.
  1904.  
  1905.      What would happen if I just change the /etc/mdtab and
  1906.      /etc/raid1.conf files to reflect the new location?
  1907.  
  1908.        A: For RAID-0/linear, one must be careful to specify the
  1909.        drives in exactly the same order. Thus, in the above exam¡
  1910.        ple, if the original config is
  1911.  
  1912.  
  1913.  
  1914.  
  1915.   mdadd /dev/md0 /dev/hda /dev/hdb
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.   Then the new config *must* be
  1922.  
  1923.  
  1924.        mdadd /dev/md0 /dev/hda /dev/hdc
  1925.  
  1926.  
  1927.  
  1928.  
  1929.  
  1930.  
  1931.   For RAID-1/4/5, the drive's ''RAID number'' is stored in its
  1932.   RAID superblock, and therefore the order in which the disks
  1933.   are specified is not important.
  1934.  
  1935.   RAID-0/linear does not have a superblock due to it's older
  1936.   design, and the desire to maintain backwards compatibility
  1937.   with this older design.
  1938.  
  1939.  
  1940.  
  1941.   4. Q: Can I convert a two-disk RAID-1 mirror to a three-disk RAID-5
  1942.      array?
  1943.  
  1944.  
  1945.        A: Yes.  Michael at BizSystems has come up with a clever,
  1946.        sneaky way of doing this.  However, like virtually all
  1947.        manipulations of RAID arrays once they have data on them, it
  1948.        is dangerous and prone to human error.  Make a backup before
  1949.        you start.
  1950.  
  1951.  
  1952.  
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958.  
  1959.  
  1960.  
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.   I will make the following assumptions:
  1982.   ---------------------------------------------
  1983.   disks
  1984.   original: hda - hdc
  1985.   raid1 partitions hda3 - hdc3
  1986.   array name /dev/md0
  1987.  
  1988.   new hda - hdc - hdd
  1989.   raid5 partitions hda3 - hdc3 - hdd3
  1990.   array name: /dev/md1
  1991.  
  1992.   You must substitute the appropriate disk and partition numbers for
  1993.   you system configuration. This will hold true for all config file
  1994.   examples.
  1995.   --------------------------------------------
  1996.   DO A BACKUP BEFORE YOU DO ANYTHING
  1997.   1) recompile kernel to include both raid1 and raid5
  1998.   2) install new kernel and verify that raid personalities are present
  1999.   3) disable the redundant partition on the raid 1 array. If this is a
  2000.    root mounted partition (mine was) you must be more careful.
  2001.  
  2002.    Reboot the kernel without starting raid devices or boot from rescue
  2003.    system ( raid tools must be available )
  2004.  
  2005.    start non-redundant raid1
  2006.   mdadd -r -p1 /dev/md0 /dev/hda3
  2007.  
  2008.   4) configure raid5 but with 'funny' config file, note that there is
  2009.     no hda3 entry and hdc3 is repeated. This is needed since the
  2010.     raid tools don't want you to do this.
  2011.   -------------------------------
  2012.   # raid-5 configuration
  2013.   raiddev                 /dev/md1
  2014.   raid-level              5
  2015.   nr-raid-disks           3
  2016.   chunk-size              32
  2017.  
  2018.   # Parity placement algorithm
  2019.   parity-algorithm        left-symmetric
  2020.  
  2021.   # Spare disks for hot reconstruction
  2022.   nr-spare-disks          0
  2023.  
  2024.   device                  /dev/hdc3
  2025.   raid-disk               0
  2026.  
  2027.   device                  /dev/hdc3
  2028.   raid-disk               1
  2029.  
  2030.   device                  /dev/hdd3
  2031.   raid-disk               2
  2032.   ---------------------------------------
  2033.    mkraid /etc/raid5.conf
  2034.   5) activate the raid5 array in non-redundant mode
  2035.  
  2036.   mdadd -r -p5 -c32k /dev/md1 /dev/hdc3 /dev/hdd3
  2037.  
  2038.   6) make a file system on the array
  2039.  
  2040.   mke2fs -b {blocksize} /dev/md1
  2041.  
  2042.   recommended blocksize by some is 4096 rather than the default 1024.
  2043.   this improves the memory utilization for the kernel raid routines and
  2044.   matches the blocksize to the page size. I compromised and used 2048
  2045.   since I have a relatively high number of small files on my system.
  2046.  
  2047.   7) mount the two raid devices somewhere
  2048.  
  2049.   mount -t ext2 /dev/md0 mnt0
  2050.   mount -t ext2 /dev/md1 mnt1
  2051.  
  2052.   8) move the data
  2053.  
  2054.   cp -a mnt0 mnt1
  2055.  
  2056.   9) verify that the data sets are identical
  2057.   10) stop both arrays
  2058.   11) correct the information for the raid5.conf file
  2059.     change /dev/md1 to /dev/md0
  2060.     change the first disk to read /dev/hda3
  2061.  
  2062.   12) upgrade the new array to full redundant status
  2063.    (THIS DESTROYS REMAINING raid1 INFORMATION)
  2064.  
  2065.   ckraid --fix /etc/raid5.conf
  2066.  
  2067.  
  2068.  
  2069.  
  2070.  
  2071.  
  2072.  
  2073.  
  2074.   8.  Performance, Tools & General Bone-headed Questions
  2075.  
  2076.  
  2077.   1. Q: I've created a RAID-0 device on /dev/sda2 and /dev/sda3. The
  2078.      device is a lot slower than a single partition. Isn't md a pile of
  2079.      junk?
  2080.  
  2081.        A: To have a RAID-0 device running a full speed, you must
  2082.        have partitions from different disks.  Besides, putting the
  2083.        two halves of the mirror on the same disk fails to give you
  2084.        any protection whatsoever against disk failure.
  2085.  
  2086.  
  2087.  
  2088.   2. Q: What's the use of having RAID-linear when RAID-0 will do the
  2089.      same thing, but provide higher performance?
  2090.  
  2091.        A: It's not obvious that RAID-0 will always provide better
  2092.        performance; in fact, in some cases, it could make things
  2093.        worse.  The ext2fs file system scatters files all over a
  2094.        partition, and it attempts to keep all of the blocks of a
  2095.        file contiguous, basically in an attempt to prevent fragmen¡
  2096.        tation.  Thus, ext2fs behaves "as if" there were a (vari¡
  2097.        able-sized) stripe per file.  If there are several disks
  2098.        concatenated into a single RAID-linear, this will result
  2099.        files being statistically distributed on each of the disks.
  2100.        Thus, at least for ext2fs, RAID-linear will behave a lot
  2101.        like RAID-0 with large stripe sizes.  Conversely, RAID-0
  2102.        with small stripe sizes can cause excessive disk activity
  2103.        leading to severely degraded performance if several large
  2104.        files are accessed simultaneously.
  2105.  
  2106.        In many cases, RAID-0 can be an obvious win. For example,
  2107.        imagine a large database file.  Since ext2fs attempts to
  2108.        cluster together all of the blocks of a file, chances are
  2109.        good that it will end up on only one drive if RAID-linear is
  2110.        used, but will get chopped into lots of stripes if RAID-0 is
  2111.        used.  Now imagine a number of (kernel) threads all trying
  2112.        to random access to this database.  Under RAID-linear, all
  2113.   accesses would go to one disk, which would not be as
  2114.   efficient as the parallel accesses that RAID-0 entails.
  2115.  
  2116.  
  2117.  
  2118.   3. Q: How does RAID-0 handle a situation where the different stripe
  2119.      partitions are different sizes?  Are the stripes uniformly
  2120.      distributed?
  2121.  
  2122.  
  2123.        A: To understand this, lets look at an example with three
  2124.        partitions; one that is 50MB, one 90MB and one 125MB.
  2125.  
  2126.        Lets call D0 the 50MB disk, D1 the 90MB disk and D2 the
  2127.        125MB disk.  When you start the device, the driver calcu¡
  2128.        lates 'strip zones'.  In this case, it finds 3 zones,
  2129.        defined like this:
  2130.  
  2131.  
  2132.                    Z0 : (D0/D1/D2) 3 x 50 = 150MB  total in this zone
  2133.                    Z1 : (D1/D2)  2 x 40 = 80MB total in this zone
  2134.                    Z2 : (D2) 125-50-40 = 35MB total in this zone.
  2135.  
  2136.  
  2137.  
  2138.  
  2139.        You can see that the total size of the zones is the size of
  2140.        the virtual device, but, depending on the zone, the striping
  2141.        is different.  Z2 is rather inefficient, since there's only
  2142.        one disk.
  2143.  
  2144.        Since ext2fs and most other Unix file systems distribute
  2145.        files all over the disk, you have a  35/265 = 13% chance
  2146.        that a fill will end up on Z2, and not get any of the bene¡
  2147.        fits of striping.
  2148.  
  2149.        (DOS tries to fill a disk from beginning to end, and thus,
  2150.        the oldest files would end up on Z0.  However, this strategy
  2151.        leads to severe filesystem fragmentation, which is why no
  2152.        one besides DOS does it this way.)
  2153.  
  2154.  
  2155.  
  2156.   4. Q: I have some Brand X hard disks and a Brand Y controller.  and am
  2157.      considering using md.  Does it significantly increase the
  2158.      throughput?  Is the performance really noticeable?
  2159.  
  2160.  
  2161.        A: The answer depends on the configuration that you use.
  2162.  
  2163.  
  2164.           Linux MD RAID-0 and RAID-linear performance:
  2165.              If the system is heavily loaded with lots of I/O,
  2166.              statistically, some of it will go to one disk, and
  2167.              some to the others.  Thus, performance will improve
  2168.              over a single large disk.   The actual improvement
  2169.              depends a lot on the actual data, stripe sizes, and
  2170.              other factors.   In a system with low I/O usage, the
  2171.              performance is equal to that of a single disk.
  2172.  
  2173.  
  2174.  
  2175.           Linux MD RAID-1 (mirroring) read performance:
  2176.              MD implements read balancing. That is, the  RAID-1
  2177.              code will alternate between each of the (two or more)
  2178.              disks in the mirror, making alternate reads to each.
  2179.         In a low-I/O situation, this won't change performance
  2180.         at all: you will have to wait for one disk to complete
  2181.         the read.  But, with two disks in a high-I/O
  2182.         environment, this could as much as double the read
  2183.         performance, since reads can be issued to each of the
  2184.         disks in parallel.  For N disks in the mirror, this
  2185.         could improve performance N-fold.
  2186.  
  2187.  
  2188.      Linux MD RAID-1 (mirroring) write performance:
  2189.         Must wait for the write to occur to all of the disks
  2190.         in the mirror.  This is because a copy of the data
  2191.         must be written to each of the disks in the mirror.
  2192.         Thus, performance will be roughly equal to the write
  2193.         performance to a single disk.
  2194.  
  2195.  
  2196.      Linux MD RAID-4/5 read performance:
  2197.         Statistically, a given block can be on any one of a
  2198.         number of disk drives, and thus RAID-4/5 read
  2199.         performance is a lot like that for RAID-0.  It will
  2200.         depend on the data, the stripe size, and the
  2201.         application.  It will not be as good as the read
  2202.         performance of a mirrored array.
  2203.  
  2204.  
  2205.      Linux MD RAID-4/5 write performance:
  2206.         This will in general be considerably slower than that
  2207.         for a single disk.  This is because the parity must be
  2208.         written out to one drive as well as the data to
  2209.         another.  However, in order to compute the new parity,
  2210.         the old parity and the old data must be read first.
  2211.         The old data, new data and old parity must all be
  2212.         XOR'ed together to determine the new parity: this
  2213.         requires considerable CPU cycles in addition to the
  2214.         numerous disk accesses.
  2215.  
  2216.  
  2217.  
  2218.   5. Q: What RAID configuration should I use for optimal performance?
  2219.  
  2220.        A: Is the goal to maximize throughput, or to minimize
  2221.        latency?  There is no easy answer, as there are many factors
  2222.        that affect performance:
  2223.  
  2224.  
  2225.        ╖  operating system  - will one process/thread, or many be
  2226.           performing disk access?
  2227.  
  2228.        ╖  application       - is it accessing data in a sequential
  2229.           fashion, or random access?
  2230.  
  2231.        ╖  file system       - clusters files or spreads them out
  2232.           (the ext2fs clusters together the blocks of a file, and
  2233.           spreads out files)
  2234.  
  2235.        ╖  disk driver       - number of blocks to read ahead (this
  2236.           is a tunable parameter)
  2237.  
  2238.        ╖  CEC hardware      - one drive controller, or many?
  2239.  
  2240.        ╖  hd controller     - able to queue multiple requests or
  2241.           not?  Does it provide a cache?
  2242.  
  2243.        ╖  hard drive        - buffer cache memory size -- is it big
  2244.           enough to handle the write sizes and rate you want?
  2245.   ╖  physical platters - blocks per cylinder -- accessing
  2246.      blocks on different cylinders will lead to seeks.
  2247.  
  2248.  
  2249.  
  2250.   6. Q: What is the optimal RAID-5 configuration for performance?
  2251.  
  2252.        A: Since RAID-5 experiences an I/O load that is equally dis¡
  2253.        tributed across several drives, the best performance will be
  2254.        obtained when the RAID set is balanced by using identical
  2255.        drives, identical controllers,  and the same (low) number of
  2256.        drives on each controller.
  2257.  
  2258.        Note, however, that using identical components will raise
  2259.        the probability of multiple simultaneous failures, for exam¡
  2260.        ple due to a sudden jolt or drop, overheating, or a power
  2261.        surge during an electrical storm. Mixing brands and models
  2262.        helps reduce this risk.
  2263.  
  2264.  
  2265.  
  2266.   7. Q: What is the optimal block size for a RAID-4/5 array?
  2267.  
  2268.  
  2269.        A: When using the current (November 1997) RAID-4/5 implemen¡
  2270.        tation, it is strongly recommended that the file system be
  2271.        created with mke2fs -b 4096 instead of the default 1024 byte
  2272.        filesystem block size.
  2273.  
  2274.  
  2275.        This is because the current RAID-5 implementation allocates
  2276.        one 4K memory page per disk block; if a disk block were just
  2277.        1K in size, then 75% of the memory which RAID-5 is
  2278.        allocating for pending I/O would not be used.  If the disk
  2279.        block size matches the memory page size, then the driver can
  2280.        (potentially) use all of the page.  Thus, for a filesystem
  2281.        with a 4096 block size as opposed to a 1024 byte block size,
  2282.        the RAID driver will potentially queue 4 times as much
  2283.        pending I/O to the low level drivers without allocating
  2284.        additional memory.
  2285.  
  2286.  
  2287.        Note: the above remarks do NOT apply to Software
  2288.        RAID-0/1/linear driver.
  2289.  
  2290.  
  2291.        Note: the statements about 4K memory page size apply to the
  2292.        Intel x86 architecture.   The page size on Alpha, Sparc, and
  2293.        other CPUS are different; I believe they're 8K on
  2294.        Alpha/Sparc (????).  Adjust the above figures accordingly.
  2295.  
  2296.  
  2297.        Note: if your file system has a lot of small files (files
  2298.        less than 10KBytes in size), a considerable fraction of the
  2299.        disk space might be wasted.  This is because the file system
  2300.        allocates disk space in multiples of the block size.
  2301.        Allocating large blocks for small files clearly results in a
  2302.        waste of disk space: thus, you may want to stick to small
  2303.        block sizes, get a larger effective storage capacity, and
  2304.        not worry about the "wasted" memory due to the block-
  2305.        size/page-size mismatch.
  2306.  
  2307.  
  2308.        Note: most ''typical'' systems do not have that many small
  2309.        files.  That is, although there might be thousands of small
  2310.        files, this would lead to only some 10 to 100MB wasted
  2311.   space, which is probably an acceptable tradeoff for
  2312.   performance on a multi-gigabyte disk.
  2313.  
  2314.   However, for news servers, there might be tens or hundreds
  2315.   of thousands of small files.  In such cases, the smaller
  2316.   block size, and thus the improved storage capacity, may be
  2317.   more important than the more efficient I/O scheduling.
  2318.  
  2319.  
  2320.   Note: there exists an experimental file system for Linux
  2321.   which packs small files and file chunks onto a single block.
  2322.   It apparently has some very positive performance
  2323.   implications when the average file size is much smaller than
  2324.   the block size.
  2325.  
  2326.  
  2327.   Note: Future versions may implement schemes that obsolete
  2328.   the above discussion. However, this is difficult to
  2329.   implement, since dynamic run-time allocation can lead to
  2330.   dead-locks; the current implementation performs a static
  2331.   pre-allocation.
  2332.  
  2333.  
  2334.  
  2335.   8. Q: How does the chunk size (stripe size) influence the speed of my
  2336.      RAID-0, RAID-4 or RAID-5 device?
  2337.  
  2338.  
  2339.        A: The chunk size is the amount of data contiguous on the
  2340.        virtual device that is also contiguous on the physical
  2341.        device.  In this HOWTO, "chunk" and "stripe" refer to the
  2342.        same thing: what is commonly called the "stripe" in other
  2343.        RAID documentation is called the "chunk" in the MD man
  2344.        pages.  Stripes or chunks apply only to RAID 0, 4 and 5,
  2345.        since stripes are not used in mirroring (RAID-1) and simple
  2346.        concatenation (RAID-linear).  The stripe size affects both
  2347.        read and write latency (delay), throughput (bandwidth), and
  2348.        contention between independent operations (ability to simul¡
  2349.        taneously service overlapping I/O requests).
  2350.  
  2351.        Assuming the use of the ext2fs file system, and the current
  2352.        kernel policies about read-ahead, large stripe sizes are
  2353.        almost always better than small stripe sizes, and stripe
  2354.        sizes from about a fourth to a full disk cylinder in size
  2355.        may be best.  To understand this claim, let us consider the
  2356.        effects of large stripes on small files, and small stripes
  2357.        on large files.  The stripe size does not affect the read
  2358.        performance of small files:  For an array of N drives, the
  2359.        file has a 1/N probability of being entirely within one
  2360.        stripe on any one of the drives.  Thus, both the read
  2361.        latency and bandwidth will be comparable to that of a single
  2362.        drive.  Assuming that the small files are statistically well
  2363.        distributed around the filesystem, (and, with the ext2fs
  2364.        file system, they should be), roughly N times more
  2365.        overlapping, concurrent reads should be possible without
  2366.        significant collision between them.  Conversely, if very
  2367.        small stripes are used, and a large file is read
  2368.        sequentially, then a read will issued to all of the disks in
  2369.        the array.  For a the read of a single large file, the
  2370.        latency will almost double, as the probability of a block
  2371.        being 3/4'ths of a revolution or farther away will increase.
  2372.        Note, however, the trade-off: the bandwidth could improve
  2373.        almost N-fold for reading a single, large file, as N drives
  2374.        can be reading simultaneously (that is, if read-ahead is
  2375.        used so that all of the disks are kept active).  But there
  2376.        is another, counter-acting trade-off:  if all of the drives
  2377.   are already busy reading one file, then attempting to read a
  2378.   second or third file at the same time will cause significant
  2379.   contention, ruining performance as the disk ladder
  2380.   algorithms lead to seeks all over the platter.  Thus,  large
  2381.   stripes will almost always lead to the best performance. The
  2382.   sole exception is the case where one is streaming a single,
  2383.   large file at a time, and one requires the top possible
  2384.   bandwidth, and one is also using a good read-ahead
  2385.   algorithm, in which case small stripes are desired.
  2386.  
  2387.  
  2388.   Note that this HOWTO previously recommended small stripe
  2389.   sizes for news spools or other systems with lots of small
  2390.   files. This was bad advice, and here's why:  news spools
  2391.   contain not only many small files, but also large summary
  2392.   files, as well as large directories.  If the summary file is
  2393.   larger than the stripe size, reading it will cause many
  2394.   disks to be accessed, slowing things down as each disk
  2395.   performs a seek.  Similarly, the current ext2fs file system
  2396.   searches directories in a linear, sequential fashion.  Thus,
  2397.   to find a given file or inode, on average half of the
  2398.   directory will be read. If this directory is spread across
  2399.   several stripes (several disks), the directory read (e.g.
  2400.   due to the ls command) could get very slow. Thanks to Steven
  2401.   A. Reisman <sar@pressenter.com> for this correction.  Steve
  2402.   also adds:
  2403.  
  2404.        I found that using a 256k stripe gives much better perfor¡
  2405.        mance.  I suspect that the optimum size would be the size of
  2406.        a disk cylinder (or maybe the size of the disk drive's sec¡
  2407.        tor cache).  However, disks nowadays have recording zones
  2408.        with different sector counts (and sector caches vary among
  2409.        different disk models).  There's no way to guarantee stripes
  2410.        won't cross a cylinder boundary.
  2411.  
  2412.  
  2413.  
  2414.  
  2415.   The tools accept the stripe size specified in KBytes.  You'll want to
  2416.   specify a multiple of if the page size for your CPU (4KB on the x86).
  2417.  
  2418.  
  2419.  
  2420.  
  2421.   9. Q: What is the correct stride factor to use when creating the
  2422.      ext2fs file system on the RAID partition?  By stride, I mean the -R
  2423.      flag on the mke2fs command:
  2424.  
  2425.      mke2fs -b 4096 -R stride=nnn  ...
  2426.  
  2427.  
  2428.  
  2429.   What should the value of nnn be?
  2430.  
  2431.        A: The -R stride flag is used to tell the file system about
  2432.        the size of the RAID stripes.  Since only RAID-0,4 and 5 use
  2433.        stripes, and RAID-1 (mirroring) and RAID-linear do not, this
  2434.        flag is applicable only for RAID-0,4,5.
  2435.  
  2436.        Knowledge of the size of a stripe allows mke2fs to allocate
  2437.        the block and inode bitmaps so that they don't all end up on
  2438.        the same physical drive.  An unknown contributor wrote:
  2439.  
  2440.        I noticed last spring that one drive in a pair always had a
  2441.        larger I/O count, and tracked it down to the these meta-data
  2442.        blocks.  Ted added the -R stride= option in response to my
  2443.   explanation and request for a workaround.
  2444.  
  2445.  
  2446.   For a 4KB block file system, with stripe size 256KB, one would use -R
  2447.   stride=64.
  2448.  
  2449.   If you don't trust the -R flag, you can get a similar effect in a
  2450.   different way.   Steven A. Reisman <sar@pressenter.com> writes:
  2451.  
  2452.        Another consideration is the filesystem used on the RAID-0
  2453.        device.  The ext2 filesystem allocates 8192 blocks per
  2454.        group.  Each group has its own set of inodes.  If there are
  2455.        2, 4 or 8 drives, these inodes cluster on the first disk.
  2456.        I've distributed the inodes across all drives by telling
  2457.        mke2fs to allocate only 7932 blocks per group.
  2458.  
  2459.  
  2460.   Some mke2fs pages do not describe the [-g blocks-per-group] flag used
  2461.   in this operation.
  2462.  
  2463.  
  2464.  
  2465.   10.
  2466.      Q: Where can I put the md commands in the startup scripts, so that
  2467.      everything will start automatically at boot time?
  2468.  
  2469.  
  2470.        A: Rod Wilkens <rwilkens@border.net> writes:
  2471.  
  2472.        What I did is put ``mdadd -ar'' in the
  2473.        ``/etc/rc.d/rc.sysinit'' right after the kernel loads the
  2474.        modules, and before the ``fsck'' disk check.  This way, you
  2475.        can put the ``/dev/md?'' device in the ``/etc/fstab''. Then
  2476.        I put the ``mdstop -a'' right after the ``umount -a''
  2477.        unmounting the disks, in the ``/etc/rc.d/init.d/halt'' file.
  2478.  
  2479.  
  2480.   For raid-5, you will want to look at the return code for mdadd, and if
  2481.   it failed, do a
  2482.  
  2483.  
  2484.        ckraid --fix /etc/raid5.conf
  2485.  
  2486.  
  2487.  
  2488.  
  2489.  
  2490.   to repair any damage.
  2491.  
  2492.  
  2493.  
  2494.   11.
  2495.      Q: I was wondering if it's possible to setup striping with more
  2496.      than 2 devices in md0? This is for a news server, and I have 9
  2497.      drives... Needless to say I need much more than two.  Is this
  2498.      possible?
  2499.  
  2500.  
  2501.        A: Yes. (describe how to do this)
  2502.  
  2503.  
  2504.  
  2505.   12.
  2506.      Q: When is Software RAID superior to Hardware RAID?
  2507.  
  2508.  
  2509.   A: Normally, Hardware RAID is considered superior to Soft¡
  2510.   ware RAID, because hardware controllers often have a large
  2511.   cache, and can do a better job of scheduling operations in
  2512.   parallel.  However, integrated Software RAID can (and does)
  2513.   gain certain advantages from being close to the operating
  2514.   system.
  2515.  
  2516.  
  2517.   For example, ... ummm. Opaque description of caching of
  2518.   reconstructed blocks in buffer cache elided ...
  2519.  
  2520.  
  2521.   On a dual PPro SMP system, it has been reported that
  2522.   Software-RAID performance exceeds the performance of a well-
  2523.   known hardware-RAID board vendor by a factor of 2 to 5.
  2524.  
  2525.  
  2526.   Software RAID is also a very interesting option for high-
  2527.   availability redundant server systems.  In such a
  2528.   configuration, two CPU's are attached to one set or SCSI
  2529.   disks.  If one server crashes or fails to respond, then the
  2530.   other server can mdadd, mdrun and mount the software RAID
  2531.   array, and take over operations.  This sort of dual-ended
  2532.   operation is not always possible with many hardware RAID
  2533.   controllers, because of the state configuration that the
  2534.   hardware controllers maintain.
  2535.  
  2536.  
  2537.  
  2538.   13.
  2539.      Q: If I upgrade my version of raidtools, will it have trouble
  2540.      manipulating older raid arrays?  In short, should I recreate my
  2541.      RAID arrays when upgrading the raid utilities?
  2542.  
  2543.  
  2544.        A: No, not unless the major version number changes.  An MD
  2545.        version x.y.z consists of three sub-versions:
  2546.  
  2547.             x:      Major version.
  2548.             y:      Minor version.
  2549.             z:      Patchlevel version.
  2550.  
  2551.  
  2552.  
  2553.  
  2554.        Version x1.y1.z1 of the RAID driver supports a RAID array
  2555.        with version x2.y2.z2 in case (x1 == x2) and (y1 >= y2).
  2556.  
  2557.        Different patchlevel (z) versions for the same (x.y) version
  2558.        are designed to be mostly compatible.
  2559.  
  2560.  
  2561.        The minor version number is increased whenever the RAID
  2562.        array layout is changed in a way which is incompatible with
  2563.        older versions of the driver. New versions of the driver
  2564.        will maintain compatibility with older RAID arrays.
  2565.  
  2566.        The major version number will be increased if it will no
  2567.        longer make sense to support old RAID arrays in the new
  2568.        kernel code.
  2569.  
  2570.  
  2571.        For RAID-1, it's not likely that the disk layout nor the
  2572.        superblock structure will change anytime soon.  Most all Any
  2573.        optimization and new features (reconstruction, multithreaded
  2574.        tools, hot-plug, etc.) doesn't affect the physical layout.
  2575.   14.
  2576.      Q: The command mdstop /dev/md0 says that the device is busy.
  2577.  
  2578.  
  2579.        A: There's a process that has a file open on /dev/md0, or
  2580.        /dev/md0 is still mounted.  Terminate the process or umount
  2581.        /dev/md0.
  2582.  
  2583.  
  2584.  
  2585.   15.
  2586.      Q: Are there performance tools?
  2587.  
  2588.        A: There is also a new utility called iotrace in the
  2589.        linux/iotrace directory. It reads /proc/io-trace and analy¡
  2590.        ses/plots it's output.  If you feel your system's block IO
  2591.        performance is too low, just look at the iotrace output.
  2592.  
  2593.  
  2594.  
  2595.   16.
  2596.      Q: I was reading the RAID source, and saw the value SPEED_LIMIT
  2597.      defined as 1024K/sec.  What does this mean?  Does this limit
  2598.      performance?
  2599.  
  2600.  
  2601.        A: SPEED_LIMIT is used to limit RAID reconstruction speed
  2602.        during automatic reconstruction.  Basically, automatic
  2603.        reconstruction allows you to e2fsck and mount immediately
  2604.        after an unclean shutdown, without first running ckraid.
  2605.        Automatic reconstruction is also used after a failed hard
  2606.        drive has been replaced.
  2607.  
  2608.  
  2609.        In order to avoid overwhelming the system while
  2610.        reconstruction is occurring, the reconstruction thread
  2611.        monitors the reconstruction speed and slows it down if its
  2612.        too fast.  The 1M/sec limit was arbitrarily chosen as a
  2613.        reasonable rate which allows the reconstruction to finish
  2614.        reasonably rapidly, while creating only a light load on the
  2615.        system so that other processes are not interfered with.
  2616.  
  2617.  
  2618.  
  2619.   17.
  2620.      Q: What about ''spindle synchronization'' or ''disk
  2621.      synchronization''?
  2622.  
  2623.        A: Spindle synchronization is used to keep multiple hard
  2624.        drives spinning at exactly the same speed, so that their
  2625.        disk platters are always perfectly aligned.  This is used by
  2626.        some hardware controllers to better organize disk writes.
  2627.        However, for software RAID, this information is not used,
  2628.        and spindle synchronization might even hurt performance.
  2629.  
  2630.  
  2631.  
  2632.   18.
  2633.      Q: How can I set up swap spaces using raid 0?  Wouldn't striped
  2634.      swap ares over 4+ drives be really fast?
  2635.  
  2636.        A: Leonard N. Zubkoff replies: It is really fast, but you
  2637.        don't need to use MD to get striped swap.  The kernel auto¡
  2638.        matically stripes across equal priority swap spaces.  For
  2639.        example, the following entries from /etc/fstab stripe swap
  2640.        space across five drives in three groups:
  2641.   /dev/sdg1       swap    swap    pri=3
  2642.   /dev/sdk1       swap    swap    pri=3
  2643.   /dev/sdd1       swap    swap    pri=3
  2644.   /dev/sdh1       swap    swap    pri=3
  2645.   /dev/sdl1       swap    swap    pri=3
  2646.   /dev/sdg2       swap    swap    pri=2
  2647.   /dev/sdk2       swap    swap    pri=2
  2648.   /dev/sdd2       swap    swap    pri=2
  2649.   /dev/sdh2       swap    swap    pri=2
  2650.   /dev/sdl2       swap    swap    pri=2
  2651.   /dev/sdg3       swap    swap    pri=1
  2652.   /dev/sdk3       swap    swap    pri=1
  2653.   /dev/sdd3       swap    swap    pri=1
  2654.   /dev/sdh3       swap    swap    pri=1
  2655.   /dev/sdl3       swap    swap    pri=1
  2656.  
  2657.  
  2658.  
  2659.  
  2660.  
  2661.   19.
  2662.      Q: I want to maximize performance.  Should I use multiple
  2663.      controllers?
  2664.  
  2665.        A: In many cases, the answer is yes.  Using several con¡
  2666.        trollers to perform disk access in parallel will improve
  2667.        performance.  However, the actual improvement depends on
  2668.        your actual configuration.  For example, it has been
  2669.        reported (Vaughan Pratt, January 98) that a single 4.3GB
  2670.        Cheetah attached to an Adaptec 2940UW can achieve a rate of
  2671.        14MB/sec (without using RAID).  Installing two disks on one
  2672.        controller, and using a RAID-0 configuration results in a
  2673.        measured performance of 27 MB/sec.
  2674.  
  2675.  
  2676.        Note that the 2940UW controller is an "Ultra-Wide" SCSI
  2677.        controller, capable of a theoretical burst rate of 40MB/sec,
  2678.        and so the above measurements are not surprising.  However,
  2679.        a slower controller attached to two fast disks would be the
  2680.        bottleneck.  Note also, that most out-board SCSI enclosures
  2681.        (e.g. the kind with hot-pluggable trays) cannot be run at
  2682.        the 40MB/sec rate, due to cabling and electrical noise
  2683.        problems.
  2684.  
  2685.  
  2686.        If you are designing a multiple controller system, remember
  2687.        that most disks and controllers typically run at 70-85% of
  2688.        their rated max speeds.
  2689.  
  2690.  
  2691.        Note also that using one controller per disk can reduce the
  2692.        likelihood of system outage due to a controller or cable
  2693.        failure (In theory -- only if the device driver for the
  2694.        controller can gracefully handle a broken controller. Not
  2695.        all SCSI device drivers seem to be able to handle such a
  2696.        situation without panicking or otherwise locking up).
  2697.  
  2698.  
  2699.   9.  High Availability RAID
  2700.  
  2701.  
  2702.   1. Q: RAID can help protect me against data loss.  But how can I also
  2703.      ensure that the system is up as long as possible, and not prone to
  2704.      breakdown?  Ideally, I want a system that is up 24 hours a day, 7
  2705.      days a week, 365 days a year.
  2706.  
  2707.        A: High-Availability is difficult and expensive.  The harder
  2708.        you try to make a system be fault tolerant, the harder and
  2709.        more expensive it gets.   The following hints, tips, ideas
  2710.        and unsubstantiated rumors may help you with this quest.
  2711.  
  2712.        ╖  IDE disks can fail in such a way that the failed disk on
  2713.           an IDE ribbon can also prevent the good disk on the same
  2714.           ribbon from responding, thus making it look as if two
  2715.           disks have failed.   Since RAID does not protect against
  2716.           two-disk failures, one should either put only one disk on
  2717.           an IDE cable, or if there are two disks, they should
  2718.           belong to different RAID sets.
  2719.  
  2720.        ╖  SCSI disks can fail in such a way that the failed disk on
  2721.           a SCSI chain can prevent any device on the chain from
  2722.           being accessed.  The failure mode involves a short of the
  2723.           common (shared) device ready pin; since this pin is
  2724.           shared, no arbitration can occur until the short is
  2725.           removed.  Thus, no two disks on the same SCSI chain
  2726.           should belong to the same  RAID array.
  2727.  
  2728.        ╖  Similar remarks apply to the disk controllers.  Don't
  2729.           load up the channels on one controller; use multiple
  2730.           controllers.
  2731.  
  2732.        ╖  Don't use the same brand or model number for all of the
  2733.           disks.  It is not uncommon for severe electrical storms
  2734.           to take out two or more disks.  (Yes, we all use surge
  2735.           suppressors, but these are not perfect either).   Heat &
  2736.           poor ventilation of the disk enclosure are other disk
  2737.           killers.  Cheap disks often run hot.  Using different
  2738.           brands of disk & controller decreases the likelihood that
  2739.           whatever took out one disk (heat, physical shock,
  2740.           vibration, electrical surge) will also damage the others
  2741.           on the same date.
  2742.  
  2743.        ╖  To guard against controller or CPU failure, it should be
  2744.           possible to build a SCSI disk enclosure that is "twin-
  2745.           tailed": i.e. is connected to two computers.  One
  2746.           computer will mount the file-systems read-write, while
  2747.           the second computer will mount them read-only, and act as
  2748.           a hot spare.  When the hot-spare is able to determine
  2749.           that the master has failed (e.g.  through a watchdog), it
  2750.           will cut the power to the master (to make sure that it's
  2751.           really off), and then fsck & remount read-write.   If
  2752.           anyone gets this working, let me know.
  2753.  
  2754.        ╖  Always use an UPS, and perform clean shutdowns.  Although
  2755.           an unclean shutdown may not damage the disks, running
  2756.           ckraid on even small-ish arrays is painfully slow.   You
  2757.           want to avoid running ckraid as much as possible.  Or you
  2758.           can hack on the kernel and get the hot-reconstruction
  2759.           code debugged ...
  2760.  
  2761.        ╖  SCSI cables are well-known to be very temperamental
  2762.           creatures, and prone to cause all sorts of problems.  Use
  2763.           the highest quality cabling that you can find for sale.
  2764.           Use e.g. bubble-wrap to make sure that ribbon cables to
  2765.           not get too close to one another and cross-talk.
  2766.           Rigorously observe cable-length restrictions.
  2767.  
  2768.        ╖  Take a look at SSI (Serial Storage Architecture).
  2769.           Although it is rather expensive, it is rumored to be less
  2770.           prone to the failure modes that SCSI exhibits.
  2771.  
  2772.  
  2773.   ╖  Enjoy yourself, its later than you think.
  2774.  
  2775.  
  2776.   10.  Questions Waiting for Answers
  2777.  
  2778.  
  2779.   1. Q: If, for cost reasons, I try to mirror a slow disk with a fast
  2780.      disk, is the S/W smart enough to balance the reads accordingly or
  2781.      will it all slow down to the speed of the slowest?
  2782.  
  2783.  
  2784.   2. Q: For testing the raw disk thru put...  is there a character
  2785.      device for raw read/raw writes instead of /dev/sdaxx that we can
  2786.      use to measure performance on the raid drives??  is there a GUI
  2787.      based tool to use to watch the disk thru-put??
  2788.  
  2789.  
  2790.   11.  Wish List of Enhancements to MD and Related Software
  2791.  
  2792.   Bradley Ward Allen <ulmo@Q.Net> wrote:
  2793.  
  2794.        Ideas include:
  2795.  
  2796.        ╖  Boot-up parameters to tell the kernel which devices are
  2797.           to be MD devices (no more ``mdadd'')
  2798.  
  2799.        ╖  Making MD transparent to ``mount''/``umount'' such that
  2800.           there is no ``mdrun'' and ``mdstop''
  2801.  
  2802.        ╖  Integrating ``ckraid'' entirely into the kernel, and
  2803.           letting it run as needed
  2804.  
  2805.           (So far, all I've done is suggest getting rid of the
  2806.           tools and putting them into the kernel; that's how I feel
  2807.           about it, this is a filesystem, not a toy.)
  2808.  
  2809.        ╖  Deal with arrays that can easily survive N disks going
  2810.           out simultaneously or at separate moments, where N is a
  2811.           whole number > 0 settable by the administrator
  2812.  
  2813.        ╖  Handle kernel freezes, power outages, and other abrupt
  2814.           shutdowns better
  2815.  
  2816.        ╖  Don't disable a whole disk if only parts of it have
  2817.           failed, e.g., if the sector errors are confined to less
  2818.           than 50% of access over the attempts of 20 dissimilar
  2819.           requests, then it continues just ignoring those sectors
  2820.           of that particular disk.
  2821.  
  2822.        ╖  Bad sectors:
  2823.  
  2824.        ╖  A mechanism for saving which sectors are bad, someplace
  2825.           onto the disk.
  2826.  
  2827.        ╖  If there is a generalized mechanism for marking degraded
  2828.           bad blocks that upper filesystem levels can recognize,
  2829.           use that. Program it if not.
  2830.  
  2831.        ╖  Perhaps alternatively a mechanism for telling the upper
  2832.           layer that the size of the disk got smaller, even
  2833.           arranging for the upper layer to move out stuff from the
  2834.           areas being eliminated.  This would help with a degraded
  2835.           blocks as well.
  2836.  
  2837.        ╖  Failing the above ideas, keeping a small (admin settable)
  2838.           amount of space aside for bad blocks (distributed evenly
  2839.      across disk?), and using them (nearby if possible)
  2840.      instead of the bad blocks when it does happen.  Of
  2841.      course, this is inefficient.  Furthermore, the kernel
  2842.      ought to log every time the RAID array starts each bad
  2843.      sector and what is being done about it with a ``crit''
  2844.      level warning, just to get the administrator to realize
  2845.      that his disk has a piece of dust burrowing into it (or a
  2846.      head with platter sickness).
  2847.  
  2848.   ╖  Software-switchable disks:
  2849.  
  2850.      ``disable this disk''
  2851.         would block until kernel has completed making sure
  2852.         there is no data on the disk being shut down that is
  2853.         needed (e.g., to complete an XOR/ECC/other error
  2854.         correction), then release the disk from use (so it
  2855.         could be removed, etc.);
  2856.  
  2857.      ``enable this disk''
  2858.         would mkraid a new disk if appropriate and then start
  2859.         using it for ECC/whatever operations, enlarging the
  2860.         RAID5 array as it goes;
  2861.  
  2862.      ``resize array''
  2863.         would respecify the total number of disks and the
  2864.         number of redundant disks, and the result would often
  2865.         be to resize the size of the array; where no data loss
  2866.         would result, doing this as needed would be nice, but
  2867.         I have a hard time figuring out how it would do that;
  2868.         in any case, a mode where it would block (for possibly
  2869.         hours (kernel ought to log something every ten seconds
  2870.         if so)) would be necessary;
  2871.  
  2872.      ``enable this disk while saving data''
  2873.         which would save the data on a disk as-is and move it
  2874.         to the RAID5 system as needed, so that a horrific save
  2875.         and restore would not have to happen every time
  2876.         someone brings up a RAID5 system (instead, it may be
  2877.         simpler to only save one partition instead of two, it
  2878.         might fit onto the first as a gzip'd file even);
  2879.         finally,
  2880.  
  2881.      ``re-enable disk''
  2882.         would be an operator's hint to the OS to try out a
  2883.         previously failed disk (it would simply call disable
  2884.         then enable, I suppose).
  2885.  
  2886.  
  2887.   Other ideas off the net:
  2888.  
  2889.  
  2890.        ╖  finalrd analog to initrd, to simplify root raid.
  2891.  
  2892.        ╖  a read-only raid mode, to simplify the above
  2893.  
  2894.        ╖  Mark the RAID set as clean whenever there are no "half
  2895.           writes" done. -- That is, whenever there are no write
  2896.           transactions that were committed on one disk but still
  2897.           unfinished on another disk.
  2898.  
  2899.           Add a "write inactivity" timeout (to avoid frequent seeks
  2900.           to the RAID superblock when the RAID set is relatively
  2901.           busy).
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.  
  2909.  
  2910.  
  2911.  
  2912.  
  2913.  
  2914.  
  2915.  
  2916.  
  2917.  
  2918.  
  2919.  
  2920.  
  2921.  
  2922.  
  2923.  
  2924.  
  2925.  
  2926.  
  2927.  
  2928.  
  2929.  
  2930.  
  2931.  
  2932.  
  2933.  
  2934.  
  2935.  
  2936.  
  2937.  
  2938.  
  2939.  
  2940.  
  2941.  
  2942.  
  2943.  
  2944.  
  2945.  
  2946.  
  2947.  
  2948.  
  2949.  
  2950.  
  2951.  
  2952.  
  2953.  
  2954.  
  2955.  
  2956.  
  2957.  
  2958.  
  2959.  
  2960.  
  2961.  
  2962.  
  2963.  
  2964.  
  2965.  
  2966.  
  2967.  
  2968.  
  2969.  
  2970.  
  2971.