- 论坛徽章:
- 0
|
首先清楚一下LVM三个名词:PV-物理卷、 VG-卷组、 LV-逻辑卷
------------------------------------------------------------------------------
[root@myserver root]# fdisk -l /dev/sda --首先创建三个物理卷(这里我建好了,分别是sda5、sda6、sda7),创建为Linux LVM格式的,它的id是8e
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 382 3068383+ 83 Linux
/dev/sda2 383 764 3068415 83 Linux
/dev/sda3 765 802 305235 82 Linux swap
/dev/sda4 803 1044 1943865 5 Extended
/dev/sda5 803 815 104391 8e Linux LVM
/dev/sda6 816 828 104391 8e Linux LVM
/dev/sda7 829 841 104391 8e Linux LVM
[root@myserver root]# pvcreate /dev/sda[5-7] --初始化这三个物理卷
pvcreate -- physical volume "/dev/sda5" successfully created
pvcreate -- physical volume "/dev/sda6" successfully created
pvcreate -- physical volume "/dev/sda7" successfully created
[root@myserver root]# vgscan --马上要创建卷组,不过记得第一次创建卷组前要执行vgscan
vgscan -- reading all physical volumes (this may take a while...)
vgscan -- "/etc/lvmtab" and "/etc/lvmtab.d" successfully created
vgscan -- WARNING: This program does not do a VGDA backup of your volume group
[root@myserver root]# vgcreate vg1 /dev/sda5 /dev/sda6 --创建卷组vg1,它包含两个物理卷sda5和sda6
vgcreate -- INFO: using default physical extent size 4 MB
vgcreate -- INFO: maximum logical volume size is 255.99 Gigabyte
vgcreate -- doing automatic backup of volume group "vg1"
vgcreate -- volume group "vg1" successfully created and activated
[root@myserver root]# vgdisplay vg1 --查看卷组vg1的信息
--- Volume group ---
VG Name vg1
VG Access read/write
VG Status available/resizable
VG # 0
MAX LV 256
Cur LV 0
Open LV 0
MAX LV Size 255.99 GB --扩展块为4MB时,逻辑卷最大支持255.99GB,可以通过定制扩展块大小修改它
Max PV 256
Cur PV 2
Act PV 2
VG Size 192 MB --当前卷组空间大小(VG Size=PE Size*Total PE)
PE Size 4 MB --最小扩展块(这里默认,可定制)
Total PE 48 --目前该卷组公分配了48个扩展块
Alloc PE / Size 0 / 0 --已经分配
Free PE / Size 48 / 192 MB --剩余分配
VG UUID RVsKN4-Qx0K-OgFY-wCkX-qGKw-Y5BA-YtpEEd
[root@myserver root]# lvcreate -n lv1 -L 20M vg1 --在卷组vg1上创建逻辑卷lv1,-n(命名),-L (制定逻辑卷大小),-L也可替换成-l(扩展块个数)
lvcreate -- doing automatic backup of "vg1"
lvcreate -- logical volume "/dev/vg1/lv1" successfully created
[root@myserver root]# mkfs.ext3 /dev/vg1/lv1 --对逻辑卷lv1进行格式化,然后才能进行挂载使用
mke2fs 1.32 (09-Nov-2002)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
--
--
--
[root@myserver root]# mount /dev/vg1/lv1 /mnt/lv1 --挂在到/mnt/lv1,就可以使用了
[root@myserver root]# lvdisplay /dev/vg1/lv1 --查看逻辑卷lv1的信息
--- Logical volume ---
LV Name /dev/vg1/lv1
VG Name vg1
LV Write Access read/write
LV Status available
LV # 1
# open 0
LV Size 20 MB --大小,注意逻辑卷的大小只能是扩展块的倍数
Current LE 5 --当前扩展块倍数
Allocated LE 5
Allocation next free
Read ahead sectors 1024
Block device 58:0
因为逻辑卷lv1是从卷组vg1上分出来的,这时我们再查看一下vg1,看有什么变化
[root@myserver root]# vgdisplay vg1
--- Volume group ---
VG Name vg1
VG Access read/write
VG Status available/resizable
VG # 0
MAX LV 256
Cur LV 1
Open LV 0
MAX LV Size 255.99 GB
Max PV 256
Cur PV 2
Act PV 2
VG Size 192 MB
PE Size 4 MB
Total PE 48
Alloc PE / Size 5 / 20 MB --已经分出了5个扩展块,大小是4MB*5=20MB
Free PE / Size 43 / 172 MB --剩余可分的扩展块和总计大小
VG UUID RVsKN4-Qx0K-OgFY-wCkX-qGKw-Y5BA-YtpEEd
[root@myserver root]# lvscan --查看系统活动的逻辑卷,这里我只建了一个/dev/vg1/lv1
lvscan -- ACTIVE "/dev/vg1/lv1" [20 MB]
lvscan -- 1 logical volumes with 20 MB total in 1 volume group
lvscan -- 1 active logical volumes
[root@myserver root]# e2fsadm -L +20M /dev/vg1/lv1 --将lv1容量增加20M,同理缩小容量就-20M;这里-L也可替换成-l,‘-l 10’和该条命令作用一致;
记得调整逻辑卷前要先卸掉啊;调整后可确认查看一下大小的变化
e2fsck 1.32 (09-Nov-2002)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg1/lv1: 11/5136 files (0.0% non-contiguous), 1696/20480 blocks
lvextend -- extending logical volume "/dev/vg1/lv1" to 40 MB
lvextend -- doing automatic backup of volume group "vg1"
lvextend -- logical volume "/dev/vg1/lv1" successfully extended
resize2fs 1.32 (09-Nov-2002)
Begin pass 1 (max = 2)
Extending the inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/vg1/lv1 is now 40960 blocks long.
e2fsadm -- ext2fs in logical volume /dev/vg1/lv1 successfully extended to 40 MB
[root@myserver root]# pvscan --查看当前所有物理卷的状态,目前只有sda5和sda6在工作
pvscan -- reading all physical volumes (this may take a while...)
pvscan -- ACTIVE PV "/dev/sda5" of VG "vg1" [96 MB / 56 MB free]
pvscan -- ACTIVE PV "/dev/sda6" of VG "vg1" [96 MB / 96 MB free]
pvscan -- inactive PV "/dev/sda7" is in no VG [101.94 MB]
pvscan -- total: 3 [305.83 MB] / in use: 2 [203.89 MB] / in no VG: 1 [101.94 MB]
You have new mail in /var/spool/mail/root
[root@myserver root]# vgextend vg1 /dev/sda7 --再增加一个物理卷sda7到卷组,是其容量变大
vgextend -- INFO: maximum logical volume size is 255.99 Gigabyte
vgextend -- doing automatic backup of volume group "vg1"
vgextend -- volume group "vg1" successfully extended
刚才是增加一个物理卷到卷组,删除一个物理卷的话得先把该物理卷内的数据移动其他物理卷上,然后再移除该物理卷
[root@myserver root]# pvmove /dev/sda5 --把该物理卷内的数据移动其他物理卷上
pvmove -- moving physical extents in active volume group "vg1"
pvmove -- WARNING: if you lose power during the move you may need
to restore your LVM metadata from backup!
pvmove -- do you want to continue? [y/n] y --确定
/dev/vg1/group::/dev/vg1/lv1: 0805 8576, 0806 8576
/dev/vg1/group::/dev/vg1/lv1: 0805 16768, 0806 16768
/dev/vg1/group::/dev/vg1/lv1: 0805 24960, 0806 24960
/dev/vg1/group::/dev/vg1/lv1: 0805 33152, 0806 33152
/dev/vg1/group::/dev/vg1/lv1: 0805 41344, 0806 41344
/dev/vg1/group::/dev/vg1/lv1: 0805 49536, 0806 49536
/dev/vg1/group::/dev/vg1/lv1: 0805 57728, 0806 57728
/dev/vg1/group::/dev/vg1/lv1: 0805 65920, 0806 65920
/dev/vg1/group::/dev/vg1/lv1: 0805 74112, 0806 74112
/dev/vg1/group::/dev/vg1/lv1: 0805 82304, 0806 82304
pvmove -- doing automatic backup of volume group "vg1"
pvmove -- 10 extents of physical volume "/dev/sda5" successfully moved
[root@myserver root]# vgreduce vg1 /dev/sda5 --然后再移除该物理卷,和vgextend功能相反
vgreduce -- doing automatic backup of volume group "vg1"
vgreduce -- volume group "vg1" successfully reduced by physical volume:
vgreduce -- /dev/sda5
[root@myserver root]# pvscan --再次查看当前所有物理卷的状态,sda5已经不再卷组内了
pvscan -- reading all physical volumes (this may take a while...)
pvscan -- inactive PV "/dev/sda5" is in no VG [101.94 MB]
pvscan -- ACTIVE PV "/dev/sda6" of VG "vg1" [96 MB / 56 MB free]
pvscan -- ACTIVE PV "/dev/sda7" of VG "vg1" [96 MB / 96 MB free]
pvscan -- total: 3 [305.83 MB] / in use: 2 [203.89 MB] / in no VG: 1 [101.94 MB]
逻辑卷有一个有趣且实用的快照功能,拿来做备份还是很合适的,不过一经挂在就不能随意卸载,否则会停止备份工作
[root@myserver root]# lvcreate -s -L 40M -n snap /dev/vg1/lv1 --创建以lv1为快照对象的大小为40M的快照逻辑卷,不需要格式化,可直接挂在使用
lvcreate -- INFO: using default snapshot chunk size of 64 KB for "/dev/vg1/snap"
lvcreate -- doing automatic backup of "vg1"
lvcreate -- logical volume "/dev/vg1/snap" successfully created
删除逻辑卷和卷组
1,删除的顺序不能乱,先删除逻辑卷(注意有快照存在的情况下,先删除快照逻辑卷)、后删除卷组,这样物理卷才会全部被释放出来
2,卷组不能直接删除,得先将其设置为休眠状态,才可删
[root@myserver root]# lvscan --先扫描一下都有哪些逻辑卷,当前有两个逻辑卷,其中以个快照snap
lvscan -- ACTIVE Original "/dev/vg1/lv1" [40 MB]
lvscan -- ACTIVE Snapshot "/dev/vg1/snap" [39.38 MB] of /dev/vg1/lv1
lvscan -- 2 logical volumes with 79.38 MB total in 2 volume groups
lvscan -- 2 active logical volumes
[root@myserver root]# lvremove /dev/vg1/snap --删除快照逻辑卷
lvremove -- do you really want to remove "/dev/vg1/snap"? [y/n]: y --确定删除
lvremove -- doing automatic backup of volume group "vg1"
lvremove -- logical volume "/dev/vg1/snap" successfully removed
[root@myserver root]# lvremove /dev/vg1/lv1 --删除逻辑卷lv1
lvremove -- do you really want to remove "/dev/vg1/lv1"? [y/n]: y --确定删除
lvremove -- doing automatic backup of volume group "vg1"
lvremove -- logical volume "/dev/vg1/lv1" successfully removed
[root@myserver root]# vgchange -an vg1 --将vg1设置为休眠状态
vgchange -- volume group "vg1" successfully deactivated
[root@myserver root]# vgremove vg1 --删除卷组vg1
vgremove -- volume group "vg1" successfully removed
[root@myserver root]# pvscan --这时所有物理卷都不属于任何卷组,都是‘自由’的了
pvscan -- reading all physical volumes (this may take a while...)
pvscan -- inactive PV "/dev/sda5" is in no VG [101.94 MB]
pvscan -- inactive PV "/dev/sda6" is in no VG [101.94 MB]
pvscan -- inactive PV "/dev/sda7" is in no VG [101.94 MB]
pvscan -- total: 3 [305.83 MB] / in use: 0 [0] / in no VG: 3 [305.83 MB]
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/91826/showart_2050064.html |
|