A missing blog post image


Hey over here, this post will be the first one of a short series of write-ups about Proxmox.

Today we will approach a tricky procedure : Reducing the disk size of an unprivileged LXC container.

The procedure

:warning: Please don’t mess with the disk size you will have to set below, you can easily destroy the container and lose your data if its value is lower than the size of the content, or not large enough for the runtime :warning:

# Put your container id here :
# Put its storage name here :
# Set the new size you want here (GB) :

# Let's stop the container, as we can't do that while it is running...
pct stop $CT_ID

# Here we run a snapshot of the container
vzdump $CT_ID -storage $STORAGE -compress lzo
# --> Please write down the path of the resulting archive !

# Let's now remove its protection (if any), and removes it from the datacenter
pct set $CT_ID -protection false
pct destroy $CT_ID

# Now we can restore it, with a lower disk size, and our own options
pct restore $CT_ID /path/to/the/arhive/dump.tar.lzo -rootfs $NEW_SIZE -unprivileged

# Once the latter operation is done, you can start it again 😌
pct start $CT_ID

# Spring cleanup
rm /path/to/the/arhive/dump.{log,tar.lzo}

Pro-tip : You can use the same procedure (without tweaking the disk size) so as to set to unprivileged a privileged container :sunglasses: