1 增加磁盘并分区(修改id)
fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 244 1959898+ fd Linux raid autodetect
/dev/sdb2 245 488 1959930 fd Linux raid autodetect
/dev/sdb3 489 732 1959930 fd Linux raid autodetect
/dev/sdb4 733 1044 2506140 fd Linux raid autodetect
2 创建raid
[root@gc1 md01]# which mdadm
/sbin/mdadm
3 查看raid的状态(我创建的是/dev/md02)
[root@gc1 md01]#mdadm -D /dev/md02
/dev/md02:
Version : 0.90
Creation Time : Wed Mar 25 14:39:01 2015
Raid Level : raid5
Array Size : 3919616 (3.74 GiB 4.01 GB)
Used Dev Size : 1959808 (1914.20 MiB 2006.84 MB)
Raid Devices : 3
Total Devices : 4
Preferred Minor : 2
Persistence : Superblock is persistent
Update Time : Wed Mar 25 14:43:35 2015
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 64K
UUID : d812a0b9:f7f9c5eb:4528a047:4b714fc2
Events : 0.2
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 18 1 active sync /dev/sdb2
2 8 19 2 active sync /dev/sdb3
3 8 20 - spare /dev/sdb4
4格式化并挂载/dev/md02
[root@gc1 md01]#mkfs.ext3 /dev/md02
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
[root@gc1 md01]# mkdir /md02
[root@gc1 md01]# mount /dev/md02 /md02
[root@gc1 md01]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
35G 7.8G 26G 24% /
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 760M 0 760M 0% /dev/shm
/dev/md01 3.7G 72M 3.5G 3% /md01
/dev/md02 3.7G 72M 3.5G 3% /md02
5 模拟故障
[root@gc1 md02]#mdadm -f /dev/md02 -f /dev/sdb2 ----模拟sdb2故障
mdadm: set /dev/sdb2 faulty in /dev/md02
[root@gc1 md02]# mdadm -D /dev/md02
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
3 8 20 1 spare rebuilding /dev/sdb4
2 8 19 2 active sync /dev/sdb3
4 8 18 - faulty spare /dev/sdb2
[root@gc1 md02]# mdadm /dev/md02 -r /dev/sdb2 ---将sdb2剔除
mdadm: hot removed /dev/sdb2
[root@gc1 md02]# mdadm -D /dev/md02
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
3 8 20 1 spare rebuilding /dev/sdb4 ---热备分区补上去了,,开始创建,估计要等一会会
2 8 19 2 active sync /dev/sdb3
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 20 1 active sync /dev/sdb4 ----过一会就变成active状态了
2 8 19 2 active sync /dev/sdb3
[root@gc1 md02]# ls ---数据依然没有丢失,raid5文件是故障前创建的一个
lost+found raid5
补充:
1 向一个已存在的raid中添加分区
[root@gc1 md02]#mdadm /dev/md02 -a /dev/sdb5
2我们单纯的使用-a命令不是只是将磁盘添加到了热备分区去了
[root@gc1 md02]# mdadm /dev/md02 -a /dev/sdb2 (sdb2前面已经被我们删除了)
[root@gc1 md02]# mdadm /dev/md2 -a /dev/sdc1 ---再加一块
[root@gc1 md02]# mdadm -D /dev/md02
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 20 1 active sync /dev/sdb4
2 8 19 2 active sync /dev/sdb3
3 8 18 - spare /dev/sdb2 ---添加到热备分区了
4 8 33 - spare /dev/sdc1
扩容
[root@gc1 md02]# mdadm -G /dev/md2 -n4 --这样就把sdc1扩容到raid成员中去了,此处02变成2是因为我不小心重启集机器了
mdadm: Need to backup 384K of critical section..
[root@gc1 md02]# mdadm -D /dev/md2
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 20 1 active sync /dev/sdb4
2 8 19 2 active sync /dev/sdb3
3 8 33 3 active sync /dev/sdc1
4 8 18 - spare /dev/sdb2