查看磁盘信息
# fdisk -l
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
Disk /dev/sdd: 21.5 GB, 21474836480 bytes
分区,大小必须相同,sdc、sdd同sdb
# fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +200M
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): p
Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ fd Linux raid autodetect
Command (m for help): w
创建磁盘阵列,-l阵列模式,-n磁盘数,/dev/md0为阵列名称
# mdadm -Cv /dev/md0 -l0 -n3 /dev/sd[bcd]1
mdadm: chunk size defaults to 512K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
设置文件
mdadm不采用/etc/mdadm.conf作为主要设置文件,能完全不依赖该文件而不会影响阵列的正常工作。该设置文件的主要作用是方便跟踪软RAID的设置。
# echo DEVICE /dev/sd[bcd]1 >/etc/mdadm.conf
# mdadm -Ds >>/etc/mdadm.conf
# mdadm --detail --scan >>/etc/mdadm.conf
格式化阵列
# mkfs.ext3 /dev/md0
# mkdir /mnt/test
# mount /dev/mdo0 /mnt/test/ -t ext3
# df
/dev/md0 612296 16872 564320 3% /mnt/test
查看阵列
# cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 sdd1[2] sdc1[1] sdb1[0]
622080 blocks super 1.2 512k chunks
unused devices: <none>
# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Sat Aug 20 12:00:31 2016
Raid Level : raid0
Array Size : 622080 (607.60 MiB 637.01 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Sat Aug 20 12:00:31 2016
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Chunk Size : 512K
Name : test1.example.com:0 (local to host test1.example.com)
UUID : 19a8281f:fdb9ab5a:2867cb8e:920b90cc
Events : 0
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
停止,需先卸载再停止
# mdadm -S /dev/md0
mdadm: stopped /dev/md0
停止指定阵列,并释放磁盘(--stop)
停止后,原组成阵列的磁盘将处于空闲状态,一旦吾操作这些磁盘,将不能再重启激活原阵列。
启动
# mdadm -A /dev/md0 /dev/sd[bcd]1
mdadm: /dev/md0 has been started with 3 drives.
启动指定的阵列,也可理解为讲一个新阵列装配到系统中(--assemble)
查找
(1)若你已在上面设置了/etc/mdadm.conf文件,也可用-s查找:
# mdadm -As /dev/md0
(2)如果你没有设置/etc/mdadm.conf文件,而且又忘了某磁盘属于那个阵列,则你能使用检测:(--examine)
# mdadm -E /dev/sdb1
/dev/sdb1:
Magic : a92b4efc
Version : 1.2
Feature Map : 0x0
Array UUID : e6add54b:c03a501b:ec673588:9080bd51
Name : test1.example.com:0 (local to host test1.example.com)
Creation Time : Sat Aug 20 12:17:08 2016
Raid Level : raid0
Raid Devices : 3
Avail Dev Size : 415579 (202.95 MiB 212.78 MB)
Data Offset : 2048 sectors
Super Offset : 8 sectors
Unused Space : before=1960 sectors, after=0 sectors
State : clean
Device UUID : ccbbc698:c535e307:b01be16f:23a795e2
Update Time : Sat Aug 20 12:17:08 2016
Bad Block Log : 512 entries available at offset 72 sectors
Checksum : 55c0fbfa - correct
Events : 0
Chunk Size : 512K
Device Role : Active device 0
Array State : AAA (‘A‘ == active, ‘.‘ == missing, ‘R‘ == replacing)
激活
# mdadm -Av /dev/md0 --uuid=8ba81579:e20fb0e8:e040da0e:f0b3fec8 /dev/sd*
添加及删除磁盘
mdadm能在Manage模式下,对运行中的阵列进行添加及删除磁盘。常用于标识failed磁盘,增加spare(冗余)磁盘,及替换磁盘等。则能使用--fail指定坏磁盘,并--remove走
# mdadm /dev/md0 --fail /dev/sdc1 --remove /dev/sdc1
※需要注意的是,对于某些阵列模式,如RAID0等,是不能用--fail和--remove的
阵列增加新的磁盘
mdadm /dev/md0 --add /dev/sdc1
※需要注意的是,对于某些阵列模式,如RAID0等,是不能用--add的
增加spare磁盘
mdadm -Cv /dev/md0 -l1 -n2 -x1 /dev/sd[bcd]1
删除阵列,需先卸载
mdadm -S /dev/md0
或
rm /dev/md0
修改/etc/mdadm.conf、/etc/fstab等设置文件,把相关的地方去掉