Resizing logic volumes

Alex.g

New Member
Nov 5, 2023
2
0
1
Hi folks!
I apologize if this topic was discussed before but I tried different methods from 3/4 days and followed all instructions and tips found here and elsewhere with no chance to get what I'm trying to do.

I installed Proxmox on a dedicated server to create different VMs for different projects, it's gonna be easier to manage everything, migrate, take snapshots, etc. Everything is working well, Proxmox is well installed with no errors, I created a test VM (Debian 11) and configured the network, installed some packages, etc. Now coming to resize a volume, I'm struggling to find a solution without corrupting another one. My lsblk command gave me the following schema:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 45G 0 disk
├─sda1 8:1 0 487M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 44.5G 0 part
├─pscom--vg-root 254:0 0 8.6G 0 lvm /
├─pscom--vg-var 254:1 0 3.2G 0 lvm /var
├─pscom--vg-swap_1 254:2 0 976M 0 lvm [SWAP]
├─pscom--vg-tmp 254:3 0 628M 0 lvm /tmp
└─pscom--vg-home 254:4 0 31.1G 0 lvm /home
sr0 11:0 1 3.7G 0 rom

I resized the disk by adding 15G, so my lsblk is now:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 487M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 44.5G 0 part
├─pscom--vg-root 254:0 0 8.6G 0 lvm /
├─pscom--vg-var 254:1 0 3.2G 0 lvm /var
├─pscom--vg-swap_1 254:2 0 976M 0 lvm [SWAP]
├─pscom--vg-tmp 254:3 0 628M 0 lvm /tmp
└─pscom--vg-home 254:4 0 31.1G 0 lvm
sr0 11:0 1 3.7G 0 rom

As you can see, 15G was added to sda (now 60G instead of 45)

My main goal is to move 15G from /home to /var or from sda (?) to /var.

Any help is much appreciated.


Thank you,
 
Hi,
as you are using lvm, this should be relatively painless, but not necessarily easy. As with all big filesystem operations, this could destroy your data. Therefore it is strongly recommended to create a backup before you start to do anything. Heck, I've been using linux for the last 10 years and still f**k it up from time to time. Especially the partition you are shrinking could easily be damaged if something goes wrong.

With that being said, here is a guide for shrinking your lvm volume, it explains it better than I probably could:
https://www.rootusers.com/lvm-resize-how-to-decrease-an-lvm-partition/

The /dev/centos/var used in the article, would be something like /dev/mapper/pscom--vg-home in your case.

After that you can expand the lv that is your var paritition, which would look something like this:
Bash:
lvextend -l +100%FREE /dev/mapper/pscom--vg-var
resize2fs /dev/mapper/pscome--vg-var
 
Thank you for the details. I'll give it a try with a second VM.

Meanwhile, I tried something different and it looks to be working (until now). This is what I've done if it could help somebody else:
First step, I mounted a new disk so my lsblk is like:
Before:
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 487M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 79.5G 0 part
├─pscom--vg-root 254:0 0 15.1G 0 lvm /
├─pscom--vg-var 254:1 0 5.3G 0 lvm /var
├─pscom--vg-swap_1 254:2 0 976M 0 lvm [SWAP]
├─pscom--vg-tmp 254:3 0 992M 0 lvm /tmp
└─pscom--vg-home 254:4 0 57.2G 0 lvm /home
sr0 11:0 1 3.7G 0 rom

After:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 487M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 79.5G 0 part
├─pscom--vg-root 254:0 0 15.1G 0 lvm /
├─pscom--vg-var 254:1 0 5.3G 0 lvm /var
├─pscom--vg-swap_1 254:2 0 976M 0 lvm [SWAP]
├─pscom--vg-tmp 254:3 0 992M 0 lvm /tmp
└─pscom--vg-home 254:4 0 57.2G 0 lvm /home
sdb 8:16 0 150G 0 disk
sr0 11:0 1 3.7G 0 rom
As you can see, there is a new sdb with 150G.

Now, I create a physical volume
# /usr/sbin/pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.

Next, extending the volume group:
# /usr/sbin/vgextend pscom-vg /dev/sdb
Volume group "pscom-vg" successfully extended

This is the result of vgs
# /usr/sbin/vgs
VG #PV #LV #SN Attr VSize VFree
pscom-vg 2 5 0 wz--n- <229.52g <150.00g

Now, we need to extend the logical volume (we can set 100%FREE to use all the free space or use something like +120G to add an extra 120G):
# /usr/sbin/lvextend -l +100%FREE /dev/pscom-vg/var
Size of logical volume pscom-vg/var changed from 5.32 GiB (1363 extents) to 155.32 GiB (39762 extents).
Logical volume pscom-vg/var successfully resized.

Once this is done, we need to extend the file system:
# /usr/sbin/resize2fs /dev/pscom-vg/var
resize2fs 1.46.2 (28-Feb-2021)
Filesystem at /dev/pscom-vg/var is mounted on /var; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 20
The filesystem on /dev/pscom-vg/var is now 40716288 (4k) blocks long.

Now, by executing lsblk, this is the result:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 487M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 79.5G 0 part
├─pscom--vg-root 254:0 0 15.1G 0 lvm /
├─pscom--vg-var 254:1 0 155.3G 0 lvm /var
├─pscom--vg-swap_1 254:2 0 976M 0 lvm [SWAP]
├─pscom--vg-tmp 254:3 0 992M 0 lvm /tmp
└─pscom--vg-home 254:4 0 57.2G 0 lvm /home
sdb 8:16 0 150G 0 disk
└─pscom--vg-var 254:1 0 155.3G 0 lvm /var
sr0 11:0 1 3.7G 0 rom

And to double-check with a df -h :
# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 0 3.9G 0% /dev
tmpfs 795M 512K 794M 1% /run
/dev/mapper/pscom--vg-root 15G 870M 14G 7% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda1 470M 49M 397M 11% /boot
/dev/mapper/pscom--vg-tmp 958M 52K 893M 1% /tmp
/dev/mapper/pscom--vg-var 153G 257M 147G 1% /var
/dev/mapper/pscom--vg-home 57G 44K 54G 1% /home
tmpfs 795M 0 795M 0% /run/user/1000

For the ones who are wondering why I'm going with this config, I'm planning to set up a Plesk to easily manage a few hosting accounts, and usually /var (where all website files/contents are stored grows up quickly for what I'm planning to do - I'm migrating these websites from a dedicated server with Debian 8 to a VM under a proxmox setup to easily make backups, snapshots and transferring from VM to VM when necessary.)


Regards,
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!