Linux 软raid设置方法
2007-04-28 10:23
531 查看
from:
http://www.flmnh.ufl.edu/linux/linux_software_raid.htmSetting 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.
When you get to the Disk Partitioning Setup screen, select:
Manually partition with Disk Druid
![](http://www.flmnh.ufl.edu/linux/images/screenshot_setup_disk_druid1.png)
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.
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.
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.
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.
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.
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
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
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.
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/mdstat Personalities : [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/sda1 mdadm: set /dev/sda1 faulty in /dev/md0
A failed drive looks like this:
# cat /proc/mdstat Personalities : [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/sda1 mdadm: 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/sda1 mdadm: hot added /dev/sda1 # cat /proc/mdstat Personalities : [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/sec unused devices:
LVM on top of Linux Software RAID (coming in the future!)
* * * This section is under construction. * * *相关文章推荐
- Linux设置固定IP上网方法
- Linux多线程锁属性设置方法
- Linux下mysql新建账号及权限设置方法
- 解决SecureCRT中文乱码解决方法--字符集设置(Linux环境)
- 在Linux里设置环境变量的方法(export PATH)
- 在 Linux 里设置环境变量的方法( export PATH )
- linux 环境变量设置方法总结
- 在Linux里设置环境变量的方法
- linux重新设置mysql密码方法
- linux 下设置环境变量PATH的方法
- 在Linux里设置环境变量的方法(export PATH)
- Linux下设置环境变量的三种方法
- Linux操作系统下设置环境变量Path的方法
- Linux下设置环境变量PATH的方法
- Linux将服务设置为开机自启动的方法小结
- 虚拟机安装linux后 分辨率设置方法
- linux下设置vi编辑器的行号,方法汇总
- Linux操作系统下Flash插件安装设置方法
- 设置Linux环境变量的三种方法
- 怎么设置Linux swap分区?方法教程