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
| Prompt | Choices | Effect |
|---|---|---|
| "About fstrim (LXC)" | OK | Information only. |
"Root filesystem is not ext4 (...). Continue anyway?" (only if / on the host is not ext4) | Yes / No | No exits. |
| "Select containers to skip from trimming:" (checklist) | All containers with name and status | Ticked containers are skipped. Cancel exits. |
Temporarily start for fstrim? [y/N]: (once per stopped, non-excluded container) | y | The 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 n | pct 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:
- If an LVM volume named
vm-<id>-disk-0exists, itsdata_percentis printed as "Data before trim". pct fstrim <id>runs. A failure, for example on a locked container during a backup, is reported and the script continues.- The
data_percentafter the trim is printed.
Files
| Path | Content |
|---|---|
/var/log/fstrim.log | Mode 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
| Variable | Default | Purpose |
|---|---|---|
COMMUNITY_SCRIPTS_CORE_URL | https://raw.githubusercontent.com/community-scripts/core/main | Base 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=onon 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.