[[email protected] ~]#fdisk -l
...省略部分輸出...
Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xba384969
Device Boot Start End Blocks ld System
/dev/sdb1 1 2610 20964793+ 5 Extended
/dev/sdb5 1 262 2104452 83 Linux
/dev/sdb6 263 524 2104483+ 83 Linux
/dev/sdb7 525 786 2104483+ 83 Linux
/dev/sdb8 787 1048 2104483+ 83 Linux
[[email protected] ~]# mdadm [模式] [RAID裝置檔名] [選項]
模式:
[[email protected] ~]# mdadm -create -auto=yes /dev/md0-level=5
-raid-devices=3 -spare-devices=1 /dev/sdb5/dev/sdb6 /dev/sdb7 /dev/sdb8
[[email protected] ~]# mdadm --detail /dev/md0
/dev/md0:
#裝置檔名
Version : 1.2
Creation Time : Tue Apr 23 23:13:48 2013
#建立時間
Raid Level : raid5
#RAID 級別
Array Size : 4206592 (4.01 GiB 4.31 GB) +RAID #總容量
Used Dev Size : 2103296 (2.01 GiB 2.15 GB)
#每個分割區的容量
Raid Devices : 3
#組成 RAID 的裝置數
Total Devices : 4
#總裝置數
Persistence : Superblock is persistent
Update Time : Tue Apr 23 23:14:52 2013 State : clean
Active Devices : 3
#啟用的裝置數
Working Devices : 4
#可用的裝置數
Failed Devices : 0
#錯誤的裝置數
Spare Devices : 1
#備份裝置數
Layout : left-symmetric
Chunk Size : 512K
Name : localhost.localdomain:0 (local to host localhost.localdomain) UOID : 15026b78:126a4930:89d8cf54:5bcb7e95 Events : 18
Number Major Minor RaidDevice State
0 8 21 0 active sync /dev/sdb5
1 8 22 1 active sync /dev/sdb6
4 8 23 2 active sync /dev/sdb7
#三個啟用的分割區
3 8 24 - spare /dev/sdb8
#備份分割區
[[email protected] ~]# cat /proc/mdstat
Personalities:[raid6] [raid5] [raid4]
md0:active raid5 sdb9[4](S) sdb5[0] sdb8[3] sdb6[1]
#RAID名 級別 組成RAID的分割區,[數位]是此分割區在RAID中的順序
#(S)代表備份分割區
4206592 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
#總block數 等級是5 區塊大小 陣列演算法 [組成裝置數/正常裝置數]
unused devices: <none>
[[email protected] ~]# mkfs -t ext4 /dev/md0
掛載命令如下:
[[email protected] ~]# mkdir /raid
#建立掛載點
[[email protected] ~]# mount /dev/md0 /raid/
#掛載/dev/md0
[[email protected] ~]# mount
…省略部分輸出…
/dev/md0 on /raid type ext4(rw)
#檢視一下,已經正常掛載
[[email protected] ~]# echo Device /dev/sdb[5-8] >>/etc/mdadm.conf
#建立/etc/mdadm.conf設定立件,並把組成RAID的分割區的裝置檔名寫入
#注意:如果有多個RAID,則要把所有組成RAID的裝置都放入組態檔中;否則RAID裝置重新啟動後會丟失
#比如組成RAID 10,就既要把分割區的裝置檔名放入此檔案中,也翻組成RAID 0的RAID 1裝置檔名放入
[[email protected] ~]# mdadm -Ds >>/etc/mdadm.conf
#查詢和掃描RAID資訊,並追加進/etc/mdadm.conf檔案
[[email protected] ~]# cat /etc/mdadm.conf
Device /dev/sdb5 /dev/sdb6 /dev/sdb7 /dev/sdb8
ARRAY /dev/md0 metadata: 1.2 spares=1 name=l(xalhost.localdomain:0 UUID=dd821fe5:8597b126:460a3afd:857c7989
#檢視檔案內容
[[email protected] ~]# vi /etc/fstab
/dev/mdO /raid
ext4 defaults 12
#加入此行
[[email protected] ~]# mdadm -S /dev/md0
#停止/dev/md0裝置
[[email protected] ~]# umount /dev/md0
#解除安裝RAID
[[email protected] ~】# vi /etc/fstab
/dev/md0 /raid ext4 defaults 12
#刪除此行
[[email protected] ~]# mdadm -S /dev/md0
mdadm: stopped /dev/md0
#停止RAID
[[email protected] ~]# vi /etc/mdadm.conf
ARRAY /dev/md0 metadata: 1.2 spares=1 name=localhost.localdomain:0 UUID=dd821fe5:8597b126:460a3afd:857c7989
#刪除或者註釋此行
[[email protected] ~]# mdadm -As /dev/md0
mdadm: /dev/md0 has been started with 3 drives and 1 spare.
#啟動/dev/md0
[[email protected] ~]# mount /dev/md0 /raid/
#啟動RAID後,記得掛載
[[email protected] ~]# mdadm /dev/mdO -f /dev/sdb7 mdadm: set /dev/sdb7 faulty in /dev/mdO、
#模擬/dev/sdb7分割區報錯
[[email protected] ~】# mdadm -D /dev/mdO /dev/mdO:
...省略部分輸出...
Active Devices : 2
Working Devices : 3
Failed Devices : 1
#1個裝置報錯了
Spare Devices : 1
...省略部分輸出...
Number Major Minor RaidDevice State
0 8 21 0 active sync /dev/sdb5
1 8 22 1 active sync /dev/sdb6
3 8 24 2 spare rebuilding /dev/sdb8
#/dev/sdb8分割區正在準備修復
4 8 23 - faulty spare /dev/sdb7
#/dev/sdb7已經報錯了
[[email protected] ~]# mdadm /dev/mdO
Number Major Minor RaidDevice State
0 8 21 0 active sync /dev/sdb5
1 8 22 1 active sync /dev/sdb6
3 8 24 2 active sync /dev/sdb8
4 8 23 - faulty spare /dev/sdb7
[[email protected] ~]# mdadm /dev/md0
-remove/dev/sdb7
mdadm: hot removed /dev/sdb7 from /dev/mdO
[[email protected] ~]#fdisk -l
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 *512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes 1512 bytes
Disk identifier: 0x151a68a9
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 5 Extended
/dev/sdb5 1 262 2104452 83 Linux
/dev/sdb6 263 524 2104483+ 83 Linux
/dev/sdb7 525 786 2104483+ 83 Linux
/dev/sdb8 787 1048 2104483+ 83 Linux
/dev/sdb9 1049 1310 2104483+ 83 Linux
[[email protected] ~]# mdadm /dev/md0 -add /dev/sdb9
mdadm: added /dev/sdb9
#把/dev/sdb9加入/dev/md0
[[email protected] ~]# mdadm -D /dev/md0
...省略部分輸出...
Number Major Minor RaidDevice State
0 8 21 0 active sync /dev/sdb5
1 8 22 1 active sync /dev/sdb6
3 8 24 2 active sync /dev/sdb8
4 8 25 - spare /dev/sdb9
#檢視一下,/dev/sdb9已經變成了備份分割區