LVM, or Logical Volume Management, is a storage device management technology that gives users the power to pool and abstract the physical layout of component storage devices for easier and flexible administration. Utilizing the device mapper Linux kernel framework, the current iteration, LVM2, can be used to gather existing storage devices into groups and allocate logical units from the combined space as needed.
First, shut down the container and ensure it’s not running.
pct list
VMID Status Lock Name 100 stopped 100.pve.prado.lt
List out the LVM logical volumes:
lvdisplay | grep "LV Path\|LV Size"
LV Path /dev/pve/swap LV Size 3.62 GiB LV Path /dev/pve/root LV Size 7.25 GiB LV Size 13.00 GiB LV Path /dev/pve/vm-100-disk-0 LV Size 20.00 GiB
Choose the disk you want to resize – you’ll see they’re named by container ID and disk number. For example, /dev/pve/vm-100-disk-0.
Check and fix the file system, just in case:
e2fsck -fy /dev/pve/vm-100-disk-0
e2fsck 1.43.4 (31-Jan-2017) 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/pve/vm-100-disk-0: 24382/1310720 files (0.0% non-contiguous), 268496/5242880 blocks
Resize the file system. It is advisable, at this point, to set this to 10 GB smaller than you actually want it (e.g. 9G when you want 10G):
resize2fs /dev/pve/vm-100-disk-0 9G
2fsck 1.43.4 (31-Jan-2017) 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/pve/vm-100-disk-0: 24382/1310720 files (0.0% non-contiguous), 268496/5242880 blocks root@pve:~# resize2fs /dev/pve/vm-100-disk-0 9G resize2fs 1.43.4 (31-Jan-2017) Resizing the filesystem on /dev/pve/vm-100-disk-0 to 2359296 (4k) blocks. The filesystem on /dev/pve/vm-100-disk-0 is now 2359296 (4k) blocks long.
Resize the LVM LV to the actual size you want it to be:
lvreduce -L 10G /dev/pve/vm-100-disk-0
Resize the file system to fill the LVM LV:
resize2fs /dev/pve/vm-100-disk-0
Finally, edit the configuration for the container such that Proxmox reports the correct size for the disk. You will find this at /etc/pve/lxc/100.conf where 100 is your container ID.
Before changes:
arch: amd64 cores: 1 hostname: 100.pve.prado.lt memory: 512 net0: name=eth0,bridge=vmbr0,firewall=1,hwaddr=AE:0B:58:33:E6:F4,ip=dhcp,ip6=dhcp,type=veth ostype: debian rootfs: local-lvm:vm-100-disk-0,size=20G swap: 512 unprivileged: 1
After changes:
arch: amd64 cores: 1 hostname: 100.pve.prado.lt memory: 512 net0: name=eth0,bridge=vmbr0,firewall=1,hwaddr=AE:0B:58:33:E6:F4,ip=dhcp,ip6=dhcp,type=veth ostype: debian rootfs: local-lvm:vm-100-disk-0,size=10G swap: 512 unprivileged: 1
You can now start your container and check the disks’ sizes:
pct start 100 pct enter 100 df -h
Filesystem Size Used Avail Use% Mounted on /dev/mapper/pve-vm--100--disk--0 9.8G 592M 8.7G 7% / none 492K 0 492K 0% /dev udev 1.9G 0 1.9G 0% /dev/tty tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs 2.0G 8.1M 2.0G 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup