1,分区
[root@ ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 652 5237158+ 5 Extended
/dev/sdb5 1 13 104359+ fd Linux raid autodetect
/dev/sdb6 14 26 104391 fd Linux raid autodetect
/dev/sdb7 27 39 104391 fd Linux raid autodetect
/dev/sdb8 40 52 104391 fd Linux raid autodetect
2,创建阵列-C=–create -l5=–rail-level=5(raid级别) -n3=–raid-devices=3(阵列硬盘数量) -x1=–spare-devices=1(热备数量)
[root@ ~]# mdadm -C /dev/md0 -l5 -n3 -x1 /dev/sdb[5-8]
mdadm: array /dev/md0 started.
3,建立配置文件,如果没有配置文件,在停止raid后就无法再激活
[root@ ~]# echo DEVICE /dev/sdb[5-8] > /etc/mdadm.conf
[root@ ~]# mdadm -Ds >> /etc/mdadm.conf
[root@ ~]# mdadm -D /dev/md0 >> /etc/mdadm.conf
没有配置文件的测试
[root@ ~]# mv /etc/mdadm.conf /etc/mdadm.conf.old
[root@ ~]# mdadm -S /dev/md0
mdadm: stopped /dev/md0
[root@ ~]# mdadm -A /dev/md0
mdadm: /dev/md0 not identified in config file.
[root@ ~]# mv /etc/mdadm.conf.old /etc/mdadm.conf
[root@ ~]# mdadm -A /dev/md0
mdadm: /dev/md0 has been started with 3 drives and 1 spare.
4,查看raid状态
[root@ ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb7[2] sdb8[3](S) sdb6[1] sdb5[0]
208512 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>
5,更详细的查看-D=–detail
mdadm: Unknown keyword /dev/md0:
mdadm: Unknown keyword Preferred
mdadm: Unknown keyword Working
以上三行的错误是因为在建立配置文件时使用了mdadm -D /dev/md0 >>/etc/mdadm.conf,如果不使用就不会有错误,使用的目的是为了更清楚最开始的raid配置
[root@ ~]# mdadm -D /dev/md0
mdadm: Unknown keyword /dev/md0:
mdadm: Unknown keyword Preferred
mdadm: Unknown keyword Working
/dev/md0:
Version : 00.90.03
Creation Time : Sat May 2 01:33:45 2009
Raid Level : raid5
Array Size : 208512 (203.66 MiB 213.52 MB)
Used Dev Size : 104256 (101.83 MiB 106.76 MB)
Raid Devices : 3
Total Devices : 4
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Sat May 2 01:33:48 2009
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 64K
UUID : 8d90e341:23a2dbb0:35fc7278:73eac58d
Events : 0.2
Number Major Minor RaidDevice State
0 8 21 0 active sync /dev/sdb5
1 8 22 1 active sync /dev/sdb6
2 8 23 2 active sync /dev/sdb7
3 8 24 - spare /dev/sdb8