给虚拟机加四块硬盘
/dev/sab,/dev/sdc,/dev/sdd,/dev/sde
第一:对硬盘的原始操作(四块硬盘的操作相同)
[root@RedHat ~]# fdisk /dev/sd[b,c,d,e] //给硬盘分区
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): 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): fd //定格硬盘的类型为raid
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): wq
二:组建RAID5
[root@Redhat ~]# mdadm –create /dev/md0 –level=5 –raid-device=3 -c 128 /dev/sdb1 /dev/sdc1 /dev/sdd1 //组建有三块硬盘组成的RAID5
三:创建LVM
[root@Redhat ~]# pvcreate /dev/md0 //创建PE
[root@Redhat ~]# vgcreate vg0 /dev/md0 //创建VG
[root@Redhat ~]# lvcreate -l1023 -n ethnicity vg0 //创建LV
[root@Redhat ~]# mkfs.ext3 /dev/md0 //格式化
[root@Redhat ~]# mkdir /data
[root@Redhat ~]# mount /dev/vg0/ethnicity /data/
[root@Redhat ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
20G 6.0G 13G 32% /
/dev/sda1 104M 21M 78M 21% /boot
tmpfs 111M 0 111M 0% /dev/shm
none 111M 107k 111M 1% /var/lib/xenstored
/dev/mapper/vg0-ethnicity
4.3G 76M 4.0G 2% /data
四:LVM扩容
[root@Redhat ~]# umount /data/
[root@Redhat ~]# mdadm /dev/md0 -a /dev/sde1 //给RAID加一块硬盘
[root@Redhat ~]# mdadm –grow /dev/md0 –raid-devices=4 //设定硬盘的数量
[root@Redhat ~]# pvresize /dev/md0
[root@Redhat ~]# lvresize -l +512 /dev/vg0/ethnicity //根据所加硬盘大小来扩容
[root@Redhat ~]# resize2fs /dev/vg0/ethnicity
resize2fs 1.39 (29-May-2006)
Please run ‘e2fsck -f /dev/vg0/ethnicity’ first.
[root@Redhat ~]# e2fsck -f /dev/vg0/ethnicity
[root@Redhat ~]# resize2fs /dev/vg0/ethnicity
[root@Redhat ~]# mount /dev/vg0/ethnicity /data/
[root@Redhat ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
20G 6.0G 13G 32% /
/dev/sda1 104M 21M 78M 21% /boot
tmpfs 111M 0 111M 0% /dev/shm
none 111M 107k 111M 1% /var/lib/xenstored
/dev/mapper/vg0-ethnicity
6.4G 76M 6.1G 2% /data
这样这个小实例就成功了
以下是几个操作的笔记
1、 导出硬盘的分区状态
sfdisk -d /dev/sdb >disk.out
2、 把分区状态导入到另外的硬盘
sfdisk /dev/sde <disk.out
3、 查看mdadm状态
cat /proc/mdstat
mdadm –detail /dev/md0
4、 LVM删除
umount /data
lvremove /dev/vg0/ethnicity
vgremove vg0
pvremove /dev/md0
5、RAID删除
mdadm /dev/md0 –fail /dev/sd[b,c,d,e]1 –remove /dev/sdb[b,c,d,e]1
6、停止RAID
mdadm –stop /dev/md0
7、清空磁盘(分区)超级块中的RAID信息
mdadm –misc –zero-superblock /dev/sd[b,c,d,e]1
总结:学习笔记,切记多练。