Linux平台下直接创建RAID

Linux平台下使用mdadm创建和管理软raid

注:本次操作以RHEL4为例,但应该可以应用到其它大部分的distro上(guess)。

mdadm的几个常用参数
-C 创建Raid,后面跟参数,代表raid设备的名称。比如:/dev/md0,/dev/md1。
-n 用于创建磁盘阵列的磁盘个数。
-l Raid的级别。
-x 指定用于hotspare(热备盘)的磁盘个数。如果阵列中有一块硬盘坏了,它会立刻顶上,并rebuild;
-D 显示软raid的详细信息;
-s 扫描配置文件(/etc/mdadm.conf)或'/proc/mdstat'来查看遗漏的信息f;

创建软raid的大体流程

使用fdisk工具为新磁盘创建分区;
使用mkfs.XXXX工具将刚才划分好的分区格式化成某种格式的文件系统。比如:ext3,reiserfs等;

使用mdadm来创建软raid;
创建/etc/mdadm.conf文件(注意文件的格式,包括是否有逗号等等。该文件是为了系统在重启后能够自动启用软raid。可以查看/etc/rc.sysinit脚本,搜索'mdadm'字符串就明白了);

示例:创建软raid5(+hotspare)

以下是我的一次实际操作的完整过程:

这是用'fdisk -l'命令查看到的我当前的磁盘和分区情况(只有/dev/sda在使用,其它四个都是新磁盘,没有分区,没有格式化):

# fdisk -l

Disk /dev/sda: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 720 5783368+ 83 Linux
/dev/sda2 721 783 506047+ 82 Linux swap

Disk /dev/sdb: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Disk /dev/sdc doesn't contain a valid partition table

Disk /dev/sdd: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Disk /dev/sdd doesn't contain a valid partition table

Disk /dev/sde: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Disk /dev/sde doesn't contain a valid partition table

使用fdisk创建分区(本例中将整块磁盘划分为一个主分区。其余几块磁盘也做相同的操作。):

# fdisk /dev/sdb
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 previous
content 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
First cylinder (1-204, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-204, default 204):
Using default value 204

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

为刚才新建的分区建立文件系统(其余几个分区依次做相同的操作):

# mkfs.ext3 /dev/sdb1
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
52416 inodes, 208880 blocks
10444 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
26 block groups
8192 blocks per group, 8192 fragments per group
2016 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

所有磁盘都操作完后,再次用'fdisk -l'查看磁盘及分区状态。

相关推荐