sábado, 14 de noviembre de 2026

Optimize disk usage docker lxc

Check how is going the disk 

root@pve1:~# pct exec 100 -- df -h / Filesystem Size Used Avail Use% Mounted on /dev/mapper/pve-vm--100--disk--0 20G 16G 3.1G 84% /



Return deleted-file space to the storage pool (safe to run anytime):
pct fstrim 100


See what's using the 16G:
pct exec 100 -- du -xsh /var/lib/docker /var/log /root /opt 2>/dev/null
pct exec 100 -- docker system df


Clean up. All of this is safe, because images used by your 7 running containers are kept:
pct exec 100 -- docker image prune -a -f      # removes the unused images
pct exec 100 -- docker builder prune -a -f    # removes the ~500MB build cache
pct exec 100 -- journalctl --vacuum-size=200M # shrinks the system logs if the


See what's using /root:

pct exec 100 -- sh -c 'du -sh /root/* /root/.[!.]* 2>/dev/null | sort -h | tail'


Then trim and check again:

pct fstrim 100
pct exec 100 -- df -h /


Had some vscode server stuff taking so much space

delete only the old server versions and keep the newest one:

pct exec 100 -- sh -c 'du -sh /root/.vscode-server/* /root/.vscode-server/cli/servers/* 2>/dev/null'
pct exec 100 -- sh -c 'cd /root/.vscode-server/cli/servers && ls -t | tail -n +2


Then trim and check the result:

pct fstrim 100
pct exec 100 -- df -h /


root@pve1:~# pct fstrim 100 pct exec 100 -- df -h / /var/lib/lxc/100/rootfs/: 4.6 GiB (4918226944 bytes) trimmed /var/lib/lxc/100/rootfs/cctv_clips: 0 B (0 bytes) trimmed Filesystem Size Used Avail Use% Mounted on /dev/mapper/pve-vm--100--disk--0 20G 13G 6.7G 65% / root@pve1:~#



Took 6.7GB free!!


Resize lvm proxmox





1. See how much free space the storage really has
pvesm status | grep storage-lvm 

vgs 

lvs


2. Grow the mount point

Use the VFree value, rounded down slightly. For example, if VFree is 23.47g:
pct resize 100 mp0 +23G


pct resize grows both the logical volume and the ext4 filesystem inside it. It works while the container is running, and Frigate doesn't need a restart.

To use every last free extent instead of a rounded number:
lvextend -l +100%FREE /dev/<vgname>/vm-100-disk-0 pct rescan # updates size= in 100.conf




3. Check it worked
grep mp0 /etc/pve/lxc/100.conf pct exec 100 -- df -h /cctv_clips



4. Restart the lxc to get all the data
pct stop 100
lvchange -ay storage-lvm/vm-100-disk-0
ls -l /dev/storage-lvm/vm-100-disk-0         # should exist now
e2fsck -f /dev/storage-lvm/vm-100-disk-0
resize2fs /dev/storage-lvm/vm-100-disk-0
pct start 100
pct exec 100 -- df -h /cctv_clips