Skip to main content
  1. Blog/

How to resize an LVM

·869 words·5 mins
Table of Contents

What I want to do
#

Because I’m migrating my VMs to a different sotrage, I have to temporarily change the partition sizes.

I am using a 2TB LVM over two 1TB disks.

I want to reduce the LVM size to 1 TB and then remove one of the disks.

See the current status
#

  • Logical Volume (LV)
  • Physical Volume (PV)
  • Volume Group (VG)
lvdisplay  
 --- Logical volume ---  
 LV Path                /dev/syn-vg/syn-lv  
 LV Name                syn-lv  
 VG Name                syn-vg  
 LV UUID                cldKUd-ZnSw-Hlj2-daUe-IVzU-eJbh-gi1DLG  
 LV Write Access        read/write  
 LV Creation host, time media2, 2025-03-11 21:55:57 +0000  
 LV Status              available  
 # open                 1  
 LV Size                <2.00 TiB  
 Current LE             524286  
 Segments               2  
 Allocation             inherit  
 Read ahead sectors     auto  
 - currently set to     256  
 Block device           252:1  
     
 --- Logical volume ---  
 LV Path                /dev/ubuntu-vg/ubuntu-lv  
 LV Name                ubuntu-lv  
 VG Name                ubuntu-vg  
 LV UUID                7paQME-ugiW-HQBI-vcqr-RrFQ-GeTN-5NiV4e  
 LV Write Access        read/write  
 LV Creation host, time ubuntu-server, 2025-03-11 21:28:23 +0000  
 LV Status              available  
 # open                 1  
 LV Size                <62.00 GiB  
 Current LE             15871  
 Segments               1  
 Allocation             inherit  
 Read ahead sectors     auto  
 - currently set to     256  
 Block device           252:0  
pvs  
 PV         VG        Fmt  Attr PSize     PFree  
 /dev/sda3  ubuntu-vg lvm2 a--    <62.00g    0    
 /dev/sdb   syn-vg    lvm2 a--  <1024.00g    0    
 /dev/sdc   syn-vg    lvm2 a--  <1024.00g    0    
pvdisplay  
 --- Physical volume ---  
 PV Name               /dev/sdb  
 VG Name               syn-vg  
 PV Size               1.00 TiB / not usable 4.00 MiB  
 Allocatable           yes (but full)  
 PE Size               4.00 MiB  
 Total PE              262143  
 Free PE               0  
 Allocated PE          262143  
 PV UUID               tBnRIW-Ktpb-Ubwq-S0Vu-Hof9-XZMw-gIMkSg  
     
 --- Physical volume ---  
 PV Name               /dev/sdc  
 VG Name               syn-vg  
 PV Size               1.00 TiB / not usable 4.00 MiB  
 Allocatable           yes (but full)  
 PE Size               4.00 MiB  
 Total PE              262143  
 Free PE               0  
 Allocated PE          262143  
 PV UUID               VpIF12-PYbu-XUgg-jYQt-iad7-iwli-JIXnGN  
     
 --- Physical volume ---  
 PV Name               /dev/sda3  
 VG Name               ubuntu-vg  
 PV Size               <62.00 GiB / not usable 0      
 Allocatable           yes (but full)  
 PE Size               4.00 MiB  
 Total PE              15871  
 Free PE               0  
 Allocated PE          15871  
 PV UUID               JY8CeY-Um2G-DBx9-PjN1-2l67-RDmT-1MC0bY

resize the LVM
#

I am purposefully going to use 1000G instead of 1T, to be 100% sure that it will fit on my 1 TiB disk. We also want to resize the filesystem with the following command:

lvreduce --resizefs -L 1000G /dev/syn-vg/syn-lv  

unmount the device
#

Do you want to unmount "/mnt/syn" ? [Y|n] y  
umount: /mnt/syn: target is busy.  
fsadm: Cannot proceed with mounted filesystem "/mnt/syn".  
 /usr/sbin/fsadm failed: 1  
 Filesystem resize failed.

find the processes that are using the mount and stop them
#

df -h
Filesystem                         Size  Used Avail Use% Mounted on  
tmpfs                              795M  1.3M  793M   1% /run  
/dev/mapper/ubuntu--vg-ubuntu--lv   61G   15G   44G  25% /  
tmpfs                              3.9G     0  3.9G   0% /dev/shm  
tmpfs                              5.0M     0  5.0M   0% /run/lock  
/dev/sda2                          2.0G  189M  1.7G  11% /boot  
/dev/mapper/syn--vg-syn--lv        2.0T  158G  1.8T   9% /mnt/syn  
overlay                             61G   15G   44G  25% /var/lib/docker/overlay2/[...]/merged  
overlay                             61G   15G   44G  25% /var/lib/docker/overlay2/[...]/merged  
tmpfs                              795M   20K  795M   1% /run/user/1000
lsof | grep 'mnt/syn'

You will see the processes or services using the mount and can stop them using systemctl stop.

Then run the resize command again:

lvreduce --resizefs -L 1000G /dev/syn-vg/syn-lv  

This can take some time. For me it was over 30 minutes.

Do you want to unmount "/mnt/syn" ? [Y|n] y  
fsck from util-linux 2.39.3  
/dev/mapper/syn--vg-syn--lv: Inode 55574911 extent tree (at level 1) could be shorter.  IGNORED.  
/dev/mapper/syn--vg-syn--lv: 988/134217728 files (19.7% non-contiguous), 49963842/536868864 blocks  
resize2fs 1.47.0 (5-Feb-2023)  
Resizing the filesystem on /dev/mapper/syn--vg-syn--lv to 262144000 (4k) blocks.  
 The filesystem on /dev/mapper/syn--vg-syn--lv is now 262144000 (4k) blocks long.  
  
 Size of logical volume syn-vg/syn-lv changed from <2.00 TiB (524286 extents) to 1000.00 GiB (256000 extents).  
 Logical volume syn-vg/syn-lv successfully resized.

Now I want to move everything to the first disk.

pvdisplay
--- Physical volume ---  
 PV Name               /dev/sdb  
 VG Name               syn-vg  
 PV Size               1.00 TiB / not usable 4.00 MiB  
 Allocatable           yes    
 PE Size               4.00 MiB  
 Total PE              262143  
 Free PE               6143  
 Allocated PE          256000  
 PV UUID               tBnRIW-Ktpb-Ubwq-S0Vu-Hof9-XZMw-gIMkSg  
     
 --- Physical volume ---  
 PV Name               /dev/sdc  
 VG Name               syn-vg  
 PV Size               1.00 TiB / not usable 4.00 MiB  
 Allocatable           yes    
 PE Size               4.00 MiB  
 Total PE              262143  
 Free PE               262143  
 Allocated PE          0  
 PV UUID               VpIF12-PYbu-XUgg-jYQt-iad7-iwli-JIXnGN
pvs
 PV         VG        Fmt  Attr PSize     PFree       
 /dev/sda3  ubuntu-vg lvm2 a--    <62.00g        0    
 /dev/sdb   syn-vg    lvm2 a--  <1024.00g   <24.00g  
 /dev/sdc   syn-vg    lvm2 a--  <1024.00g <1024.00g

You can see that /dev/sdc already is completely free. In case it is not free in your case, you can use the following command:

pvmove /dev/sdc

And again pvdisplay to verify.

Then I can remove the disk

pvremove /dev/sdc

Check the LV size using lvdisplay again and it is 1000 GiB:

--- Logical volume ---  
 LV Path                /dev/syn-vg/syn-lv  
 LV Name                syn-lv  
 VG Name                syn-vg  
 LV UUID                cldKUd-ZnSw-Hlj2-daUe-IVzU-eJbh-gi1DLG  
 LV Write Access        read/write  
 LV Creation host, time media2, 2025-03-11 21:55:57 +0000  
 LV Status              available  
 # open                 1  
 LV Size                1000.00 GiB  
 Current LE             256000  
 Segments               1  
 Allocation             inherit  
 Read ahead sectors     auto  
 - currently set to     256  
 Block device           252:1

remove the vg from the disk
#

first remove the group

vgreduce syn-vg /dev/sdc  
 Removed "/dev/sdc" from volume group "syn-vg"

then wipe the disk from any remaining signatures

pvremove /dev/sdc  
 Labels on physical volume "/dev/sdc" successfully wiped.

And check using pvs or pvdisplay

pvs  
 PV         VG        Fmt  Attr PSize     PFree     
 /dev/sda3  ubuntu-vg lvm2 a--    <62.00g      0    
 /dev/sdb   syn-vg    lvm2 a--  <1024.00g <24.00g
Bjarne
Author
Bjarne
I’m a network engineer from Germany and like to tinker with my homelab