LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 517|回复: 0

Gentoo Raid Installation and other sundry ways to wack your box by G.Tiller(转

[复制链接]
发表于 2005-5-29 10:19:54 | 显示全部楼层 |阅读模式
  1. Version 0.1
  2. 02/08/2004 - G.Tiller

  3. Version 0.2
  4. 02/09/2004 - G.Tiller


  5. Gentoo Raid Installation and other sundry ways to wack your box by G.Tiller

  6. This documentation is free for all to read and use. If something's wrong please
  7. feel free to correct it. I am not the best typist this side of Stone Mountain.
  8. I had a spare server and some old WD 4.3 GB drives around so I thought I would
  9. venture down this road for awhile.



  10. Gentoo Linux Installation with Raid Installation Using Raidtools.

  11. If you haven't gotten a copy of O'reilly's book Managing Raid On Linux I would
  12. suggest you get one as it has a lot of information about Raid. You should also
  13. check out the Raid information at The Linux Documentation Project. The HOWTO's
  14. have information pertaining to booting raid using lilo.


  15. Step # 1.)  Install Identical hard drives on your IDE controllers. One hard
  16.             drive on each controller is the preferred method. Here is my
  17.             configuration:

  18.             IDE0 - First hard drive
  19.             IDE1 -  CD drive
  20.             IDE2 -  Second hard drive  ( Port 1 of Promise Technologies
  21.                                          Ultra100 TX2 )
  22.             IDE3 -  Third hard drive   ( Port 2 of Promise controller )

  23.             Note: Identical hard drive will eliminate some of the problems
  24.             that may occur if you use disks of different sizes and geometries.

  25. Step # 2.) Boot from the Gentoo LiveCD.

  26. Step # 3.) Partition the hard disks. My partition layout is below.

  27.            I used WD 4.3 GB Drives in my test server.

  28.            /dev/hda1        128MB     bootable  partition type -  fd
  29.            /dev/hda2    256MB               partition type -  82 ( swap)
  30.            /dev/hda3    1024MB              partition type -  fd
  31.            /dev/hda4    remainder           partition type -  fd

  32.            The other 2 hard drives were partitioned the same.

  33. Step # 4.) Load the kernel raid modules you intend to use.

  34.            Modprobe raid0 raid1 raid5

  35. Step # 5.) Create the raidtab file. The raidtab file must reside in /etc.

  36.            My raidtab file:

  37.               raiddev /dev/md0
  38.                       raid-level                1
  39.                       nr-raid-disks                2
  40.                       nr-spare-disks                1
  41.                       persistent-superblock        1
  42.                       chunk-size                4
  43.                       device                        /dev/hda1
  44.                       raid-disk                        0
  45.                       device                        /dev/hde1
  46.                       raid-disk                        1
  47.                       device                        /dev/hdg1
  48.                       spare-disk                0


  49.               raiddev /dev/md1
  50.                       raid-level                1
  51.                       nr-raid-disks                2
  52.                       nr-spare-disks                1
  53.                       persistent-superblock        1
  54.                       chunk-size                4
  55.                       device                        /dev/hda2
  56.                       raid-disk                        0
  57.                       device                        /dev/hde2
  58.                       raid-disk                        1
  59.                       device                        /dev/hdg2
  60.                       spare-disk                0

  61.               raiddev /dev/md2
  62.                       raid-level                5
  63.                       nr-raid-disks                3
  64.                       nr-spare-disks                0
  65.                       persistent-superblock        1
  66.                       parity-algorithm                left-symmetric
  67.                       chunk-size                32
  68.                       device                        /dev/hda3
  69.                       raid-disk                        0
  70.                       device                        /dev/hde3
  71.                       raid-disk                        1
  72.                       device                        /dev/hdg3
  73.                       raid-disk                        2

  74.               raiddev /dev/md3
  75.                       raid-level                1
  76.                       nr-raid-disks                2
  77.                       nr-spare-disks                1
  78.                       persistent-superblock        1
  79.                       chunk-size                4
  80.                       device                        /dev/hda4
  81.                       raid-disk                        0
  82.                       device                        /dev/hde4
  83.                       raid-disk                        1
  84.                       device                        /dev/hdg4
  85.                       spare-disk                0






  86. Step # 6.) Create the raid arrays

  87.            mkraid /dev/md0 /dev/md1 /dev/md2 /dev/md3

  88.            This may take awhile depending on the size of your partitions.

  89.            Check /proc/mdstat to see the progress of the arrays.

  90.            cat /proc/mdstat  - this will show active arrays and those
  91.                                being built with a estimated finish time.

  92. Step # 8.)  Install Gentoo using the normal installation instructions except
  93.             use /dev/md(x) instead of using the actual hard disk device. I did
  94.             not replicate the Gentoo Installation instructions in these
  95.             instructions so be careful to not use this as a complete
  96.             installation procedure. I just referenced parts of the relevant
  97.             sections.


  98.              Installation Section 4.i. Creating Filesystems

  99.              Create your filesystems as you desire. I used ext3.

  100.              mkfs.ext3 /dev/md0
  101.              mkswap /dev/md1
  102.              mkfs.ext3 /dev/md2
  103.              mkfs.ext3 /dev/md3

  104.              swapon /dev/md1     ( swap doesn?t really need to be raided, if
  105.                                    you choose not to then you will need
  106.                                    multiple swap entries in your fstab file. )

  107.             Installation Section 4.j. Mounting

  108.              mount /dev/md3 /mnt/gentoo
  109.              mkdir /mnt/gentoo/boot
  110.              mount /dev/md0 /mnt/gentoo/boot

  111.             Install Section 6.a. Chrooting

  112.               copy your raidtab file from /etc to /mnt/gentoo/etc

  113.               You must also bind the /dev directory to /mnt/gentoo/dev even
  114.               though you are using the LiveCD version. This is so that the
  115.               bootloader can find the raid devices as they are not part of the
  116.               stage-3 tarball.

  117.               mount -o bind /dev /mnt/gentoo/dev


  118.         Configureing the Kernel

  119.         Installation Section 7.c Default: Manual configuration

  120.         I used the manual method of configuring and installing the kernel due
  121.         to problems I encountered using the latest genkernel program. Also I am
  122.         not using initrd when booting the kernel.

  123.         Be sure and configure the Raid options to compile into the kernel and
  124.         not as modules. This is necessary for the kernel to boot and load
  125.         properly from RAID. If you use modules for your RAID you must use
  126.         initrd to boot and mount root.


  127.         Installation Section 8.a Filesystem Information

  128.         Edit /etc/fstab and change the partition information to reflect the
  129.         raid arrays.

  130.                 for example  /dev/BOOT change to /dev/md0
  131.                              /dev/ROOT change to /dev/md3
  132.                              /dev/SWAP change to /dev/md1

  133.                 also be sure to set your  to the proper filesystem type.

  134.         Installation Section 9.c Using LILO

  135.         Get the latest version of lilo ( emerge lilo )  This insures you have
  136.         the latest fixes and updates to LILO.

  137.         Create a lilo.conf file in /etc.

  138.         This information was taken from Boot+Root+Raid+Lilo HOWTO documentation
  139.         found at the Linux Documentation Project, [url]www.tldp.org[/url].



  140.            My lilo.conf file for example:

  141.                 # Start of Gentoo Linux Raid Configuration

  142.                 disk=/dev/md3
  143.                 bios=0x80
  144.                 sectors=63
  145.                 heads=255
  146.                 cylinders=523
  147.                 partition=/dev/md0
  148.                 start=63
  149.                 boot=/dev/hda
  150.                 map=/boot/map
  151.                 install=/boot/boot.b

  152.                 # optional parameters - your choice
  153.                 prompt
  154.                 timeout=300
  155.                 vga=791
  156.                 # End of optional parameters

  157.                 # Kernel Configuration
  158.                 image=/boot/kernel-2.4.20-gentoo-r5
  159.                         root=/dev/md3
  160.                         read-only
  161.                         label=Gentoo
  162.                         append="hdc=ide-scsi"

  163.         The HOWTO documentation shows a second set of lilo entries for the
  164.         second boot drive but I can?t get it to work. Lilo complains of syntax
  165.         errors when you define those entries twice in lilo.conf. I don't know
  166.         enough about lilo to tell whether or not is is supposed to allow you to
  167.         specify two boot devices.

  168.         However, I was able to use the example lilo.conf file located in
  169.         "/usr/doc/lilo-22.5.8-r1" to construct a new lilo.conf that does not
  170.         complain.

  171.         My new lilo.conf is as follows:

  172.              # ---------- Start of Lilo Configuration ---------- #

  173.              # --- Boot Array --- #
  174.              boot=/dev/md0

  175.              # --- Auxillary Boot records for a parrallel raid array --- #
  176.              raid-extra-boot=auto

  177.              # --- Disks to boot from ---#
  178.              disk=/dev/hda
  179.                 bios=0x80   # --- first  disk on ide0 --- #
  180.              disk=/dev/hde
  181.                 bios=0x82   # --- first disk on ide2 --- #

  182.              # --- Wait for the user to choose and set the display mode --- #
  183.              prompt
  184.                 timeout=300
  185.                 vga=791

  186.              # --- Use the Menu interface , lilo > 22.3 --- #
  187.              install=menu
  188.                 menu-title="Gentoo Linux Raid Configuration"
  189.                 menu-scheme="wk:Wg:wk:Gk"

  190.              # --- Set the Default to Boot --- #
  191.              default=Gentoo

  192.              # --- Both kernels use the same root array --- #
  193.              root=/dev/md3
  194.                 read-only

  195.              # --- Kernel Image to boot --- #
  196.              image=/boot/kernel-2.4.22-r5
  197.                 label=Gentoo
  198.                 append="reboot=warm hdc=ide-scsi"

  199.              # ---------- End of Lilo Configuration --------- #

  200.         Be sure and emerge raidtools and emerge mdadm otherwise your raid
  201.         arrays will not be started.

  202.         Follow the rest of the Installation manual as you desire and then
  203.         reboot.

  204.         This procedure worked well for me.











  205. Gentoo Linux Installation with Raid Installation using Mdadm Raid Tools.

  206. Step # 1.)  Install Identical hard drives on your IDE controllers. One hard
  207.             drive on each controller is the preferred method. Here is my
  208.             configuration:

  209.                IDE0 - First hard drive
  210.                IDE1 -  CD drive
  211.                IDE2 -  Second hard drive  ( Port 1 of Promise Technologies
  212.                                             Ultra100 TX2 )
  213.                IDE3 -  Third hard drive   ( Port 2 of Promise controller )

  214.             Note: Identical hard drive will eliminate some of the problems
  215.                   that may occur if you use disks of different sizes and
  216.                   geometries.

  217. Step # 2.) Boot from the Gentoo LiveCD.

  218. Step # 3.) Partition the hard disks. My partition layout is below.

  219.               I used WD 4.3 GB Drives in my test server.

  220.               /dev/hda1        128MB     bootable  partition type -  fd
  221.               /dev/hda2 256MB               partition type -  82 ( swap)
  222.               /dev/hda3 1024MB              partition type -  fd
  223.               /dev/hda4 remainder           partition type -  fd

  224.               The other 2 hard drives were partitioned the same.

  225. Step # 4.) Load the kernel raid modules you intend to use.

  226.               Modprobe raid0 raid1 raid5

  227. Step # 5.) Begin creating your raid arrays with mdadm:

  228.               CREATE A RAID1 ARRAY

  229.               mdadm --create /dev/md0 --level=1 --raid-disks=2 /dev/hda1 \
  230.                     /dev/hde1 --spare-disks=1 /dev/hdg1

  231.               or use this command:

  232.               mdadm -C /dev/md0 -l1 -n2 /dev/hda1 /dev/hde1 -x1 /dev/hdg1


  233.               CREATE A RAID1 ARRAY

  234.               mdadm --create /dev/md1 --level=1 --?raid-disks=2 /dev/hda2 \
  235.                     /dev/hde2 --spare-disks=1 /dev/hdg2

  236.               or use this command:

  237.               mdadm -C /dev/md1 -l1 -n2 /dev/hda2 /dev/hde2 -x1 /dev/hdg2


  238.               CREATE A RAID5 ARRAY

  239.               mdadm --create /dev/md2 --level=5 --parity=left-symmetric \
  240.                     --raid-disks=3 /dev/hda3 /dev/hde3 /dev/hdg3

  241.               or use this command:

  242.               mdadm -C /dev/md2 -l5 -pls -n3 /dev/hda1 /dev/hde1 /dev/hdg1


  243.               CREATE A RAID1 ARRAY

  244.               mdadm --create /dev/md3 --level=1 --raid-disks=2 /dev/hda4 \
  245.                     /dev/hde4 --spare-disks=1 /dev/hdg4

  246.               or use this command:

  247.               mdadm -C /dev/md3 -l1 -n2 /dev/hda4 /dev/hde4 -x1 /dev/hdg4


  248.              This may take awhile depending on the size of your partitions.

  249.              Check /proc/mdstat to see the progress of the arrays.

  250.              cat /proc/mdstat  - this will show active arrays and those being
  251.                                  built with a estimated finish time.

  252. Step # 6.)  Assembling / Starting your Arrays.

  253.             You must next assemble the arrays. ( This is equivalent to using
  254.             the raidstart command from the raidtools set of programs. This
  255.             command madm --assemble utilizes a configuration file
  256.             "/etc/mdadm.conf" to determine which arrays and disks to start.
  257.             After creating my arrays I noticed that I did not need to assemble
  258.             them. They were already  started by the create command. The
  259.             O'reilly book did not say this would happen when creating the
  260.             arrays but I suppose this is ok and that the mdadm --assemble
  261.             command is used to start the arrays at boot time.
  262.       

  263.             Create or add entries to your mdadm.conf file. See the example
  264.             below.


  265.                 DEVICE        /dev/hda1 /dev/hde1 /dev/hdg1
  266.                 ARRAY        /dev/md0 level=1 num-devices=2 \
  267.                         devices=/dev/hda1,/dev/hde1,/dev/hdg1

  268.                 DEVICE        /dev/hda2 /dev/hde2 /dev/hdg2
  269.                 ARRAY        /dev/md1 level=1 num-devices=2 \
  270.                         devices=/dev/hda2,/dev/hde2,/dev/hdg2

  271.                 DEVICE        /dev/hda3 /dev/hde3 /dev/hdg3
  272.                 ARRAY        /dev/md2 level=5 num-devices=3 \
  273.                         devices=/dev/hda3,/dev/hde3,/dev/hdg3

  274.                 DEVICE        /dev/hda4 /dev/hde4 /dev/hdg4
  275.                 ARRAY        /dev/md3 level=1 num-devices=2 \
  276.                         devices=/dev/hda4,/dev/hde4,/dev/hdg4

  277.                 MAILADDR=root@yourdomain.XXX

  278.             The commands below will assemble the arrays and start them.

  279.             mdadm --assemble --scan /dev/md0
  280.             mdadm --assemble --scan /dev/md1
  281.             mdadm --assemble --scan /dev/md2
  282.             mdadm --assemble --scan /dev/md3


  283. Step # 7.)  Install Gentoo using the normal installation instructions except
  284.             use /dev/md(x) instead of using the actual hard disk device. I did
  285.             not replicate the Gentoo Installation instructions in these
  286.             instructions so be careful to not use this as a complete
  287.             installation procedure. I just referenced parts of the relevant
  288.             sections.

  289.             Installation Section 4.i. Creating Filesystems

  290.             Create your filesystems as you desire. I used ext3.

  291.              mkfs.ext3 /dev/md0
  292.              mkswap /dev/md1
  293.              mkfs.ext3 /dev/md2
  294.              mkfs.ext3 /dev/md3

  295.              swapon /dev/md1     ( swap doesn't really need to be raided,
  296.                                    if you choose not to then you will need
  297.                                    multiple swap entries in your fstab file. )


  298.             Installation Section 4.j. Mounting

  299.              mount /dev/md3 /mnt/gentoo
  300.              mkdir /mnt/gentoo/boot
  301.              mount /dev/md0 /mnt/gentoo/boot

  302.             Install Section 6.a. Chrooting

  303.               copy your mdadm.conf file from /etc to /mnt/gentoo/etc

  304.             You must also bind the /dev directory to /mnt/gentoo/dev even
  305.             though you are using the LiveCD version. This is so that the
  306.             bootloader can find the raid devices as they are not part of the
  307.             stage-3 tarball.

  308.                   mount -o bind /dev /mnt/gentoo/dev


  309.           Configureing the Kernel

  310.           Installation Section 7.c Default: Manual configuration

  311.           I used the manual method of configuring and install ing the kernel
  312.           due to problems I encountered using the latest genkernel program.
  313.           Also I am not using initrd when booting the kernel.

  314.           Be sure and configure the Raid options to compile into the kernel
  315.           and not as modules. This is necessary for the kernel to boot and
  316.           load properly from RAID. If you use modules for your RAID you must
  317.           use initrd to boot and mount root.


  318.           Installation Section 8.a Filesystem Information

  319.           Edit /etc/fstab and change the partition information to reflect the
  320.           raid arrays.

  321.                 for example  /dev/BOOT change to /dev/md0
  322.                              /dev/ROOT change to /dev/md3
  323.                              /dev/SWAP change to /dev/md1

  324.                 also be sure to set your  to the proper filesystem type.




  325.            Installation Section 9.c Using LILO

  326.            Get the latest version of lilo ( emerge lilo )  This insures you
  327.            have the latest fixes and updates to LILO.

  328.                    Create a lilo.conf file in /etc.

  329.           This information was taken from Boot+Root+Raid+Lilo HOWTO
  330.           documentation found at the Linux Documentation Project, [url]www.tldp.org[/url].
  331.        
  332.                 My lilo.conf file for example:

  333.                  # Start of Gentoo Linux Raid Configuration

  334.                 disk=/dev/md3
  335.                 bios=0x80
  336.                 sectors=63
  337.                 heads=255
  338.                 cylinders=523
  339.                 partition=/dev/md0
  340.                 start=63
  341.                 boot=/dev/hda
  342.                 map=/boot/map
  343.                 install=/boot/boot.b

  344.                 # optional parameters - your choice
  345.                 prompt
  346.                 timeout=300
  347.                 vga=791
  348.                 # End of optional parameters

  349.                 # Kernel Configuration
  350.                 image=/boot/kernel-2.4.20-gentoo-r5
  351.                       root=/dev/md3
  352.                       read-only
  353.                       label=Gentoo
  354.                       append="hdc=ide-scsi"

  355.         The HOWTO shows a second set of lilo entries for the second boot drive
  356.         but I can't get it to work.  Lilo complains of syntax errors when you
  357.         define those entries twice in lilo.conf. I don't know enough about lilo
  358.         to tell whether or not is is supposed to allow you to specify two boot
  359.         devices.

  360.         However, I was able to use the example lilo.conf file located in
  361.         "/usr/doc/lilo-22.5.8-r1" to construct a new lilo.conf that does not
  362.         complain .

  363.         My new lilo.conf is as follows:

  364.              # ---------- Start of Lilo Configuration ---------- #

  365.              # --- Boot Array --- #
  366.              boot=/dev/md0

  367.              # --- Auxillary Boot records for a parrallel raid array --- #
  368.              raid-extra-boot=auto

  369.              # --- Disks to boot from ---#
  370.              disk=/dev/hda
  371.                 bios=0x80   # --- first  disk on ide0 --- #
  372.              disk=/dev/hde
  373.                 bios=0x82   # --- first disk on ide2 --- #

  374.              # --- Wait for the user to choose and set the display mode --- #
  375.              prompt
  376.                 timeout=300
  377.                 vga=791

  378.              # --- Use the Menu interface , lilo > 22.3 --- #
  379.              install=menu
  380.                 menu-title="Gentoo Linux Raid Configuration"
  381.                 menu-scheme="wk:Wg:wk:Gk"

  382.              # --- Set the Default to Boot --- #
  383.              default=Gentoo

  384.              # --- Both kernels use the same root array --- #
  385.              root=/dev/md3
  386.                 read-only

  387.              # --- Kernel Image to boot --- #
  388.              image=/boot/kernel-2.4.22-r5
  389.                 label=Gentoo
  390.                 append="reboot=warm hdc=ide-scsi"

  391.              # ---------- End of Lilo Configuration --------- #

  392.         Be sure and emerge raidtools and emerge mdadm otherwise your raid
  393.         arrays may not be started.

  394.         Follow the rest of the Installation manual as you desire but be sure
  395.         to edit the file "/etc/init.d/checkfs". This script has to be modified
  396.         to include the mdadm command necessary to start the raid array for swap
  397.         and any other arrays that are not set to auto.

  398.         These are the changes I made to "/etc/init.d/checkfs"

  399.         line # 41 change this: if [ -f /proc/mdstat -a -f /etc/raidtab ]
  400.             to: if [ -f /proc/mdstat -a -f /etc/raidtab -o -f /etc/mdadm.conf ]

  401.         line # 48 add this:  if [ -f /etc/raidtab ]
  402.                               then

  403.         line # 105 add the following:   elif [ -f /etc/mdadm.conf ]
  404.                                         then
  405.                                                 mdadm ?As
  406.                                                 retval=$?
  407.                                         fi
  408.                                         if [ ?${retval}? ?gt 0 ]
  409.                                         then
  410.                                                 rc=1
  411.                                                 eend${retval}
  412.                                         else
  413.                                                 ewend ${retval}
  414.                                         fi

  415.         Follow the final instructions in the Installation manual to perform
  416.         your reboot.

  417.         This procedure worked well for me.


  418. Now for some test scenarios.

  419.         Server Configuration

  420.         MB - ASUS A7N8X
  421.         RAM - 512 M
  422.         Video - Geforce MX-400 with 64M
  423.         Disk Drives - 3 Western Digital 4.3 GB ata-33
  424.         CDROM - HP 8200+ cdrw

  425.        Test # 1 - Server is booted up and running normally. This test is to
  426.                    fail the primary boot drive "/dev/hda". ( pulling the
  427.                                                              power plug )

  428.         Note:  I do not recommend doing this to achieve hot-swappability as
  429.                this could cause severe damage to your MB or Drives.

  430.        Result:  Server still up and running, raid-device 0 of all arrays
  431.                 marked as faulty. Reconstruction begun using spare drive.
  432.                 After reconstruction mdadm --detail shows the faulty
  433.                 raid-device to be 2 and the spare is now active as raid-device0.

  434.        Test # 2 - Rebooting server with a failed primary boot drive,
  435.                  "/dev/had". This test is to determine if the alternate boot
  436.                  strategy works as indicated with lilo.

  437.        Result:  Reboot with a failed "/dev/had" was successful. Server booted
  438.                 off of "/dev/hde" which was marked a HDD-2 in the bios since
  439.                 it is on the Promise controller.

  440.        Test # 3 - Reinsertion of raid-device 0 ( "/dev/hda" ) into the live
  441.                   system. I do not recommend reinserting a drive into the live
  442.                   system.  Your hardware could suffer severe damage.

  443.        Result:  System is still up and running. (I put the power plug back in).
  444.                 The disk is not recognized by the system. The device "/dev/hda"
  445.                 no longer exists in the /dev directory.

  446.                 System must be rebooted in order for the missing drive to be
  447.                 add back into the /dev directory. ( there may be a way to do
  448.                 this without rebooting but I don't know how to make the active
  449.                 system detect the drive without doing a reboot.)

  450.                 After the reboot you must hot-add the drive back into your
  451.                 arrays.

  452.                         mdadm -a /dev/md0 /dev/hda1
  453.                         mdadm -a /dev/md1 /dev/hda2
  454.                         mdadm -a /dev/md2 /dev/hda3
  455.                         mdadm -a /dev/md3 /dev/hda4

  456.                 This will invoke reconstruction of the newly added drive.
  457.                 Under raid1 the newly added drive becomes the spare if you had
  458.                 originally configured your arrays with a spare drive.

  459.                 Under raid5 the newly added drive is again made an active part
  460.                 of the array.

  461.         You should also set up a way to monitor your arrays and have it alert
  462.         you to problems. You can use the "mdadm --monitor --scan" command to
  463.         alert you through email or some external alerting program.

  464.         While these tests are not very detailed ( and not necessarily a very
  465.         smart way of testing ), they do show that the raid scenario that I
  466.         built does seem to work properly. There are different raid
  467.         configurations possible as well as other types of failures that can
  468.         happen that I don?t have the hardware resources to try or the burning
  469.         desire to destroy my motherboards and drives.
  470.       
  471.         As with everything your mileage may vary.
复制代码


http://www.fatofthelan.com/articles/articles.php?pid=19
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表