Resize LXC DISK on Proxmox

Drthrax74

Member
Apr 22, 2019
23
1
8
32
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: 16

wolfgang

Proxmox Staff Member
Oct 1, 2014
6,496
493
103
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.
 

adrian_vg

Member
Mar 8, 2020
65
9
13
Sweden
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?
 

adrian_vg

Member
Mar 8, 2020
65
9
13
Sweden
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
 

Drthrax74

Member
Apr 22, 2019
23
1
8
32
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:

adrian_vg

Member
Mar 8, 2020
65
9
13
Sweden
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). :)
 

hotelrwanda

New Member
Apr 20, 2022
5
1
3
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

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!