Linux "fstrim" Command Line Options and Examples
discard unused blocks on a mounted filesystem

fstrim is used on a mounted filesystem to discard (or "trim") blocks which are not in use by the filesystem. This is useful for solid-state drives (SSDs) and thinly-provisioned storage. By default, fstrim will discard all unused blocks in the filesystem.


Usage:

fstrim [-a] [-o offset] [-l length] [-m minimum-size] [-v] mountpoint






Command Line Options:

-a
Trim all mounted filesystems on devices that support the discard operation. The other supplied options, like --offset,
fstrim -a ...
-o
Byte offset in the filesystem from which to begin searching for free blocks to discard. The default value is zero, startingat the beginning of the filesystem.
fstrim -o ...
-l
The number of bytes (after the starting point) to search for free blocks to discard. If the specified value extends past theend of the filesystem, fstrim will stop at the filesystem size boundary. The default value extends to the end of the filesys‐tem.
fstrim -l ...
-m
Minimum contiguous free range to discard, in bytes. (This value is internally rounded up to a multiple of the filesystem blocksize.) Free ranges smaller than this will be ignored. By increasing this value, the fstrim operation will complete morequickly for filesystems with badly fragmented freespace, although not all blocks will be discarded. The default value iszero, discarding every free block.
fstrim -m ...
-v
Verbose execution. With this option fstrim will output the number of bytes passed from the filesystem down the block stack tothe device for potential discard. This number is a maximum discard amount from the storage device's perspective, becauseFITRIM ioctl called repeated will keep sending the same sectors for discard repeatedly.fstrim will report the same potential discard bytes each time, but only sectors which had been written to between the discardswould actually be discarded by the storage device. Further, the kernel block layer reserves the right to adjust the discardranges to fit raid stripe geometry, non-trim capable devices in a LVM setup, etc. These reductions would not be reflected infstrim_range.len (the --length option).
fstrim -v ...
-V
Display version information and exit.
fstrim -V ...
-h
Display help text and exit.RETURN CODES0 success1 failure32 all failed64 some filesystem discards have succeeded, some failedThe command fstrim --all returns 0 (all succeeded), 32 (all failed) or 64 (some failed, some succeeded).AUTHORLukas Czerner <lczerner@redhat.com>Karel Zak <kzak@redhat.com>
fstrim -h ...