home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Edition 1: Linux / CD1.iso / doc / HOWTO / mini / Software-RAID < prev    next >
Text File  |  1998-10-14  |  104KB  |  2,905 lines

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