mdadm使用详解及RAID 5简单分析,一般系统自带有。
<?xml:namespace prefix = o /><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
mdadm用法
基本语法 :mdadm [mode] <raid-device> [options] <component-devices>
mode 有7种:
1. Assemble:将以前定义的某个阵列加入当前在用阵列。
2. Build:Build a legacy array ,每个device 没有 superblocks
3.Create:创建一个新的阵列,每个device 具有 superblocks
4.Manage: 管理阵列,比如 add 或 remove
5.Misc:允许单独对阵列中的某个 device 做操作,比如抹去superblocks 或 终止在用的阵列。
6. Follow or Monitor:监控 raid 1,4,5,6 和 multipath 的状态
7. Grow:改变raid 容量或 阵列中的 device 数目
可用的 [options]:
-A, --assemble:加入一个以前定义的阵列
-B, --build:Build a legacy array without superblocks.
-C, --create:创建一个新的阵列
-Q, --query:查看一个device,判断它为一个 md device 或是 一个 md 阵列的一部分
-D, --detail:打印一个或多个 md device 的详细信息
-E, --examine:打印 device 上的 md superblock 的内容
-F, --follow, --monitor:选择 Monitor 模式
-G, --grow:改变在用阵列的大小或形态
-h, --help:帮助信息,用在以上选项后,则显示该选项信息
--help-options
-V, --version
-v, --verbose:显示细节
-b, --brief:较少的细节。用于 --detail 和 --examine 选项
-f, --force
-c, --config= :指定配置文件,缺省为 /etc/mdadm.conf
-s, --scan:扫描配置文件或 /proc/mdstat以搜寻丢失的信息。配置文件/etc/mdadm.conf
RARI-5配置的基本步骤:
添加4块硬盘。
[root@localhost ~]# fdisk –l 查看

分区
N(开始划分分区)àP(主分区)->1(第一个主分区) 然后指定大小
分区的大小要相同
[root@localhost ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previouscontent won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n 添加分区
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1 添加主分区1
First cylinder (1-130, default 1):确定第一个主分区的起始磁柱,默认为1就好。
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): 50 设置大小(也可用+<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />200M来指定)
Command (m for help): p 查看
Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 50 401593+ 83 Linux
Command (m for help): t 改变分区类型
Selected partition 1
Hex code (type L to list codes): fd fd为linux raid autodetect
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): p
Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 50 401593+ fd Linux raid autodetect
Command (m for help): w (q) 保存退出 (不保存退出)
划分完之后
[root@localhost ~]# fdisk –l 查看
Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 50 401593+ fd Linux raid autodetect
Disk /dev/sdd: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdd1 1 50 401593+ fd Linux raid autodetect
Disk /dev/sde: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sde1 1 50 401593+ fd Linux raid autodetect
创建RAID-5卷
好了现在我们随便添加些数据
查看RAID信息
[root@localhost ~]# mdadm -D /dev/md5

[root@localhost ~]# mdadm /dev/md5 -f /dev/sdc1
mdadm: set /dev/sdc1 faulty in /dev/md5
[root@localhost ~]# mdadm -D /dev/md5
移除失败磁盘
[root@localhost ~]# mdadm /dev/md5 –r /dev/sdc1
mdadm: hot removed /dev/sdc1
[root@localhost ~]# mdadm -D /dev/md5

虽然坏了一个盘,但数据依然在。

现在我们来添加一块盘,分区.格式做成RAID5.
[root@localhost ~]# fdisk /dev/sdf
将磁盘加入到阵列中,可以看到数据正在恢复中并完整恢复
保存配置文件
若要开机自动挂载,请在/etc/fstab中添加:
/dev/md5 /mnt/md5 auto defaults 0 0
转载于:https://blog.51cto.com/blue107/166219