For Proxmox installs - Clean up your server (re-claim disk space)

If you have your HomeAssistant installed in Proxmox then there’s a possibility that you could save disk space on your backups/snapshots.

With Proxmox, resources are allocated to VM or LXC for the VM/Container to use.
Lots of temporary files are often created and expunged as part of the system running, but what (I think) happens is that Proxmox host registers the increase in disk use, but doesn’t know that the temporary VM/LXC files are removed and so it thinks the disk still needs the extra space.

The below are a couple of tools to let the host know that these deleted data blocks can be returned to the available disk pool.


VM:


In the VM, select the VM and select:

Hardware | Hard Disk | Edit

NB: Only do this to the main data HDD, not EFI Disks

In the pop-up, tick the Discard option.
image

Once that’s done, open the VM’s console and launch a terminal window.
As root, type: fstrim -a

My understanding of what this does is trigger an immediate trim to release blocks from previously deleted files back to Proxmox and in the VM it will continue to self maintain/release No need to run it again or set up a cron.

As an example, our Proxmox HA backup runs in half the time and the backup files files went from 20Gb+ > 8.5Gb by doing this and has remained small.
image


LXC/Containers:


If you’re running HA in a container rather than VM, then the below command will do the same task of releasing data blocks back to the Proxmox host. Unlike the VM, this has to be run manually (or by cron) each time you want it to trim.

Run in the Proxmox host as Root/Admin:
pct fstrim <Container ID>
e.g.
pct fstrim 144

Alternatively, the below script will do the same, but will trim all the LXC that you have installed automatically. Each one in sequence.

#!/usr/bin/env bash
for file in /etc/pve/lxc/*.conf; do
    filename=$(basename "$file" .conf)  # Extract the container name without the extension
    echo "Processing container ID $filename"
    pct fstrim $filename
done

We auto-run this script weekly via cron to prevent our disk use from creeping up too much.

/etc/crontab:

#      Reclaim empty space from containers. Uses command: pct fstrim $filename
30  9 2-31 * 1     root    ~/admin_tasks/trim_containers.sh
30  9  1   * *     root    ~/admin_tasks/trim_containers.sh

The first time I ran both the above our Proxmox host disk reduced from 83%+ down to 45% (500Gb disk). Before that I was thinking about getting a bigger drive for the host :slight_smile:

This was our initial run of the VM trim the first time and then the LXC trim the following day
image

2 Likes