lv的最大容量和PE的大小有关,每个lv的容量PE x 65536,默认pe=4M,所以最大只有256G。
已设置好的pe大小,之后没法更改。
1、扩展LV容量
a.添加lvm分区(fdisk ---- t ----- l 编号 ----- 8e -----w ---- partprobe)
b.格式分区:mkfs.ext4 /dev/sdb7
c.创建pv物理卷 pvcreate /dev/sdb7
d.把pv添加到vg vgextend lvmvmhard /dev/sdb7
e.扩展lv容量 lvextend -L +2G /dev/lvmvmhard/lvmlv1
f.重设文件系统大小 resize2fs /dev/lvmvmhard/lvmlv1
[root@kvm /]# pvs PV VG Fmt Attr PSize PFree /dev/sdb5 lvmvmhard lvm2 a-- 1.87g 684.00m /dev/sdb6 lvmvmhard lvm2 a-- 2.80g 0 /dev/sdb7 lvm2 a-- 4.67g 4.67g
[root@kvm /]# vgdisplay --- Volume group --- VG Name lvmvmhard System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 4.67 GiB PE Size 4.00 MiB Total PE 1195 Alloc PE / Size 1024 / 4.00 GiB Free PE / Size 171 / 684.00 MiB VG UUID yWRR2f-3SZx-MZnc-gCz1-zwYT-KH3D-FdOiHk
把sdb7添加到 lvmvmhard卷组中
[root@kvm /]# vgextend lvmvmhard /dev/sdb7 Volume group "lvmvmhard" successfully extended
查看vgdisplay,vgsize total pe已改变,增加了不少。
[root@kvm /]# pvs PV VG Fmt Attr PSize PFree /dev/sdb5 lvmvmhard lvm2 a-- 1.87g 684.00m /dev/sdb6 lvmvmhard lvm2 a-- 2.80g 0 /dev/sdb7 lvmvmhard lvm2 a-- 4.66g 4.66g /dev/sdb8 lvm2 a-- 10.00g 10.00g ----------------------------------------------------------- [root@kvm /]# vgdisplay --- Volume group --- VG Name lvmvmhard System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 3 Act PV 3 VG Size 9.33 GiB PE Size 4.00 MiB Total PE 2389 Alloc PE / Size 1024 / 4.00 GiB Free PE / Size 1365 / 5.33 GiB VG UUID yWRR2f-3SZx-MZnc-gCz1-zwYT-KH3D-FdOiHk
使用lvextend 为lvmlv1(lv)扩容。
[root@kvm /]# lvextend -L +2G /dev/lvmvmhard/lvmlv1
Extending logical volume lvmlv1 to 6.00 GiB
Logical volume lvmlv1 successfully resized
df -h lvmlv1还是大小还是原来的,并没有增加。
[root@kvm /]# pvscan PV /dev/sdb5 VG lvmvmhard lvm2 [1.87 GiB / 0 free] PV /dev/sdb6 VG lvmvmhard lvm2 [2.80 GiB / 0 free] PV /dev/sdb7 VG lvmvmhard lvm2 [4.66 GiB / 3.33 GiB free] PV /dev/sdb8 lvm2 [10.00 GiB] Total: 4 [19.34 GiB] / in use: 3 [9.33 GiB] / in no VG: 1 [10.00 GiB] [root@kvm /]# lvdisplay --- Logical volume --- LV Path /dev/lvmvmhard/lvmlv1 LV Name lvmlv1 VG Name lvmvmhard LV UUID Rlx8Lk-mZQU-WniC-Rw9B-OCaW-r2q9-q3KrYL LV Write Access read/write LV Creation host, time kvm, 2014-04-11 21:00:58 +0800 LV Status available # open 1 LV Size 6.00 GiB Current LE 1536 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@kvm /]# vgdisplay --- Volume group --- VG Name lvmvmhard System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 3 Act PV 3 VG Size 9.33 GiB PE Size 4.00 MiB Total PE 2389 Alloc PE / Size 1536 / 6.00 GiB Free PE / Size 853 / 3.33 GiB VG UUID yWRR2f-3SZx-MZnc-gCz1-zwYT-KH3D-FdOiHk [root@kvm /]# [root@kvm /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 117G 11G 100G 10% / tmpfs 242M 76K 242M 1% /dev/shm /dev/mapper/lvmvmhard-lvmlv1 4.0G 167M 3.6G 5% /lvlvm1 /dev/sr0 602M 602M 0 100% /media/GRTMPVOL_CN [root@kvm /]#
[root@kvm /]# resize2fs /dev/lvmvmhard/lvmlv1
使用resize2fs重设大小
[root@kvm /]# resize2fs /dev/lvmvmhard/lvmlv1 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/lvmvmhard/lvmlv1 is mounted on /lvlvm1; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/lvmvmhard/lvmlv1 to 1572864 (4k) blocks. The filesystem on /dev/lvmvmhard/lvmlv1 is now 1572864 blocks long. [root@kvm /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 117G 11G 100G 10% / tmpfs 242M 76K 242M 1% /dev/shm /dev/mapper/lvmvmhard-lvmlv1 6.0G 167M 5.5G 3% /lvlvm1 /dev/sr0 602M 602M 0 100% /media/GRTMPVOL_CN [root@kvm /]#
2、缩小LV容量
a.umount分区 umount /dev/lvmvmhard/lvmlv1
b.调整文件系统大小为5G(即缩小1G空间) resize2fs /dev/lvmvmhard/lvmlv1 5G
c.把lv空间缩小到5G(要和文件系统一样大小) lvreduce -L 5G /dev/lvmvmhard/lvmlv1
d.重新挂载分区 mount /dev/lvmvmhard/lvmlv1 /lvlvm1/
[root@kvm /]# lvdisplay --- Logical volume --- LV Path /dev/lvmvmhard/lvmlv1 LV Name lvmlv1 VG Name lvmvmhard LV UUID Rlx8Lk-mZQU-WniC-Rw9B-OCaW-r2q9-q3KrYL LV Write Access read/write LV Creation host, time kvm, 2014-04-11 21:00:58 +0800 LV Status available # open 1 LV Size 6.00 GiB Current LE 1536 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@kvm /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 117G 11G 100G 10% / tmpfs 242M 76K 242M 1% /dev/shm /dev/mapper/lvmvmhard-lvmlv1 6.0G 167M 5.5G 3% /lvlvm1 /dev/sr0 602M 602M 0 100% /media/GRTMPVOL_CN [root@kvm /]# umount /dev/lvmvmhard/lvmlv1 [root@kvm /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 117G 11G 100G 10% / tmpfs 242M 76K 242M 1% /dev/shm /dev/sr0 602M 602M 0 100% /media/GRTMPVOL_CN [root@kvm /]# resize2fs --help resize2fs 1.41.12 (17-May-2010) resize2fs: invalid option -- '-' Usage: resize2fs [-d debug_flags] [-f] [-F] [-M] [-P] [-p] device [new_size] [root@kvm /]# resize2fs /dev/lvmvmhard/lvmlv1 5GB resize2fs 1.41.12 (17-May-2010) resize2fs: Invalid new size: 5GB [root@kvm /]# resize2fs /dev/lvmvmhard/lvmlv1 5GB resize2fs 1.41.12 (17-May-2010) resize2fs: Invalid new size: 5GB [root@kvm /]# resize2fs /dev/lvmvmhard/lvmlv1 5000MB resize2fs 1.41.12 (17-May-2010) resize2fs: Invalid new size: 5000MB [root@kvm /]# resize2fs /dev/lvmvmhard/lvmlv1 5G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/lvmvmhard/lvmlv1 to 1310720 (4k) blocks. The filesystem on /dev/lvmvmhard/lvmlv1 is now 1310720 blocks long. [root@kvm /]# lvreduce -L 5G /dev/lvmvmhard/lvmlv1 WARNING: Reducing active logical volume to 5.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lvmlv1? [y/n]: y Reducing logical volume lvmlv1 to 5.00 GiB Logical volume lvmlv1 successfully resized [root@kvm /]# mount /dev/lvmvmhard/lvmlv1 /m media/ misc/ mnt/ mytest/ [root@kvm /]# mount /dev/lvmvmhard/lvmlv1 /m media/ misc/ mnt/ mytest/ [root@kvm /]# mount /dev/lvmvmhard/lvmlv1 /l lib/ lib64/ lost+found/ lvlvm1/ [root@kvm /]# mount /dev/lvmvmhard/lvmlv1 /lvlvm1/ [root@kvm /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 117G 11G 100G 10% / tmpfs 242M 76K 242M 1% /dev/shm /dev/sr0 602M 602M 0 100% /media/GRTMPVOL_CN /dev/mapper/lvmvmhard-lvmlv1 5.0G 167M 4.6G 4% /lvlvm1 [root@kvm /]# cd /lvlvm1/ [root@kvm lvlvm1]# ls etc lost+found