通过mdadm命令调用内核MD模块实现软Raid

1.软raid的实现方式:

软Raid本身是一个软件程序,这个程序是内核模块MD来模拟实现的。由于它的运行是依赖于操作系统的,软件程序和系统出现故障,RAID就有可能出现问题。性能上不及硬件RAID,还会对CPU造成一定的压力。在生产环境中,不建议使用软Raid,使用raid卡或者Raid芯片实现Raid功能。Linux软体RAID设备通过MD(多个设备)设备驱动程序来实现。

2.mdadm命令介绍:

mdadm:模式化的命令

mdadm [mode] <raiddevice> [options] <component-devices>

-A:–assemble 装配模式,组装一个预先存在的数组。

-C:–build 创建模式,创建一个新的数组

-F:–follow,–monitor 监控模式,选择监控模式。

-G: –grow 改变的有源阵列的大小或形状。

-I: –incremental 添加/从适当的数组中删除单个器件/,并可能启动阵列。

创建的软Raid:/dev/md0, /dev/md1, /dev/md2…

-a {yes|no}:是否为新建的raid设备自动创建设备文件/dev/md#

-l #:指定Raid级别;

-n #:指定用于Raid的块设备的个数,不包括备盘;

-c:指定chunks块的大小

-x #:指定用于备盘的块设备个数;

DEVICE…

-D,–detail :详细信息 显示一个Raid设备的详细信息。

用法示例:

mdadm -D /dev/md0 等同于mdadm -detail /dev/md0

设备文件:

major:主设备号,用于区分设备类别;

minor:此设备号,,用于区分同一种类别下不同的具体设备;

一、通过mdadm命令,调用内核MD模块创建Raid0

1.首先,在虚拟机上新添加两块20G的物理硬盘,用来做在不同磁盘上的Raid。

注意:在同一块磁盘的不同分区上,不能做raid,当磁盘出现故障,Raid就无法使用了。做Raid的时候,要在不同的物理硬盘上。

1).查看添加好的物理硬盘。

[root@Vmware5 ~]# fdisk -l /dev/sdbDisk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000[root@Vmware5 ~]# fdisk -l /dev/sdcDisk /dev/sdc: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000

2).创建一个5G大小的sdb1新分区,文件分区类型为fd。

[root@Vmware5 ~]# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x19603682.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won’t be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)WARNING: DOS-compatible mode is deprecated. It’s strongly recommended toswitch off the mode (command ‘c’) and change display units tosectors (command ‘u’).Command (m for help): nCommand action e extended p primary partition (1-4)pPartition number (1-4): 1First cylinder (1-2610, default 1):Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5GCommand (m for help): tSelected partition 1Hex code (type L to list codes): fdChanged system type of partition 1 to fd (Linux raid autodetect)Command (m for help): pDisk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x19603682 Device BootStartEndBlocks Id System/dev/sdb116545253223+ fd Linux raid autodetectCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.

3).创建一个大小为5G的sdc1新分区,文件分区类型为fd。

[root@Vmware5 ~]# fdisk /dev/sdcDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x07b84e42.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won’t be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)WARNING: DOS-compatible mode is deprecated. It’s strongly recommended toswitch off the mode (command ‘c’) and change display units tosectors (command ‘u’).Command (m for help): nCommand action e extended p primary partition (1-4)pPartition number (1-4): 1First cylinder (1-2610, default 1):Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5GCommand (m for help): tSelected partition 1Hex code (type L to list codes): fdChanged system type of partition 1 to fd (Linux raid autodetect)Command (m for help): pDisk /dev/sdc: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x07b84e42 Device BootStartEndBlocks Id System/dev/sdc116545253223+ fd Linux raid autodetectCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.

注意:创建好分区之后,不要格式化,格式化的是创建好的软Raid,不是它下边的分区。

努力爱一个人。付出,不一定会有收获;

通过mdadm命令调用内核MD模块实现软Raid

相关文章:

你感兴趣的文章:

标签云: