mdadm 用于建設,管理和監(jiān)控RAID陣列
用法:
mdadm --create device options...
用未使用的設備,創(chuàng)建raid選項,
mdadm --assemble device options...
合并先前創(chuàng)建的raid陣列。
mdadm --build device options...
創(chuàng)建或合并沒有元數據的一個raid。
mdadm --manage device options...
對現有陣列進行更改
mdadm --misc options... devices
報告或修改各種MD相關設備的。
mdadm --grow options device
調整以激活的raid陣列
mdadm --incremental device
從一個raid中,添加/刪除設備
mdadm --monitor options...
監(jiān)視一個或多個raid陣列的變化
mdadm device options...
--manage的簡寫
mdadm --create 主要參數
--auto=yes :決定建立后面接的軟體磁盤陣列設備,亦即/ dev/md0的,/ dev/md1上...
--raid-devices=N :使用幾個磁盤 (partition) 作為磁盤陣列的設備
--spare-devices=N :使用幾個磁盤作用磁盤陣列的備用設備
--level=[015] :設置磁盤陣列的等級,常用0,1,5
mdadm --manage 主要參數
--add :會將后面的設備加入到這個MD中!
--remove :會將后面的設備由這個MD中移除
--fail :會將后面的設備設定成為出錯的狀態(tài)
一、在linux系統(tǒng)中目前以MD(Multiple Devices)虛擬塊設備的方式實現軟件RAID,利用多個底層的塊設備虛擬出一個新的虛擬設備,并且利用條帶化(stripping)技術將數據塊均勻分布到多個磁盤上來提高虛擬設備的讀寫性能,利用不同的數據冗祭算法來保護用戶數據不會因為某個塊設備的故障而完全丟失,而且還能在設備被替換后將丟失的數據恢復到新的設備上.
目前MD支持linear,multipath,raid0(stripping),raid1(mirror),raid4,raid5,raid6,raid10等不同的冗余級別和級成方式,當然也能支持多個RAID陳列的層疊組成raid1 0,raid5 1等類型的陳列,
本文主要講解用戶層mdadm如何管理軟件RAID及使用中經常遇到的問題及解決辦法.現流行的系統(tǒng)中一般已經將MD驅動模塊直接編譯到內核中或編譯為可動態(tài)加載的驅動模塊,我們可以在機器啟動后通過cat /proc/mdstat看內核是否已經加載MD驅動或者cat /proc/devices是否有md塊設備,并且可以使用lsmod看MD是否可以模塊加載到系統(tǒng)中.
代碼如下:
[root@testggv ~]# cat /proc/mdstat
Personalities :
unused devices:
[root@testggv ~]#
[root@testggv ~]# cat /proc/devices | grep md
1 ramdisk
9 md
254 mdp
[root@testggv ~]#mdadm --version
[root@testggv ~]# mdadm --version
mdadm - v2.5.4 - 13 October 2006
[root@testggv ~]#
二、mdadm管理軟raid陳列
mdadm程序是一個獨立的程序,能完成所有的軟件raid管理功能,主要有7種使用模式:
Create
使用空閑的設備創(chuàng)建一個新的陣列,每個設備具有元數據塊
Assemble
將原來屬于一個陣列的每個塊設備組裝為陣列
Build
創(chuàng)建或組裝不需要元數據的陣列,每個設備沒有元數據塊
Manage
管理已經存儲陣列中的設備,比如增加熱備磁盤或者設置某個磁盤失效,然后從陣列中刪除這個磁盤
Misc
報告或者修改陣列中相關設備的信息,比如查詢陣列或者設備的狀態(tài)信息
Grow
改變陣列中每個設備被使用的容量或陣列中的設備的數目
Monitor
監(jiān)控一個或多個陣列,上報指定的事件
如果MD驅動被編譯到內核中,當內核調用執(zhí)行MD驅動時,會自動查找分區(qū)為FD(linux raid autodetect格式的磁盤。所以一般會使用fdisk工具將HD磁盤或者SD磁盤分區(qū),再設置為FD的磁盤。
代碼如下:
[root@testggv ~]# fdisk /dev/hdc
The number of cylinders for this disk is set to 25232.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-25232, default 1):
Using default value 1
Last cylinder or size or sizeM or sizeK (1-25232, default 25232):
Using default value 25232
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or
busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@testggv ~]#