Linux 软raid设置方法

来源:互联网 发布:hp清零软件 编辑:程序博客网 时间:2024/06/07 02:02

from:

http://www.flmnh.ufl.edu/linux/linux_software_raid.htm

Setting up Linux Software RAID on CentOS

* * RAID is not a substitute for data backups! Always backup your data! * * </>

This document describes how to configure your system for Software RAID1 (mirroring) during the CentOS 4.x clean install. We will mirror data between two hard drives to prevent data loss in the event of a single hard drive failure.

The first section shows how to do a basic setup without LVM. The second section shows how to do LVM on top of software RAID.

Software RAID setup during CentOS installation

For this procedure, we will go with a somewhat simplified setup that includes a single root filesytem and a swap partition. This is similar to the disk layout of a CentOS Automatic partitioning scheme.

Steps 3 and 4 (below) will create the device that will hold the root filesystem.
Steps 5 and 6 (below) will create the swap partition.

Note: This document uses sda/sdb as the hard drive device names. On most GNU/Linux systems this will be true for SCSI or SATA drives. PATA IDE drives will be named hda/hdb.
  1. When you get to the Disk Partitioning Setup screen, select:
    Manually partition with Disk Druid

    Disk Partitioning Setup Screen
  2. Highlight and Delete each partition, Logical Volume, and Volume Group until all of the existing partitions have been removed. When finished you should only have "Free Space" in the Type column.

  3. Add the first Software RAID member by clicking the "New" button.
    - Select File System Type = software RAID
    - uncheck the Allowable Drives until only the first hard drive is selected (probably sda)
    - enter the size in MB. Must leave enough space for Swap partition (1000 MB), and probably want to leave a little fudge factor in case a replacment drive is not quite the same size. For example, an "80 GB" drive might actually have 76000 MB, but a future replacement drive from a different vendor might only have 75000 MB, so we create a software RAID partition of 73000 MB.
    - check the box "Force to be a primary partition" because this helps Disk Druid remember to keep the root volume at the front of the hard drive.

  4. Add the second Software RAID member by clicking the "New" button.
    - Select File System Type = software RAID
    - uncheck the Allowable Drives until only the second hard drive is selected (probably sdb)
    - enter the size in MB. This should be the same size as entered in step 3 above.
  5. Add the first Software RAID member that will be used as Swap partition by clicking the "New" button.
    - Select File System Type = software RAID
    - uncheck the Allowable Drives until only the first hard drive is selected (probably sda)
    - enter the size in MB. My rule of thumb is to create a swap partition that is "twice the size of the amount of RAM in the system" plus 512 MB. If I have 512 MB of RAM, my swap partition would be 1 GB.

  6. Add the second Software RAID member that will be used as Swap partition by clicking the "New" button.
    - Select File System Type = software RAID
    - uncheck the Allowable Drives until only the second hard drive is selected (probably sdb)
    - enter the size in MB. This should be the same size as entered in step 5 above.
  7. Create the first RAID device. Click the "RAID" button. Select "Create a RAID device [default=/dev/md0]."
      Mount Point:           /  File System Type:      ext3  RAID Device:           md0  RAID Level:            RAID1  RAID Members:          sda1, sdb1     (these are the members created in steps 3 and 4)  Number of spares:      0

  8. Create the second RAID device. Click the "RAID" button. Select "Create a RAID device [default=/dev/md1]."
      Mount Point:             File System Type:      swap  RAID Device:           md1  RAID Level:            RAID1  RAID Members:          sda2, sdb2     (these are the members created in steps 5 and 6)  Number of spares:      0

  9. Once the disks are formated and files are being copied from the CD, switch to a virtual console (CTRL-ALT-F1) to install grub on both disks. If you fail to do this, you will need to boot from the install disk and use rescue mode to make your system bootable.
    grub> device (hd0) /dev/sda> root (hd0,0)> setup (hd0)> device (hd1) /dev/sdb> root (hd1,0)> setup (hd1)

    This makes sure that the grub boot loader is installed on both physical drives and that the system will be bootable even if one of the drives fails.


  10. Done!

We have chosen to install linux in one big partition. Many people like to create smaller partitions (such as a separate partition for /usr). To do this, you would just need to create additional idential Software RAID members on each disk, and an additional RAID device.

Here is the finished setup:
# cat /proc/mdstatPersonalities : [raid1]md1 : active raid1 sdb2[1] sda2[0]      4297280 blocks [2/2] [UU]md0 : active raid1 sdb1[1] sda1[0]      235520832 blocks [2/2] [UU] unused devices: 

Failed Drives

In this case, we simulate a drive failure by forcing one of the software raid members into a failed state.
# mdadm /dev/md0 --fail /dev/sda1mdadm: set /dev/sda1 faulty in /dev/md0
A failed drive looks like this:
# cat /proc/mdstatPersonalities : [raid1]md1 : active raid1 sdb2[1] sda2[0]      4297280 blocks [2/2] [UU]md0 : active raid1 sdb1[1]      235520832 blocks [2/1] [_U] 
Get more info on the array by asking for details:
# mdadm --detail /dev/md0
We then remove the failed member from the array.
# mdadm /dev/md0 --remove /dev/sda1mdadm: hot removed /dev/sda1

After replacing the failed drive, you add a "hot spare" and the system will automatically rebuild the failed md device(s).

# mdadm /dev/md0 --add /dev/sda1mdadm: hot added /dev/sda1# cat /proc/mdstatPersonalities : [raid1]md1 : active raid1 sdb2[1] sda2[0]      4297280 blocks [2/2] [UU]md0 : active raid1 sda1[2] sdb1[1]      235520832 blocks [2/1] [_U]      [=>...................]  recovery =  6.4% (15183872/235520832)finish=79.6min speed=46101K/secunused devices: 

LVM on top of Linux Software RAID (coming in the future!)

* * * This section is under construction. * * *
 
原创粉丝点击