[root@mylab ~]# fdisk -l /dev/sdb
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
/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@mylab ~]# mdadm -C /dev/md0 -l5 -n3 -x1 /dev/sdb[5-8]
mdadm: array /dev/md0 started.
[root@mylab ~]# echo DEVICE /dev/sdb[5-8] > /etc/mdadm.conf
[root@mylab ~]# mdadm -Ds >> /etc/mdadm.conf
[root@mylab ~]# mdadm -D /dev/md0 >> /etc/mdadm.conf
[root@mylab ~]# mdadm -S /dev/md0
mdadm: stopped /dev/md0
[root@mylab ~]# mdadm -A /dev/md0
mdadm: /dev/md0 not identified in config file.
[root@mylab ~]# mv /etc/mdadm.conf.old /etc/mdadm.conf
[root@mylab ~]# mdadm -A /dev/md0
mdadm: /dev/md0 has been started with 3 drives and 1 spare.
4,查看raid状态
[root@mylab ~]# 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>
mdadm: Unknown keyword /dev/md0:
mdadm: Unknown keyword Preferred
mdadm: Unknown keyword Working
以上三行的错误是因为在建立配置文件时使用了mdadm -D /dev/md0 >>/etc/mdadm.conf,如果不使用就不会有错误,使用的目的是为了更清楚最开始的raid配置
[root@mylab ~]# 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
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Chunk Size : 64K
Events : 0.2
0 8 21 0 active sync /dev/sdb5
1 8 22 1 active sync /dev/sdb6
2 8 23 2 active sync /dev/sdb7
6,停止阵列
[root@mylab ~]# mdadm -S /dev/md0
mdadm: stopped /dev/md0
[root@mylab ~]# mdadm -A /dev/md0
mdadm: /dev/md0 has been started with 3 drives and 1 spare.
8,将/dev/sdb5设为故障盘并移除
[root@mylab ~]# mdadm /dev/md0 –fail /dev/sdb5 –remove /dev/sdb5
mdadm: set /dev/sdb5 faulty in /dev/md0
mdadm: hot removed /dev/sdb5
[root@mylab ~]# mdadm -D /dev/md0
……………
Number Major Minor RaidDevice State
0 8 24 0 active sync /dev/sdb8
1 8 22 1 active sync /dev/sdb6
2 8 23 2 active sync /dev/sdb7
10,将/dev/sdb5加入阵列,自动变为热备盘
[root@mylab ~]# mdadm /dev/md0 –add /dev/sdb5
mdadm: added /dev/sdb5
[root@mylab ~]# mdadm -D /dev/md0
Number Major Minor RaidDevice State
0 8 24 0 active sync /dev/sdb8
1 8 22 1 active sync /dev/sdb6
2 8 23 2 active sync /dev/sdb7
-a, –auto{=no,yes,md,mdp,part,p}{NN}: