Skip to main content

Proxmox VE – Enable TRIM / Discard

Overview

TRIM/discard lets a filesystem report unused blocks to the storage beneath it. Depending on the storage configuration, this can reclaim thin-provisioned space and help SSDs manage unused blocks.

Configure each applicable layer separately:

  • Proxmox host: periodic TRIM for supported mounted filesystems.
  • Virtual machines: enable discard on the virtual disk and run TRIM inside the guest.
  • LXC containers: run pct fstrim from the Proxmox host.
  • ZFS pools: optionally enable native device TRIM.

Discard support must be available throughout the storage stack. Snapshots can retain blocks and delay space reclamation.

1. Enable periodic TRIM on the Proxmox host

Run on the Proxmox host:

systemctl enable --now fstrim.timer

Verify the timer and its next scheduled run:

systemctl status fstrim.timer
systemctl list-timers --all fstrim.timer

The standard timer normally runs weekly. Check the displayed schedule on your host.

To run TRIM immediately on eligible mounted filesystems:

fstrim -av

Check the service’s recent results:

journalctl -u fstrim.service --since "14 days ago"

Host filesystem TRIM does not replace TRIM inside virtual machines or the container procedure below.

2. Enable discard for virtual machines

Configure the virtual disk in Proxmox

For each disk that should support discard:

  1. Select the VM.
  2. Open Hardware.
  3. Select the virtual hard disk and click Edit.
  4. Enable Discard.
  5. Save the configuration.
  6. If Proxmox shows the change as pending, fully shut down and start the VM.

For new Linux VMs, VirtIO SCSI is a common choice. Changing an existing VM’s disk controller requires preparation and may affect its ability to boot.

Enable periodic TRIM inside a Linux guest

Run inside the VM:

sudo systemctl enable --now fstrim.timer
sudo systemctl list-timers --all fstrim.timer

Inspect the discard capabilities exposed to the guest:

lsblk -D

Non-zero DISC-GRAN and DISC-MAX values indicate that the device advertises discard support. They do not prove that space has been reclaimed at every underlying layer.

Run TRIM manually:

sudo fstrim -av

Repeat for each applicable Linux VM.

3. Run TRIM for LXC containers

Run container TRIM from the Proxmox host.

For one container:

pct fstrim <CTID>

Replace <CTID> with the container ID.

For all running containers:

while read -r id; do
    pct fstrim "$id"
done < <(pct list | awk 'NR > 1 && $2 == "running" {print $1}')

Whether a container mount can be trimmed depends on its storage backend and mount configuration. Inspect command output for skipped mounts or errors.

4. Optional: schedule weekly LXC TRIM

The host’s fstrim.timer does not invoke pct fstrim for each container. If you want a separate container schedule, first check for existing automation to avoid duplicate jobs.

Create a script on the Proxmox host:

cat > /usr/local/sbin/pve-lxc-fstrim <<'EOF'
#!/bin/bash
set -u

containers=$(/usr/sbin/pct list) || exit 1
result=0

while read -r id; do
    if ! /usr/sbin/pct fstrim "$id"; then
        printf 'TRIM failed for container %s\n' "$id" >&2
        result=1
    fi
done < <(awk 'NR > 1 && $2 == "running" {print $1}' <<< "$containers")

exit "$result"
EOF

chmod 0750 /usr/local/sbin/pve-lxc-fstrim

Test it:

/usr/local/sbin/pve-lxc-fstrim

Then edit root’s crontab:

crontab -e

Add:

0 3 * * 1 /usr/local/sbin/pve-lxc-fstrim

This example runs every Monday at 03:00 in the host’s timezone. Choose a time outside backup windows and other heavy storage activity.

Only containers running at that time are included. Keep scheduled-job output connected to your normal monitoring or mail delivery so failures are visible.

5. Verify space reclamation

Compare storage usage before and after deleting disposable test data and running guest or container TRIM.

LVM-thin

Run on the Proxmox host:

lvs -o vg_name,lv_name,lv_size,data_percent,metadata_percent

Watch the thin pool’s Data%. Snapshots or other references can prevent an immediate reduction.

File-based virtual disks

For a QCOW2 or sparse raw image, inspect its allocated host space:

du -h /path/to/vm-disk.qcow2

Check free space on the filesystem containing the image:

df -h /path/to/vm-disk.qcow2

Deleting files inside the guest can increase guest free space before the host allocation decreases.

A successful fstrim message reports ranges submitted for discard; it is not a measurement of physical space reclaimed.

6. Optional: enable ZFS device TRIM

ZFS device TRIM and guest discard perform different jobs:

  • Guest discard can release unused virtual-disk blocks to ZFS.
  • ZFS device TRIM informs supported underlying devices about blocks that ZFS has freed.

Inspect your pools:

zpool list
zpool status
zpool get autotrim

To enable automatic device TRIM for a suitable pool:

zpool set autotrim=on <POOL>

Replace <POOL> with the pool name, then verify:

zpool get autotrim <POOL>

To request a manual pool TRIM:

zpool trim <POOL>

Inspect its progress:

zpool status -t <POOL>

Use ZFS-native TRIM for pool devices. Enabling the host’s fstrim.timer does not enable ZFS autotrim.

Notes

  • Periodic TRIM is usually a suitable starting point; continuous filesystem discard is a separate configuration choice.
  • Thin storage, image formats, controllers and physical devices must support the relevant discard operations.
  • Snapshots and clones may retain blocks after files are deleted.
  • The ZFS section applies only to hosts using ZFS pools.
  • TRIM is not a secure-erasure procedure.

References