Blog · Sleepless Coder
Reducing lxc size in Proxmox
Sometimes there comes a moment when a container in Proxmox becomes uselessly large and its size needs to be reduced. In this article I will tell you how to do it.
Reducing disk size
Important: Before reducing the disk size, make sure to make a backup of the container!
- First we need to find the disk what we need, you can use the command
lvdisplay | grep "LV Path\|LV Size"
LV Path /dev/pve/vm-107-disk-0
LV Size 10.00 GiB
- Check the file system inside the disk and compose the information in it
e2fsck -fy /dev/pve/vm-107-disk-0
e2fsck 1.46.5 (30-Dec-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/pve/vm-107-disk-0: 11575/655360 files (0.1% non-contiguous), 209335/2621440 blocks
- Shrink the filesystem to the desired size
resize2fs /dev/pve/vm-107-disk-0 5G
resize2fs 1.46.5 (30-Dec-2021)
Resizing the filesystem on /dev/pve/vm-107-disk-0 to 1310720 (4k) blocks.
The filesystem on /dev/pve/vm-107-disk-0 is now 1310720 (4k) blocks long.
- Reducing the logical volume size
lvreduce -L 5G /dev/pve/vm-107-disk-0
WARNING: Reducing active and open logical volume to 5.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce pve/vm-107-disk-0? [y/n]: y
Size of logical volume pve/vm-107-disk-0 changed from 10.00 GiB (2560 extents) to 5.00 GiB (1280 extents).
Logical volume pve/vm-107-disk-0 successfully resized.
- If you have lvm-thin, you can reduce the size of the volume after that
mkdir temp
mount /dev/pve/vm-107-disk-0 temp
fstrim -v temp
resize2fs /dev/pve/vm-107-disk-0
umount temp
rm -r temp
- Update disk information in Proxmox
nano /etc/pve/lxc/107.conf
Where we replace rootfs: local-lvm:vm-107-disk-0,size=10G with rootfs: local-lvm:vm-107-disk-0,size=5G.
Done! The disk size has now been reduced to 5Gb!
Keep reading
Related articles
Article
Cleaning disk space after docker
Using docker on your computer, you can notice how actively it uses space for containers and images.
ArticleMigrating a PostgreSQL Database Using Replication
Today we will talk about how to migrate a production PostgreSQL database without any downtime for o
ArticleDHC-6-400 Crash in Nepal 2016
The DHC 6 plane crash occurred on February 24, 2016 in Nepal, near the village of Dana. Of the 23 p