How to resize LXC Disk on Proxmox

Ever ran into the situation where you found out that the original estimate for and LCX container disk-size exceeds reality. The question is how to decrease the size of the allocated disk space.

This works as follows:

First connect to the Proxmox node. This can be done using the proxmox GUI selecting the node and >_ Shell. An other way is connnect over ssh using putty or other. After logging in with your account and password, do the following:

First you list the containers and determine the right one.

pct list

Now you can stop the LXC container using:

pct stop 123

Another way to determine the right container volume is to check the LXC settings in proxmox. Next is to determine the right path to the volume:

lvdisplay | grep "LV Path\|LV Size"

To make sure the volume is in good shape you canrun a file system check using:

e2fsck -fy /dev/pve/vm-123-disk-0

When the volume is in good shape we can start with the shrinking of the filesystem. Say you have a 32GB volume and you want to make it 8GB, you should use:

resize2fs /dev/pve/vm-123-disk-0 8G

After this you can resize the local volume:

lvreduce -L 8G /dev/pve/vm-123-disk-0

After the reducing of the volume it’s time to modify the container’s configuration. We use nano to modify the file and change the size value to 8GB.

nano /etc/pve/lxc/123.conf

Locate the rootfs: entry and change it to the requested size:

rootfs: local-lvm:vm-123-disk-0,size=32G ->

rootfs: local-lvm:vm-123-disk-0,size=8G

arch: amd64
cores: 1
features: nesting=1
hostname: netdata
memory: 1024
net0: name=eth0,bridge=vmbr0,firewall=1,hwaddr=xx:xx:xx:xx:xx:xx,ip=dhcp,type=v>
ostype: debian
rootfs: local-lvm:vm-123-disk-0,size=8G
searchdomain: 192.168.1.100
swap: 512
unprivileged: 1

Now the volume needs to start.

pct start 123

For the final check you can enter the lxc container ..

pct enter 123

and check the file size..

dh -h

Sources:

https://forum.proxmox.com/threads/resize-lxc-disk-on-proxmox.68901/