參考網頁:
Setup RAID Level 6 (Striping with Double Distributed Parity) in Linux – Part 5
OS:Debian Linux 5.8.0
HDD:
10G*1 Debian Linux System
20G *5 (/dev/sdb,sdc,sdd,sde,sdf)
1. 檢視目前的 RAID 狀態
# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Jun 28 10:25:06 2016
Raid Level : raid6
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Tue Jun 28 10:39:54 2016
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Name : debian:0 (local to host debian)
UUID : 8f039d29:9179c09a:17a76417:e54c9dfa
Events : 27
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
2 8 49 2 active sync /dev/sdd1
3 8 65 3 active sync /dev/sde1[@more@]2. 建立 /dev/sdf 磁碟分割區
# fdisk /dev/sdf
Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x8d30e7ab.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): 按二下 Enter 鍵
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039):
Created a new partition 1 of type ‘Linux’ and of size 20 GiB.
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition ‘Linux’ to ‘Linux raid autodetect’.
Command (m for help): wq
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
3. 將 /dev/sdf1 加入到 /dev/md0 中
# mdadm –add /dev/md0 /dev/sdf1
mdadm: added /dev/sdf1
4. 檢視目前的 RAID 狀態,多了一顆 Spare Devices
# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Jun 28 10:25:06 2016
Raid Level : raid6
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 4
Total Devices : 5
Persistence : Superblock is persistent
Update Time : Tue Jun 28 10:44:37 2016
State : clean
Active Devices : 4
Working Devices : 5
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Name : debian:0 (local to host debian)
UUID : 8f039d29:9179c09a:17a76417:e54c9dfa
Events : 28
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
2 8 49 2 active sync /dev/sdd1
3 8 65 3 active sync /dev/sde1
4 8 81 – spare /dev/sdf1
5. 模擬 /dev/sdd1 故障
# mdadm –manage –fail /dev/md0 /dev/sdd1
# mdadm –manage –set-faulty/dev/md0 /dev/sdd1
mdadm: set /dev/sdd1 faulty in /dev/md0
6. 檢查目前的 RAID 狀態,RAID 系統會自動讓 /dev/sdf1 產生作用
# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Jun 28 10:25:06 2016
Raid Level : raid6
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 4
Total Devices : 5
Persistence : Superblock is persistent
Update Time : Tue Jun 28 10:47:46 2016
State : clean, degraded, recovering
Active Devices : 3
Working Devices : 4
Failed Devices : 1
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Rebuild Status : 35% complete
Name : debian:0 (local to host debian)
UUID : 8f039d29:9179c09a:17a76417:e54c9dfa
Events : 35
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
4 8 81 2 spare rebuilding /dev/sdf1
3 8 65 3 active sync /dev/sde1
2 8 49 – faulty /dev/sdd1
# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid6 sdf1[4] sdb1[0] sde1[3] sdd1[2](F) sdc1[1]
41908224 blocks super 1.2 level 6, 512k chunk, algorithm 2 [4/3] [UU_U]
[================>….] recovery = 80.8% (16943104/20954112) finish=0.4min speed=161494K/sec
unused devices: <none>
7. 將故障的硬碟移出
# mdadm –manage –remove /dev/md0 /dev/sdd1
mdadm: hot removed /dev/sdd1 from /dev/md0
# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid6 sdf1[4] sdb1[0] sde1[3] sdc1[1]
41908224 blocks super 1.2 level 6, 512k chunk, algorithm 2 [4/4] [UUUU]
unused devices: <none>
8.也可以直接在建立 RAID 時直接指定
# mdadm –create –verbose /dev/md0 –level=6 –raid-devices=4 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 -x 1 /dev/sdf1