【实例1】
某台机器上有4块空闲的硬盘,分别是/dev/sdb、/dev/sdc、/dev/sdd和/dev/sde,并用这四块硬盘来创建来创建一个RAID 5,具体操作步骤如下:
首先使用“fdisk”命令在每块硬盘上创建一个分区,操作如下:
root@xiaop-laptop:/# 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 #按n创建新分区
Command action
e extended
p primary partition (1-4) #输入p 选择创建主分区
p
Partition number (1-4): 1 #输入 1 创建第一个主分区
First cylinder (1-102, default 1): #直接回车,选择分区开始柱面这里就从 1 开始
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-102, default 102):
Using default value 102
Command (m for help): w #然后输入w写盘
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
针对其余几块硬盘也做相同操作,按照此步骤在另外的两块磁盘上做同样的操作;
全部做完后,运行 fdisk -l 应该可以看到如下信息:
Disk /dev/sdb: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 204 208880 fd Linux raid autodetect
Disk /dev/sdc: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 204 208880 fd Linux raid autodetect
Disk /dev/sdd: 214 MB, 214748160 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Device Boot Start End Blocks Id System
/dev/sdd1 1 204 208880 fd Linux raid autodetect
看到上面三个磁盘上分别建了一个分区,分区大小都一样;
4.1.2 创建RAID 5;
创建完/dev/sdb1、/dev/sdc1、/dev/sdd1、/dev/sde1四个分区后,下面就可以来创建RAID 5了,其中设定/dev/sde1作为备用设备,其余为活动设备,备用设备的作用是一旦某一设备损坏可以立即使用备用设备替换。操作命令如下:
root@xiaop-laptop:/# mdadm --create /dev/md0 --level=5 --raid-devices=3 --spare-devices=1 /dev/sd[b-e]1
mdadm: array /dev/md0 started.
其中“--spare-devices=1”表示当前阵列中备用设备只有一块,即作为备用设备的“/dev/sde1”,若有多块备用设备,则将“--spare-devices”的值设置为相应的数目。成功创建完成RAID设备后,通过如下命令可以查看到RAID的详细信息:
root@xiaop-laptop:/# mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.01
Creation Time : Mon Jan 22 10:55:49 2007
Raid Level : raid5
Array Size : 208640 (203.75 MiB 213.65 MB)
Device Size : 104320 (101.88 MiB 106.82 MB)
Raid Devices : 3
Total Devices : 4
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Mon Jan 22 10:55:52 2007
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 64K
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
3 8 65 -1 spare /dev/sde1
UUID : b372436a:6ba09b3d:2c80612c:efe19d75
Events : 0.6
4.1.3 创建RAID的配置文件;
RAID的配置文件名为“mdadm.conf”,默认是不存在的,所以需要手工创建,该配置文件存在的主要作用是系统启动的时候能够自动加载软RAID,同时也方便日后管理。“mdadm.conf”文件内容包括:由DEVICE选项指定用于软RAID的所有设备,和ARRAY选项所指定阵列的设备名、RAID级别、阵列中活动设备的数目以及设备的UUID号。生成RAID配置文件操做如下:
root@xiaop-laptop:/# mdadm --detail --scan > /etc/mdadm.conf
但是当前生成“mdadm.conf”文件的内容并不符合所规定的格式,所以也是不生效的,这时需要手工修改该文件内容为如下格式:
root@xiaop-laptop:/# vi /etc/mdadm.conf
DEVICE /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
ARRAY /dev/md0 level=raid5 num-devices=3 UUID=b372436a:6ba09b3d:2c80612c:efe19d75
如果没有创建RAID的配置文件,那么在每次系统启动后,需要手工加载软RAID才能使用,手工加载软RAID的命令是:
root@xiaop-laptop:/# mdadm --assemble /dev/md0 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
mdadm: /dev/md0 has been started with 3 drives and 1 spare.
4.1.4 创建文件系统;