环境:
OS:Red Hat Linux As5
1.添加三块scsi硬盘sd[d e f],因为实现RAID5最少需要3块硬盘.
[root@hxl oracle]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1147 9213246 83 Linux
/dev/sda2 1148 1305 1269135 82 Linux swap
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 83 Linux
Disk /dev/sdc: 17.1 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 2088 16771828+ 83 Linux
Disk /dev/sdd: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdd doesn't contain a valid partition table
Disk /dev/sde: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sde doesn't contain a valid partition table
Disk /dev/sdf: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdf doesn't contain a valid partition table
2.分别fisk磁盘sdd/sde/sdf
[root@hxl oracle]# fdisk /dev/sdd -- 选择格式化磁盘
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-261, default 1): -- 启始柱面,这里默认直接回车
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261): -- 结束面柱
Using default value 261
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): l -- 列出分区类型
0 Empty 1e Hidden W95 FAT1 75 PC/IX be Solaris boot
1 FAT12 24 NEC DOS 80 Old Minix bf Solaris
2 XENIX root 39 Plan 9 81 Minix / old Lin c1 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 82 Linux swap c4 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 83 Linux c6 DRDOS/sec (FAT-
5 Extended 41 PPC PReP Boot 84 OS/2 hidden C: c7 Syrinx
6 FAT16 42 SFS 85 Linux extended da Non-FS data
7 HPFS/NTFS 4d QNX4.x 86 NTFS volume set db CP/M / CTOS / .
8 AIX 4e QNX4.x 2nd part 87 NTFS volume set de Dell Utility
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
f W95 Ext'd (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT
10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT
1c Hidden W95 FAT3
Hex code (type L to list codes): fd -- 选择RAID卷
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): p -- 查看分区
Disk /dev/sdd: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdd1 1 261 2096451 fd Linux raid autodetect
Command (m for help): w -- 保存分区信息
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
其他2个磁盘也做如上操作,完成3个磁盘格式.
3.下面准备使用mdadm创建RAID5
3.1检查是否安装mdadm包,没有安装的话找到相应介质进行安装(在linux安装盘里一般会有mdadm安装包)
[root@hxl oracle]# rpm -qa|grep mdadm
mdadm-1.6.0-3
3.2 创建RAID5
[root@hxl oracle]# mdadm -C /dev/md5 -l5 -n3 /dev/sd[def]1
mdadm: array /dev/md5 started
-C:创建新的整列
-l:设定raid level这里是raid5
-n:阵列中可用device的数目,这里设置为3,代表3块硬盘.
sd[def]1:表示sdd1,sde1,sdf1,表示3个分区.
3.3 设置文件
mdadm不采用/etc/mdadm.conf作为主要设置文件,他能完全不依赖该文件而不会影响阵列的正常工作.
通常能这样来建立:
echo DEVICE /dev/sd[def]1>/etc/mdadm.conf
mdadm -Ds>>/etc/mdadm.conf
mdadm --detail --scan>>/etc/mdadm.conf
3.4 创建PV物理卷
[root@hxl oracle]# pvcreate /dev/md5
Physical volume "/dev/md5" successfully created
3.5 创建卷组
[root@hxl oracle]# vgcreate myvg /dev/md5
Volume group "myvg" successfully created
3.6 显示卷组
[root@hxl oracle]# vgdisplay
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 4.00 GB
PE Size 4.00 MB
Total PE 1023
Alloc PE / Size 0 / 0
Free PE / Size 1023 / 4.00 GB
VG UUID TUVUAX-P3jw-meO7-vGZJ-FJmJ-7K1r-KbPIka
从VG的大小可以看出,3块2g的磁盘做raid5后,最后的存储容量量是4g,即n-1个磁盘的容量.
3.7 创建lv
[root@hxl oracle]# lvcreate -L 3G -n lv01 myvg
Logical volume "lv01" created
3.8 格式化逻辑卷
[root@hxl oracle]#mkfs -t ext3 /dev/myvg/lv01
3.9 加载逻辑卷
[root@hxl oracle]# mount /dev/myvg/lv01 /raid5
3.10 查看磁盘情况
[root@hxl oracle]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext3 8.7G 7.3G 1.1G 88% /
none tmpfs 505M 0 505M 0% /dev/shm
/dev/sdb1 ext3 9.9G 9.4G 0 100% /u01
/dev/sdc1 ext3 16G 2.1G 13G 14% /u02
/dev/mapper/myvg-lv01
ext3 3.0G 37M 2.8G 2% /raid5
3.11 开启自动挂载
编辑/etc/fstab添加如下内容
/dev/myvg/lv01 /raid5 ext3 defaults 0 0
3.12 验证
[root@hxl /]# cd raid5
[root@hxl raid5]# mkdir mytest
[root@hxl raid5]# cd mytest
[root@hxl mytest]# echo "aa">aa.txt
[root@hxl mytest]# ls
aa.txt
raid5加挂点下能创建目录和文件,说明以上步骤做的raid5是好的.
说明:
在做RAID5的时候最好是每块硬盘容量都一致,虽然刚开始的时候,不同大小的硬盘可以做RAID5的,但是以最小的那块硬盘做容量计算,大于该容量的硬盘空间就浪费了.可以使用-x选项创建热盘,如mdadm -Cv /dev/md5 -l5 -n3 /dev/sd[bcd]1 -x1 /dev/sde1,其中sde1作为热盘.
-- The End--