LinuxCommandLibrary

fstrim-all

Trim all mounted file systems on SSDs

SYNOPSIS

fstrim-all [options]

PARAMETERS

-a, --all
    Trim all mounted filesystems in /etc/fstab with discard option (default).

-d, --discard-only
    List filesystems supporting discard without trimming.

-h, --help
    Display help and exit.

-n, --dry-run
    Simulate trimming without performing it.

-q, --quiet
    Suppress output.

-v, --verbose
    Increase output verbosity.

-V, --version
    Show version information and exit.

DESCRIPTION

fstrim-all is a convenience script from the util-linux package that automatically runs the fstrim command on all mounted filesystems listed in /etc/fstab which have the discard mount option enabled. This performs the ATA TRIM or UNMAP operation, informing the storage device (typically SSDs or thinly-provisioned volumes) which blocks are no longer in use, allowing the device to optimize performance and reclaim space.

Over time, as files are deleted, the filesystem marks blocks as unused internally, but the underlying device remains unaware without explicit trimming. Regular use of fstrim-all prevents write amplification, maintains consistent performance, and can extend SSD lifespan by reducing unnecessary writes. It is commonly scheduled via cron (e.g., weekly) on systems with SSDs.

The tool skips filesystems without discard support or those not mounted. For safety, filesystems must be mounted read-write with discard enabled at mount time (e.g., mount -o discard /dev/sda1 /mnt). It supports both block devices and filesystems, handling LVM, Btrfs, ext4, and XFS among others.

CAVEATS

Requires discard mount option; ineffective without it. Avoid on HDDs as it may cause wear. Not for root filesystem during boot (use systemd service). Large filesystems may take time; monitor with -v.

TYPICAL CRON USAGE

Add to crontab: 0 2 * * 0 /usr/sbin/fstrim-all for weekly runs at 2AM Sunday.
Or systemd timer: fstrim.timer enabled by default on many distros.

ENABLING DISCARD

Edit /etc/fstab: add discard to options, e.g., UUID=xxx / ext4 defaults,discard 0 1. Remount or reboot.

HISTORY

Introduced in util-linux 2.21 (2012) as a wrapper for fstrim. Enhanced in later versions for better fstab parsing and options like --dry-run. Widely used since SSD adoption grew post-2010.

SEE ALSO

fstrim(8), blkdiscard(8), mount(8)

Copied to clipboard