Linux下创建raid5卷相当方便,用自带的工具mdadm命令就可以轻松实现,下面是我在虚拟机上做的实验,只为学习操作
实验环境:RHEL5.6+三块SCIS硬盘,大小相同,都是3GB
虚拟机添加新的硬盘要重启系统才能识别
三块新硬盘被系统识别后我们接下来要进行分区
输入fdisk /dev/sdb 具体要看你实际环境中硬盘的编号
下面就是我们在Linux中正常分区的交互式分区操作这里我就不在重复了
分好区后用fdisk -l查看分区如何,这里为了实验,每个硬盘都是单独一个分区
分区工作已经准备好了,下面我们就使用mdadm命令创建raid5卷
[root@test ~]# mdadm -C /dev/md0 -a yes -l 5 -n 3 -x 0 /dev/sd[bcd] -C表示创建(create的意思),-l表示raid级别(level意思) -n表示设备的数据(number) -x 指定初始阵列的富余device 数目
创建完成后会输入下面一条信息
mdadm: array /dev/md0 started.
[root@test ~]# mdadm -Ds /dev/md0 //查看raid详细信息
/dev/md0:
Version : 0.90
Creation Time : Thu Jun 7 20:05:41 2012
Raid Level : raid5
Array Size : 6291328 (6.00 GiB 6.44 GB)
Used Dev Size : 3145664 (3.00 GiB 3.22 GB)
Raid Devices : 3
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Thu Jun 7 20:05:41 2012
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 64K
Rebuild Status : 69% complete
UUID : fb19f6b4:410569c7:d3cd7b7f:1966e6df
Events : 0.1
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
3 8 48 2 spare rebuilding /dev/sdd
把这些文件输出到一个配置文件中
[root@test ~]# mdadm -Ds > /etc/mdadm.conf //生成raid5配置文件
分完区后我们还要进行格式化,否则仍然写不了数据
[root@test ~]# mkfs -t ext3 /dev/md0
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
786432 inodes, 1572832 blocks
78641 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1610612736
48 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
已经格式化完成,下面我们就可以把这个RAID5卷挂载到某个目录下面正常使用了
[root@test ~]# mkdir /var/raid5
[root@test ~]# mount /dev/md0 /var/raid5/
[root@test ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 17981340 2300956 14752232 14% /
/dev/sda1 295561 16161 264140 6% /boot
tmpfs 517352 0 517352 0% /dev/shm
/dev/md0 6192576 143488 5734524 3% /var/raid5 //因为RAID5的空间是总空间的3/4(总空间为9G),所以只有6G空间
添加到默认挂载配置文件中,让其随系统启动挂载
[root@test ~]# vi /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda3 swap swap defaults 0 0
/dev/md0 /var/raid5 ext3 defaults 0 0 //添加此行
[root@test ~]# cd /var/raid5/
[root@test raid5]# ll
total 16
drwx------ 2 root root 16384 Jun 7 20:08 lost+found
[root@test raid5]# init 6 //重启后查看是不是自动挂载
[root@test ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 17981340 2301168 14752020 14% /
/dev/sda1 295561 16161 264140 6% /boot
tmpfs 517352 0 517352 0% /dev/shm
/dev/md0 6192576 143488 5734524 3% /var/raid5 //自动挂载了
[root@test ~]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
/dev/md0 on /var/raid5 type ext3 (rw) //自动挂载了
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)