[SOLVED] Reduce LXC disk with minimal risk

jl2035

Active Member
Jun 13, 2020
9
0
41
38
I have an LXC container with 50G (cloned from other LXC) that doesn't need that much, so I would like to reduce it to 25G. Data is not critical, so I think it's reasonable to try and learn. I did a google search and AI assistant provided me with these steps. Before I try anything I would like to make sure if this is the right approach and if there are any blind spots.

Bash:
export CTID=114

Stop the container:
Bash:
pct stop ${CTID}

Find the logical volume path using the following command:
Bash:
lvdisplay | grep "LV Path\|LV Size"

Run a Filesystem Check: Before resizing, check the filesystem for errors:
Bash:
e2fsck -fy /dev/pve/vm-${CTID}-disk-0

Shrink the Filesystem: Enter the container and shrink the filesystem to the desired size (e.g., 25G):
Bash:
resize2fs /dev/pve/vm-${CTID}-disk-0 25G

Shrink the Logical Volume: Use the following command to reduce the logical volume size:
Bash:
lvreduce -L 25G /dev/pve/vm-${CTID}-disk-0

Update the container's configuration file to reflect the new disk size:
Bash:
sed -i 's|50G|25G|g' /etc/pve/lxc/${CTID}.conf

Start the cointainer:
Bash:
pct start ${CTID}

Can anybody confirm these steps will not break anything?
 
It worked!

I did skip fsck check. According to your instructions it seems like an optional step.
 
It's really not because you can't be sure that data integrity is still correct until you actually checked it
 
I rewrote that step a bit to give it more importance. The FSCK happens before the shrinking (of the file system). If I remember correctly there's no second one afterwards. If you have suggestions please let me know.
 
Last edited:
  • Like
Reactions: Johannes S