说明:实验环境为LINUX自带kvm虚拟机,首先进行raid5和raid0的制作,在此基础上,创建,物理卷,逻辑卷组,逻辑卷。并进行简单测试。
测试系统:centos6.6
[root@centos6-1 ~]# ll /dev/sd* --原始硬盘
brw-rw----. 1 root disk 8, 0 Aug 13 11:12 /dev/sda
brw-rw----. 1 root disk 8, 16 Aug 13 11:12 /dev/sdb
brw-rw----. 1 root disk 8, 32 Aug 13 11:12 /dev/sdc
brw-rw----. 1 root disk 8, 48 Aug 13 11:12 /dev/sdd
brw-rw----. 1 root disk 8, 64 Aug 13 11:12 /dev/sde
brw-rw----. 1 root disk 8, 80 Aug 13 11:12 /dev/sdf
brw-rw----. 1 root disk 8, 96 Aug 13 11:12 /dev/sdg
brw-rw----. 1 root disk 8, 112 Aug 13 11:12 /dev/sdh
[root@centos6-1 ~]#
[root@centos6-1 ~]# mdadm -C /dev/md0 -l5 -n3 -x1 /dev/sd{a,b,c,d} --制作raid5
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@centos6-1 ~]#
[root@centos6-1 ~]# mdadm -C /dev/md1 -l0 -n2 -x1 /dev/sd{e,f,g} --制作raid0 --提示不能加热备盘
mdadm: spare-devices setting is incompatible with raid level 0
[root@centos6-1 ~]# mdadm -C /dev/md1 -l0 -n2 /dev/sd{e,f} --重新制作raid0,这次不加热备盘
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[root@centos6-1 ~]#
[root@centos6-1 ~]# pvcreate /dev/md{0,1} -- 创建物理卷,提示没有该命令
-bash: lvcreate: command not found
[root@centos6-1 ~]# yum provides pvcreate --查询提供该命令的rpm包
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
iso | 4.0 kB 00:00 ...
Warning: 3.0.x versions of yum would erroneously match against filenames.
You can use "*/pvcreate" and/or "*bin/pvcreate" to get that behaviour
No Matches found
[root@centos6-1 ~]# yum provides */pvcreate
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
iso/filelists_db | 6.0 MB 00:00 ...
lvm2-2.02.111-2.el6.x86_64 : Userland logical volume management tools
Repo : iso
Matched from:
Filename : /sbin/lvcreate
[root@centos6-1 ~]# yum -y install lvm2 --查询出来后安装该包
[root@centos6-1 ~]# pvcreate /dev/md{0,1} --重新创建物理卷
Physical volume "/dev/md0" successfully created
Physical volume "/dev/md1" successfully created
[root@centos6-1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/md0 lvm2 --- 2.00g 2.00g
/dev/md1 lvm2 --- 2.00g 2.00g
[root@centos6-1 ~]# vgs
No volume groups found
[root@centos6-1 ~]# vgcreate vg01 /dev/md{0,1} --创建逻辑卷组
Volume group "vg01" successfully created
[root@centos6-1 ~]# lvcreate -l 100 -n lv01 vg01 --创建逻辑卷LV01 100*4=400M
Logical volume "lv01" created
[root@centos6-1 ~]# lvcreate -L 200 -n lv02 vg01 --创建逻辑卷LV02 200M
Logical volume "lv02" created
[root@centos6-1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv01 vg01 -wi-a----- 400.00m
lv02 vg01 -wi-a----- 200.00m
[root@centos6-1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/md0 vg01 lvm2 a-- 2.00g 1.41g
/dev/md1 vg01 lvm2 a-- 2.00g 2.00g
[root@centos6-1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg01 2 2 0 wz--n- 3.99g 3.41g
[root@centos6-1 ~]# mkfs.ext4 /dev/vg01/lv01 --给LV01 逻辑卷创建文件系统
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=512 blocks, Stripe width=1024 blocks
102400 inodes, 409600 blocks
20480 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
50 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@centos6-1 ~]# mkfs.ext4 /dev/vg01/lv02 --给LV02逻辑卷创建文件系统
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=512 blocks, Stripe width=1024 blocks
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@centos6-1 ~]#
[root@centos6-1 ~]# mdadm -Ds
ARRAY /dev/md0 metadata=1.2 spares=1 name=centos6-1:0 UUID=cf35972f:6bac4619:8192e793:88403010
ARRAY /dev/md1 metadata=1.2 name=centos6-1:1 UUID=a416f6a2:b256b0a3:0c08356f:d88d9212
[root@centos6-1 ~]# mdadm -Ds > /etc/mdadm.conf --设置磁盘阵列开机有效
[root@centos6-1 ~]# cat /etc/mdadm.conf
ARRAY /dev/md0 metadata=1.2 spares=1 name=centos6-1:0 UUID=cf35972f:6bac4619:8192e793:88403010
ARRAY /dev/md1 metadata=1.2 name=centos6-1:1 UUID=a416f6a2:b256b0a3:0c08356f:d88d9212
[root@centos6-1 ~]#
[root@centos6-1 ~]# blkid |grep lv|awk -F" " '{print $2}' |xargs -I {} echo {} /mnt/lv ext4 defaults 0 0 >>/etc/fstab --lv分区uuid写入fatab
[root@centos6-1 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Mar 30 14:07:03 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=2a3ba691-702f-48b5-91e7-6aff9446eeea / ext4 defaults 1 1
UUID=24ea2c49-983a-4d69-af81-2562e0d57b5c /boot ext4 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
/dev/sr0 /mnt/centos iso9660 defaults 0 0
UUID=44d81cd1-726c-47f9-a4f2-abfd958fafe0 /mnt/lv ext4 defaults 0 0
UUID=e1a68deb-9d5d-43cc-8daa-8328784743d4 /mnt/lv ext4 defaults 0 0
[root@centos6-1 ~]# vim /etc/fstab --**手动修给挂载点目录为 /mnt/lv1 /mnt/lv2
[root@centos6-1 ~]#
[root@centos6-1 ~]# mount -a
[root@centos6-1 ~]#
[root@centos6-1 ~]# cd /mnt/
[root@centos6-1 mnt]# ls
centos lv1 lv2
[root@centos6-1 mnt]# cd lv1/
[root@centos6-1 lv1]# ls
lost+found
[root@centos6-1 lv1]# ls ../lv2/
lost+found
[root@centos6-1 lv1]#
[root@centos6-1 lv1]# time dd if=/dev/zero of=test.file bs=1M count=50 测试均为默认的非同步(async)测试结果,结果仅为大概参考
50+0 records in
50+0 records out
52428800 bytes (52 MB) copied, 0.11927 s, 440 MB/s
real 0m0.122s
user 0m0.001s
sys 0m0.043s
[root@centos6-1 lv1]# cd ../lv2
[root@centos6-1 lv2]# time dd if=/dev/zero of=test.file bs=1M count=50
50+0 records in
50+0 records out
52428800 bytes (52 MB) copied, 0.0360319 s, 1.5 GB/s
real 0m0.039s
user 0m0.000s
sys 0m0.036s
[root@centos6-1 lv2]#
[root@centos6-1 lv2]# cd /
[root@centos6-1 /]# time dd if=/dev/zero of=test.file bs=1M count=50
50+0 records in
50+0 records out
52428800 bytes (52 MB) copied, 0.222715 s, 235 MB/s
real 0m0.225s
user 0m0.000s
sys 0m0.041s
[root@centos6-1 /]#
[root@centos6-1 lv1]# time dd if=/dev/zero of=test.file bs=1M count=200 --同步测试
200+0 records in
200+0 records out
209715200 bytes (210 MB) copied, 4.0815 s, 51.4 MB/s
real 0m4.084s
user 0m0.000s
sys 0m0.303s
[root@centos6-1 lv1]#
[root@centos6-1 lv1]# mdadm -D /dev/md0
Number Major Minor RaidDevice State
0 8 0 0 active sync /dev/sda
1 8 16 1 active sync /dev/sdb
4 8 32 2 active sync /dev/sdc
3 8 48 - spare /dev/sdd
[root@centos6-1 lv1]# mdadm -D /dev/md1
Number Major Minor RaidDevice State
0 8 64 0 active sync /dev/sde
1 8 80 1 active sync /dev/sdf
[root@centos6-1 lv1]# fdisk /dev/sdg
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x89ce895c.
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)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1011, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1011, default 1011):
Using default value 1011
Command (m for help): p
Disk /dev/sdg: 1073 MB, 1073741824 bytes
34 heads, 61 sectors/track, 1011 cylinders
Units = cylinders of 2074 * 512 = 1061888 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x89ce895c
Device Boot Start End Blocks Id System
/dev/sdg1 1 1011 1048376+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos6-1 lv1]# partx /dev/sdg
# 1: 61- 2096813 ( 2096753 sectors, 1073 MB)
# 2: 0- -1 ( 0 sectors, 0 MB)
# 3: 0- -1 ( 0 sectors, 0 MB)
# 4: 0- -1 ( 0 sectors, 0 MB)
[root@centos6-1 lv1]# partx -a /dev/sdg
BLKPG: Device or resource busy
error adding partition 1
[root@centos6-1 lv1]#
[root@centos6-1 lv1]# mkdir /mnt/sdg
[root@centos6-1 lv1]# mount -o sync /dev/sdg /mnt/sdg/
mount: you must specify the filesystem type
[root@centos6-1 lv1]# mkfs.ext4 /dev/sdg1
......
[root@centos6-1 lv1]# mount -o sync /dev/sdg1 /mnt/sdg/
[root@centos6-1 lv1]# cd ../sdg/
[root@centos6-1 sdg]# time dd if=/dev/zero of=test.file bs=1M count=200
200+0 records in
200+0 records out
209715200 bytes (210 MB) copied, 7.94937 s, 26.4 MB/s
real 0m7.973s
user 0m0.003s
sys 0m0.384s
[root@centos6-1 sdg]# df -ThP
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda2 ext4 7.6G 810M 6.4G 12% /
tmpfs tmpfs 246M 0 246M 0% /dev/shm
/dev/vda1 ext4 190M 26M 155M 14% /boot
/dev/sr0 iso9660 4.4G 4.4G 0 100% /mnt/centos
/dev/mapper/vg01-lv01 ext4 380M 203M 158M 57% /mnt/lv1
/dev/mapper/vg01-lv02 ext4 190M 52M 129M 29% /mnt/lv2
/dev/sdg1 ext4 992M 202M 740M 22% /mnt/sdg
[root@centos6-1 sdg]#
上边为创建及测试
--------------------------------------------------------------------------------------------------------------------------------------------------
下边为删除
[root@centos6-1 ~]# umount /mnt/lv1 --卸载挂载
[root@centos6-1 ~]# umount /mnt/lv2
[root@centos6-1 ~]#
[root@centos6-1 ~]# lvremove /dev/vg01/lv01 --删除lv
Do you really want to remove active logical volume lv01? [y/n]: y
Logical volume "lv01" successfully removed
[root@centos6-1 ~]# lvremove /dev/vg01/lv02
Do you really want to remove active logical volume lv02? [y/n]: y
Logical volume "lv02" successfully removed
[root@centos6-1 ~]#
[root@centos6-1 ~]# lvs
[root@centos6-1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg01 2 0 0 wz--n- 3.99g 3.99g
[root@centos6-1 ~]# vgremove vg01 --删除vg
Volume group "vg01" successfully removed
[root@centos6-1 ~]# vgs
No volume groups found
[root@centos6-1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/md0 lvm2 --- 2.00g 2.00g
/dev/md1 lvm2 --- 2.00g 2.00g
[root@centos6-1 ~]# pvremove /dev/md0 --删除pv
Labels on physical volume "/dev/md0" successfully wiped
[root@centos6-1 ~]# pvremove /dev/md1
Labels on physical volume "/dev/md1" successfully wiped
[root@centos6-1 ~]# pvs
[root@centos6-1 ~]#
[root@centos6-1 ~]# mdadm -S /dev/md0 --停用raid5
mdadm: stopped /dev/md0
[root@centos6-1 ~]# mdadm -S /dev/md1 --停用raid0
mdadm: stopped /dev/md1
[root@centos6-1 ~]#
[root@centos6-1 ~]# rm -rf /dev/md0 --删除raid5
[root@centos6-1 ~]# rm -rf /dev/md1 --删除raid0
[root@centos6-1 ~]# mdadm --zero-superblock /dev/sda --释放硬盘
[root@centos6-1 ~]# mdadm --zero-superblock /dev/sdb
[root@centos6-1 ~]# mdadm --zero-superblock /dev/sdc
[root@centos6-1 ~]# mdadm --zero-superblock /dev/sdd
[root@centos6-1 ~]# mdadm --zero-superblock /dev/sde
[root@centos6-1 ~]# mdadm --zero-superblock /dev/sdf
[root@centos6-1 ~]# rm -rf /etc/mdadm.conf --删除raid配置文件
[root@centos6-1 ~]#
至此,创建raid0 ,raid5, pv, vg, lv 并且删除操作完成。
谢谢查阅,如有问题,敬请指正。