linux 系统基础知识 - 卷管理

 测试环境:RHEL5.3;硬盘8G,1000M一个分区分成6个
一、创建逻辑卷的步骤:
1)通过pvcreate命令将linux分区处理成物理卷(PV);
2)通过vgcreate命令将创建好的物理卷处理成卷组(Vg);
3)通过lvcreate命令将卷组分成若干个逻辑卷(Lv);
之后我们可以对逻辑卷进行格式化,挂载,删除等操作,我们可以动态的调整逻辑卷的大小,并且该操作不会影响我们在逻辑卷(Lv)上的数据.
二、物理卷创建管理操作:
1)pvcreate创建物理卷:( 把普通Linux分区变成物理卷)
格式:pvcreate /dev/sdb{1,2,3...} 
———————————————————————————————
[root@station1 ~]# [root@station1 ~]# pvcreate /dev/sdb{1,2,3,5,6,7}
Physical volume "/dev/sdb3" successfully created
Physical volume "/dev/sdb5" successfully created
Physical volume "/dev/sdb6" successfully created
Physical volume "/dev/sdb7" successfully created
————————————————————————————————
2)pvscan查看物理卷信息:会显示所有物理卷的情况.
格式:pvscan
————————————————————————————————
[root@station1 ~]# pvscan
PV /dev/sdb1 lvm2 [964.81 MB]
PV /dev/sdb2 lvm2 [964.84 MB]
PV /dev/sdb3 lvm2 [964.84 MB]
PV /dev/sdb5 lvm2 [964.81 MB]
PV /dev/sdb6 lvm2 [964.81 MB]
PV /dev/sdb7 lvm2 [964.81 MB]
Total: 6 [5.65 GB] / in use: 0 [0 ] / in no VG: 6 [5.65 GB]
————————————————————————————————
3)pvdisplay查看各个物理卷的详细参数:
格式:pvdisplay [/dev/sdb{1,2,3...}] 不跟参数则显示所有的物理卷信息
————————————————————————————————

[root@station1 ~]# pvdisplay /dev/sdb1
"/dev/sdb1" is a new physical volume of "964.81 MB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 964.81 MB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID FKaYKk-d46E-KHCQ-WRnn-jUUE-Cd1d-mM8mPN
————————————————————————————————————
4)pvremove删除物理卷:当物理卷里的扩展快没有被使用时可以删除.
格式:pvremove /dev/sdb5
——————————————————————————————
[root@station1 ~]# pvscan
PV /dev/sdb7 VG vg1 lvm2 [960.00 MB / 960.00 MB free]
PV /dev/sdb1 VG vg0 lvm2 [964.00 MB / 964.00 MB free]
PV /dev/sdb2 VG vg0 lvm2 [964.00 MB / 964.00 MB free]
PV /dev/sdb3 VG vg0 lvm2 [964.00 MB / 964.00 MB free]
PV /dev/sdb5 lvm2 [964.81 MB]
PV /dev/sdb6 lvm2 [964.81 MB]
Total: 6 [5.65 GB] / in use: 4 [3.76 GB] / in no VG: 2 [1.88 GB]
[root@station1 ~]# pvremove /dev/sdb5
Labels on physical volume "/dev/sdb5" successfully wiped
[root@station1 ~]# pvscan
PV /dev/sdb7 VG vg1 lvm2 [960.00 MB / 960.00 MB free]
PV /dev/sdb1 VG vg0 lvm2 [964.00 MB / 964.00 MB free]
PV /dev/sdb2 VG vg0 lvm2 [964.00 MB / 964.00 MB free]
PV /dev/sdb3 VG vg0 lvm2 [964.00 MB / 964.00 MB free]
PV /dev/sdb6 lvm2 [964.81 MB]
Total: 5 [4.70 GB] / in use: 4 [3.76 GB] / in no VG: 1 [964.81 MB]
————————————————————————————————
三、卷组的创建管理:
1)vgcreate创建卷组:
格式:vgcreate [-s <8M|16M|...>] vg0 /dev/sdb{1,2,3...}
-s:指定扩展块(PE)的大小,默认为4MB;(相当与磁盘上的簇,扩展逻辑卷的基本单位. 后面的值可以是8M 16M 32M 64M .....最多65532个扩展块.

vg0:新创建的卷组的名字.
/dev/sdb{1,2,3...}:需要的物理卷可以写多个;
————————————————————————————————
[root@station1 ~]# vgcreate vg0 /dev/sdb{1,2,3}
Volume group "vg0" successfully created
————————————————————————————————
2)vgdisplay查看各个卷组的详细参数:
格式:vgdisplay /dev/vg0
————————————————————————————————
[root@station1 ~]# vgdisplay /dev/vg0
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 1
VG Access read/write
VG Status resizable
Cur PV 3
Act PV 3
VG Size 2.82 GB
PE Size 4.00 MB //扩展快大小 默认4MB
Total PE 723
Alloc PE / Size 0 / 0
Free PE / Size 723 / 2.82 GB
VG UUID w4q8ET-UBLY-rHwg-2ZVv-NOw4-dd1e-1ABr2f
[root@station1 ~]# vgcreate -s 16M vg1 /dev/sdb{5,6,7}
Volume group "vg1" successfully created
[root@station1 ~]# vgdisplay /dev/vg1
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 1
VG Access read/write
VG Status resizable
Cur PV 3
Act PV 3
VG Size 2.81 GB
PE Size 16.00 MB //指定扩展块大小为16MB
Total PE 180
Alloc PE / Size 0 / 0
Free PE / Size 180 / 2.81 GB
VG UUID x97eh2-JYxW-4Ygh-5axx-TquS-0vxR-YdFyJ1
———————————————————————————————————
3)vgscan查看卷组的信息:
格式:vgsacn
————————————————————————————————
[root@station1 ~]# vgscan
Found volume group "vg1" using metadata type lvm2
Found volume group "vg0" using metadata type lvm2

