1 前面说到了LVM的创建,我们发现创建其实是很简单的,下面设想几种情况
现在是如果有其他人需要盘,而我的VG还有容量,那么我只需要从VG中lvcreate一个即可
2 如果VG用完了,我还有硬盘,怎么新增加卷到我的lvm逻辑卷管理器中呢
大致步骤和创建类似
2.1 首先我们需要把盘给设置为lvm卷 fdisk
我分了5G
[email protected]:~# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created
2.2 把pv加入卷组
[email protected]:~# vgextend liulianca_test /dev/sdb2
Volume group "liulianca_test" successfully extended
[email protected]:~# vgdisplay
--- Volume group ---
VG Name liulianca_test
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 14.99 GiB
PE Size 4.00 MiB
Total PE 3838
Alloc PE / Size 256 / 1.00 GiB
Free PE / Size 3582 / 13.99 GiB
VG UUID HQsd1f-XU0o-4rUZ-q60o-KrT2-wMTb-SrTT7n
2.3 lv扩容
扩容前
[email protected]:~# lvdisplay
--- Logical volume ---
LV Path /dev/liulianca_test/lqx
LV Name lqx
VG Name liulianca_test
LV UUID GeZhTn-Tjb5-Fl7L-wZKu-wvcg-agbj-zaddza
LV Write Access read/write
LV Creation host, time liuliancao, 2015-10-26 01:16:37 -0700
LV Status available
# open 0
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:1
扩容
[email protected]:~# lvextend -L +2G /dev/liulianca_test/lqx
Size of logical volume liulianca_test/lqx changed from 1.00 GiB (256 extents) to 3.00 GiB (768 extents).
Logical volume lqx successfully resized
扩容后
[email protected]:~# df -h /dev/mapper/liulianca_test-lqx
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/liulianca_test-lqx 976M 1.3M 924M 1% /lvm_test
[email protected]:~# lvdisplay /dev/liulianca_test/lqx
--- Logical volume ---
LV Path /dev/liulianca_test/lqx
LV Name lqx
VG Name liulianca_test
LV UUID GeZhTn-Tjb5-Fl7L-wZKu-wvcg-agbj-zaddza
LV Write Access read/write
LV Creation host, time liuliancao, 2015-10-26 01:16:37 -0700
LV Status available
# open 1
LV Size 3.00 GiB
Current LE 768
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:1
大家注意到了,还存在不同步的问题,需要执行下面的命令
[email protected]:~# resize2fs /dev/mapper/liulianca_test-lqx
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/mapper/liulianca_test-lqx is mounted on /lvm_test; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/liulianca_test-lqx is now 786432 (4k) blocks long.
再看容量就行了
[email protected]:~# df -h /dev/mapper/liulianca_test-lqx
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/liulianca_test-lqx 3.0G 1.6M 2.8G 1% /lvm_test
当我们对一个挂载分区的估计超过了预期,我们就需要收回一部分磁盘空间,这个时候就需要lvm缩减
2.4 lv缩减
缩减的动作正好和增加相反
[email protected]:~# umount /dev/mapper/liulianca_test-lqx
[email protected]:~# resize2fs -f /dev/mapper/liulianca_test-lqx 2g
resize2fs 1.42.12 (29-Aug-2014)
Resizing the filesystem on /dev/mapper/liulianca_test-lqx to 524288 (4k) blocks.
The filesystem on /dev/mapper/liulianca_test-lqx is now 524288 (4k) blocks long.
[email protected]:~# lvreduce -L 2g /dev/liulianca_test/lqx
WARNING: Reducing active logical volume to 2.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lqx? [y/n]: y
Size of logical volume liulianca_test/lqx changed from 3.00 GiB (768 extents) to 2.00 GiB (512 extents).
Logical volume lqx successfully resized
[email protected]:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lqx liulianca_test -wi-a----- 2.00g