Resize LXC DISK on Proxmox

Drthrax74

Active Member
Apr 22, 2019
33
2
28
33
Hello,
I have an 8 GB container which was created under LXC but I cannot resize it so that it is smaller. I want it to be 5 GB.

I also install Proxmox in EXT4 without ZFS support.






1587744507368.png


Code:
root@Proxmox:~# pct resize 105 rootfs 3G
unable to shrink disk size
 

Attachments

  • 1587744479653.png
    1587744479653.png
    116.9 KB · Views: 40
Hi,

shrinking a disk must be done manually.
You can loose your data so I recommand you to make a backup before.
first, shrink the fs in your container.
resize2fs will help you.
The next step would be to shrink the lv.
 
Hi,

shrinking a disk must be done manually.
You can loose your data so I recommand you to make a backup before.
first, shrink the fs in your container.
resize2fs will help you.
The next step would be to shrink the lv.

Could you please elaborate on this, or better yet - point to some pve-documentation on decreasing disk size?
 
Nevermind, found out how.
Documenting it here for posterity. :)

On your proxmox node, do this.

List the containers:
pct list

Stop the particular container you want to resize:
pct stop 999

Find out it's path on the node:
lvdisplay | grep "LV Path\|LV Size"

For good measure one can run a file system check:
e2fsck -fy /dev/pve/vm-999-disk-0

Resize the file system:
resize2fs /dev/pve/vm-999-disk-0 10G

Resize the local volume
lvreduce -L 10G /dev/pve/vm-999-disk-0

Edit the container's conf, look for the rootfs line and change accordingly:
nano /etc/pve/lxc/999.conf

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

Start it:
pct start 999

Enter it and check the new size:
pct enter 999
df -h
 
Hello,

First of all thank you for your good advice, It would be worth making scripts to do the actions in an automated way.
 
Last edited:
Hello,

First of all thank you for your good advice, It would be worth making scripts to do the actions in an automated way.

From my personal point of view scripted disk reductions are iffy, as things may go wrong.
I prefer to do this manually and reviewing each step before I continue to the next step.

This is Dangerous Stuff(tm). :)
 
  • Like
Reactions: Darkk
Nevermind, found out how.
Documenting it here for posterity. :)

On your proxmox node, do this.

List the containers:
pct list

Stop the particular container you want to resize:
pct stop 999

Find out it's path on the node:
lvdisplay | grep "LV Path\|LV Size"

For good measure one can run a file system check:
e2fsck -fy /dev/pve/vm-999-disk-0

Resize the file system:
resize2fs /dev/pve/vm-999-disk-0 10G

Resize the local volume
lvreduce -L 10G /dev/pve/vm-999-disk-0

Edit the container's conf, look for the rootfs line and change accordingly:
nano /etc/pve/lxc/999.conf

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

Start it:
pct start 999

Enter it and check the new size:
pct enter 999
df -h

Thanks adrian, nice one!
I had a warning after the resize when checking the volume (lvdisplay -v /dev/pve/vm-100-disk-0) that the LV size was larger than allocated:

Code:
WARNING: LV pve/vm-100-disk-0 maps 7.93 GiB while the size is only 6.00 GiB

So I mounted the volume and ran a trim:

Code:
mkdir /tmp/100
mount /dev/pve/vm-100-disk-0 /tmp/100
fstrim -v /tmp/100

Not sure if this is the best way to do it, but it works :)
 
  • Like
Reactions: adrian_vg
Is funny that the wuestion was about LXC resize and not VM resize, also the disk if it is a Ceph one the procedure is something and if it inside lvm-local is comething completly different.

The lazyone works doubled
 
Thanks for the nice description. My pve has btrfs so as hint for others the different file location as it was not so easy to find ;)
Example:
Code:
/var/lib/pve/local-btrfs/images/999/vm-999-disk-0/disk.raw
 
hello
i can do the resize... and it works somehow... but after the lxc containter want start anymore... what can i do
 
Same as you it didn't work when starting the container
you can restore your backup if you have a backup (this is my case)
 

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 your own in 60 seconds.

Buy now!