mdadm 指令

# mdadm –help
mdadm is used for building, managing, and monitoring
Linux md devices (aka RAID arrays)
Usage: mdadm –create device options…
            Create a new array from unused devices.
       mdadm –assemble device options…
            Assemble a previously created array.
       mdadm –build device options…
            Create or assemble an array without metadata.
       mdadm –manage device options…
            make changes to an existing array.
       mdadm –misc options… devices
            report on or modify various md related devices.
       mdadm –grow options device
            resize/reshape an active array
       mdadm –incremental device
            add/remove a device to/from an array as appropriate
       mdadm –monitor options…
            Monitor one or more array for significant changes.[@more@]列出常用指令
mdadm –create –help
Usage:  mdadm –create device -chunk=X –level=Y –raid-devices=Z devices
 –level=      -l   : raid level: 0,1,4,5,6,10,linear,multipath and synonyms
  –raid-devices= -n : number of active devices in array
Example:
# mdadm –create /dev/md0 –level=stripe –raid-devices=4 /dev/sd[b-e]1
# mdadm –create /dev/md0 –level=5 –raid-devices=4 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
# mdadm –create /dev/md0 –level=6 –raid-devices=4 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1

# mdadm -E /dev/sd[b-e]
# mdadm –examine /dev/sd[b-e]
# mdadm –examine /dev/sdb /dev/sdc /dev/sdd /dev/sde
/dev/sdb:
   MBR Magic : aa55
Partition[0] :     41940992 sectors at         2048 (type fd)
/dev/sdc:
   MBR Magic : aa55
Partition[0] :     41940992 sectors at         2048 (type fd)
/dev/sdd:
   MBR Magic : aa55
Partition[0] :     41940992 sectors at         2048 (type fd)
/dev/sde:
   MBR Magic : aa55
Partition[0] :     41940992 sectors at         2048 (type fd)

顯示 RAID 資訊
# mdadm –detail /dev/md0
# 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:36:08 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 : 23

    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

# mdadm –detail –scan –verbose
ARRAY /dev/md/0 level=raid6 num-devices=4 metadata=1.2 name=debian:0 UUID=8f039d29:9179c09a:17a76417:e54c9dfa
   devices=/dev/sdb1,/dev/sdc1,/dev/sdd1,/dev/sde1

停止 RAID
# mdadm –manage –stop /dev/md0

啟動 RAID
# mdadm –assemble –run /dev/md0
# mdadm -A –run /dev/md0

模擬磁碟故障
# mdadm –manage /dev/md0 –fail /dev/sdd1
# mdadm –manage /dev/md0 –set-faulty /dev/sdd1

加入磁碟到 RAID 中
# mdadm –manage /dev/md0 –add /dev/sdf1

從 RAID 中移除磁碟
# mdadm –manage /dev/md0 –remove /dev/sdd1