This article is adjunct to https://tickets.dominodatalab.com/hc/en-us/articles/6555762877716
The former being more involved with additional steps.
Assume you have 2 PVs mapped to 2 diff VGs which are assigned an LV each:
sdb 8:16 0 8G 0 disk
|-sdb1 8:17 0 2G 0 part
`-sdb2 8:18 0 6G 0 part
[root@localhost ~]# pvscan
PV /dev/sdb1 VG vg1 lvm2 [<2.00 GiB / <2.00 GiB free]
PV /dev/sdb2 VG vg2 lvm2 [<6.00 GiB / <6.00 GiB free]
[root@localhost ~]# vgs -v
VG Attr Ext #PV #LV #SN VSize VFree VG UUID VProfile
vg1 wz--n- 4.00m 1 0 0 <2.00g <2.00g yDW2FC-UjZT-MpyG-Fo3r-PNZM-aFbU-ahZVmD
vg2 wz--n- 4.00m 1 0 0 <6.00g <6.00g GH4JSm-56PK-jUop-SgSr-2hbt-qeds-yehVFW
[root@localhost ~]# lvcreate -n lv1 -l 100%FREE /dev/vg1
WARNING: ext4 signature detected on /dev/vg1/lv1 at offset 1080. Wipe it? [y/n]: y
Wiping ext4 signature on /dev/vg1/lv1.
Logical volume "lv1" created.
[root@localhost ~]# lvcreate -n lv2 -l 100%FREE /dev/vg2
Logical volume "lv2" created.
[root@localhost ~]# lvscan -v
ACTIVE '/dev/vg1/lv1' [<2.00 GiB] inherit
ACTIVE '/dev/vg2/lv2' [<6.00 GiB] inherit
The scenario for this article would be that you one of the LV is almost fully consumed while the other is hardly used :-
/dev/mapper/vg1-lv1 ext4 2.0G 1.7G 181M 91% /lv1
/dev/mapper/vg2-lv2 ext4 5.8G 24M 5.5G 1% /lv2
The primary aim of this article is to achieve the resize without destroying the underlying abstractions, both of these LVs are formatted as ext4 which can be resized. If the filesystem used is something other that ext, like xfs, then you'd have to temporarily store the contents of the LV to another partition (logical or otherwise).
Now we'd shrink lv2 and mount it again, steps to follow :-
umount /dev/mapper/vg2-lv2
e2fsck -f /dev/mapper/vg2-lv2
lvresize -r /dev/vg2/lv2 -L500M
e2fsck -f /dev/mapper/vg2-lv2
mount -t ext4 /dev/mapper/vg2-lv2 /lv2
[root@localhost /]# umount /dev/mapper/vg2-lv2
[root@localhost /]# e2fsck -f /dev/mapper/vg2-lv2
e2fsck 1.42.9 (28-Dec-2013)
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/mapper/vg2-lv2: 11/393216 files (0.0% non-contiguous), 63598/1571840 blocks
[root@localhost /]# lvresize -r /dev/vg2/lv2 -L500M
fsck from util-linux 2.23.2
/dev/mapper/vg2-lv2: clean, 11/393216 files, 63598/1571840 blocks
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/vg2-lv2 to 128000 (4k) blocks.
The filesystem on /dev/mapper/vg2-lv2 is now 128000 blocks long.
Size of logical volume vg2/lv2 changed from <6.00 GiB (1535 extents) to 500.00 MiB (125 extents).
Logical volume vg2/lv2 successfully resized.
[root@localhost /]# e2fsck -f /dev/mapper/vg2-lv2
e2fsck 1.42.9 (28-Dec-2013)
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/mapper/vg2-lv2: 11/32768 files (0.0% non-contiguous), 37137/128000 blocks
[root@localhost /]# mount -t ext4 /dev/mapper/vg2-lv2 /lv2
[root@localhost /]# df -ThP
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg1-lv1 ext4 2.0G 1.7G 181M 91% /lv1
/dev/mapper/vg2-lv2 ext4 364M 9.1M 320M 3% /lv2
[root@localhost /]# lvs -v
LV VG #Seg Attr LSize Maj Min KMaj KMin Pool Origin Data% Meta% Move Cpy%Sync Log Convert LV UUID LProfile
lv1 vg1 1 -wi-ao---- <2.00g -1 -1 253 2 cVPdvl-Ca4o-s3XF-vV7e-zfKb-Yh0i-cOFlcz
lv2 vg2 1 -wi-ao---- 500.00m -1 -1 253 3 JJ16DT-6w7p-ZUce-RqxC-8WUb-KVWA-jtVAUz
And as we can see below using pvs -v, the space has been released
[root@localhost /]# pvs -v
PV VG Fmt Attr PSize PFree DevSize PV UUID
/dev/sdb1 vg1 lvm2 a-- <2.00g 0 <2.00g KvziZ8-1gdC-kew5-oDM1-bJVB-jy6V-tQl7Xq
/dev/sdb2 vg2 lvm2 a-- <6.00g <5.51g 6.00g YMnwgX-mLh5-Gf9g-6uIP-JeHc-8mFC-PNRY4o
At this stage, if the PVs were part of the same VG we could have reclaimed the free space and mount it again but in our case we'd first merge the VGs and then perform the rest
vgchange -an /dev/vg1
vgmerge vg0 vg1
[root@localhost /]# umount /dev/mapper/vg2-lv2
[root@localhost /]# vgchange -an /dev/vg2
0 logical volume(s) in volume group "vg2" now active
[root@localhost /]# vgmerge vg1 vg2
Volume group "vg2" successfully merged into "vg1"
[root@localhost /]# vgs -v
VG Attr Ext #PV #LV #SN VSize VFree VG UUID VProfile
vg1 wz--n- 4.00m 2 2 0 7.99g <5.51g yDW2FC-UjZT-MpyG-Fo3r-PNZM-aFbU-ahZVmD
[[root@localhost /]# pvscan
PV /dev/sdb1 VG vg1 lvm2 [<2.00 GiB / 0 free]
PV /dev/sdb2 VG vg1 lvm2 [<6.00 GiB / <5.51 GiB free]
Now we can swap the volumes, I tried moving sdb2 to sdb1 first but there weren't any extents available so moved sdb1 to sdb2 then sdb2 to sdb1 again, as per :-
root@localhost /]# pvmove -n lv2 /dev/sdb2 /dev/sdb1
WARNING: No free extents on physical volume "/dev/sdb1".
No specified PVs have space available.
[root@localhost /]# pvmove -n lv1 /dev/sdb1 /dev/sdb2
/dev/sdb1: Moved: 0.78%
/dev/sdb1: Moved: 100.00%
[root@localhost /]# pvmove -n lv2 /dev/sdb2 /dev/sdb1
/dev/sdb2: Moved: 1.60%
/dev/sdb2: Moved: 100.00%
The remaining steps are to basically split the VG and extend the LV :-
[root@localhost /]# vgsplit vg1 vg2 /dev/sdb2
New volume group "vg2" successfully split from "vg1"
[root@localhost /]# lvresize -r -l 100%FREE /dev/mapper/vg1-lv1
Size of logical volume vg1/lv1 changed from <2.00 GiB (511 extents) to 4.00 GiB (1024 extents).
Logical volume vg1/lv1 successfully resized.
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/vg1-lv1 is mounted on /lv1; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mapper/vg1-lv1 is now 1048576 blocks long.
[root@localhost /]# lvchange -ay /dev/vg2/lv2
[root@localhost /]# lvresize -r -l 100%FREE /dev/mapper/vg2-lv2
fsck from util-linux 2.23.2
/dev/mapper/vg2-lv2: 11/32768 files (0.0% non-contiguous), 37137/128000 blocks
Size of logical volume vg2/lv2 changed from 500.00 MiB (125 extents) to <1.51 GiB (386 extents).
Logical volume vg2/lv2 successfully resized.
[root@localhost /]# df -ThP | grep lv
/dev/mapper/vg1-lv1 ext4 4.0G 1.7G 2.1G 45% /lv1
Comments
0 comments
Please sign in to leave a comment.