—————————————————————————————————
4)vgreduce缩小卷组:把物理卷重卷组中删除.
格式:vgreduce vg0 /dev/sdb3
——————————————————————————————————
[root@station1 ~]# vgreduce vg0 /dev/sdb3
Removed "/dev/sdb3" from volume group "vg0"
——————————————————————————————————
4)vgextend扩展卷组:把某个物理卷添加到卷组中.
格式:vgextend vg0 /dev/sdb2 将物理卷/dev/sdb2添加到vg0卷组 
——————————————————————————————————
[root@station1 ~]# vgextend vg0 /dev/sdb3
Volume group "vg0" successfully extended
——————————————————————————————————
5)vgremove删除卷组:
格式:vgremove /dev/vg1
——————————————————————————————————
[root@station1 ~]# pvscan
PV /dev/sdb7 VG vg1 lvm2 [960.00 MB / 960.00 MB free]
PV /dev/sdb5 VG vg1 lvm2 [960.00 MB / 960.00 MB free]
PV /dev/sdb6 VG vg1 lvm2 [960.00 MB / 960.00 MB free]
PV /dev/sdb1 VG vg0 lvm2 [964.00 MB / 964.00 MB free]
PV /dev/sdb2 VG vg0 lvm2 [964.00 MB / 964.00 MB free]
PV /dev/sdb3 VG vg0 lvm2 [964.00 MB / 964.00 MB free]
Total: 6 [5.64 GB] / in use: 6 [5.64 GB] / in no VG: 0 [0 ]
[root@station1 ~]# vgremove /dev/vg1
Volume group "vg1" successfully removed
[root@station1 ~]# pvscan
PV /dev/sdb1 VG vg0 lvm2 [964.00 MB / 964.00 MB free]
PV /dev/sdb2 VG vg0 lvm2 [964.00 MB / 964.00 MB free]
PV /dev/sdb3 VG vg0 lvm2 [964.00 MB / 964.00 MB free]
PV /dev/sdb5 lvm2 [964.81 MB]
PV /dev/sdb6 lvm2 [964.81 MB]
PV /dev/sdb7 lvm2 [964.81 MB]

Total: 6 [5.65 GB] / in use: 3 [2.82 GB] / in no VG: 3 [2.83 GB]
——————————————————————————————————
 

你可能感兴趣的:(卷管理)