Skip to main content
Community Scripts logo
Skip to Content
Tools & Add-onsPVE Tools

PVE LXC Filesystem Trim

Run pct fstrim on LXC containers to hand unused blocks back to SSD or thin-provisioned storage.

fstrim.sh runs pct fstrim on the containers of a node. On thin-provisioned LVM or SSD storage this releases blocks that deleted files still occupy. On classic HDDs or thick LVM it has no effect.

Website entry: fstrim. Source: tools/pve/fstrim.sh.

Run

In the Proxmox VE host shell, as root:

bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/tools/pve/fstrim.sh)"

Prompts

PromptChoicesEffect
"About fstrim (LXC)"OKInformation only.
"Root filesystem is not ext4 (...). Continue anyway?" (only if / on the host is not ext4)Yes / NoNo exits.
"Select containers to skip from trimming:" (checklist)All containers with name and statusTicked containers are skipped. Cancel exits.
Temporarily start for fstrim? [y/N]: (once per stopped, non-excluded container)yThe container is started for the trim. Anything else skips it.
Stop LXC <id> (<name>) again after trim? [Y/n]: (for each container started this way)Enter or anything but npct stop after the trim. n leaves it running.

What it does

For every container that is not excluded, not a template, and either running or selected for a temporary start:

  1. If an LVM volume named vm-<id>-disk-0 exists, its data_percent is printed as "Data before trim".
  2. pct fstrim <id> runs. A failure, for example on a locked container during a backup, is reported and the script continues.
  3. The data_percent after the trim is printed.

Files

PathContent
/var/log/fstrim.logMode 600. One header line per run and one line per container: time, CTID, Name, Before, After and the fstrim output.

Nothing else on the host is changed.

Environment variables

VariableDefaultPurpose
COMMUNITY_SCRIPTS_CORE_URLhttps://raw.githubusercontent.com/community-scripts/core/mainBase URL the script loads api/api.func from.

Limits

  • The before and after figures only exist for LVM thin volumes named vm-<id>-disk-0. On ZFS, directory storage or other disk names the script prints "not available (non-LVM storage)"; the trim still runs.
  • For ZFS the script's own advice is to set autotrim=on on the pool.
  • Temporarily started containers are stopped with pct stop, not shut down cleanly.
  • The script trims once. It does not set up a schedule.