basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    Discard on a VM disk — otherwise Proxmox’s thin pool only grows

    The guest deleted 20 GB — it freed the space on its side, but in the local-lvm thin pool or in ZFS those blocks stay allocated: the storage doesn’t know they’re no longer needed. TRIM from the guest tells it, and the disk’s discard=on option lets TRIM through to the storage. Without it the pool fills up to 100 % and stops every guest on it.

    How it works:

    guest: rm a big file            the guest file system marks the blocks free
    guest: fstrim                   the guest sends TRIM to the disk: "these blocks aren't needed"
    Proxmox: discard=on on the disk QEMU passes TRIM on to the storage
    storage: LVM-thin, ZFS, qcow2   the blocks go back to the pool

    Without discard=on the second line goes nowhere: pool usage only grows until it equals the size of the disk given to the guest. On a thin pool, where guests are given more than there is space, that’s the road to a full pool (Proxmox storage).

    Enable it on every disk of the VM: Hardware › disk › Edit › Discard, or

    qm set 101 --scsi0 local-lvm:vm-101-disk-0,discard=on,size=30G

    Take the line from qm config 101 and append discard=on without dropping anything. The cloud-init template has it from the start (VM template with cloud-init). The SSD emulation checkbox next to it is about something else: the guest sees the disk as an SSD rather than a spinning drive and won’t, for example, defragment it.

    Inside the guest, TRIM has to be run. On Ubuntu fstrim.timer does it once a week and is enabled by default; on other systems check systemctl status fstrim.timer. Mounting with the discard option isn’t needed: TRIM on every delete loads the disk more than one batch a week.

    For LXC containers the host runs TRIM for them: pct fstrim 201 — for all of the container’s volumes.

    If it doesn’t work

    Discard is on, fstrim -av ran, but Data% in lvs didn’t go down

    Cause
    The option was enabled on a running VM: it’s [PENDING] and takes effect after the VM’s process restarts. Or the volume has snapshots — they hold on to the old blocks.
    Fix
    qm reboot 101, then fstrim -av in the guest. Delete snapshots you no longer need.

    How to check

    lvs pve/data                      # Data% before
    qm guest exec 101 -- fstrim -av   # or sudo fstrim -av in the VM itself: /: 18.2 GiB trimmed
    lvs pve/data                      # Data% after — lower