1FSTRIM(8)                    System Administration                   FSTRIM(8)
2
3
4

NAME

6       fstrim - discard unused blocks on a mounted filesystem
7

SYNOPSIS

9       fstrim [-Aav] [-o offset] [-l length] [-m minimum-size] [mountpoint]
10

DESCRIPTION

12       fstrim is used on a mounted filesystem to discard (or "trim") blocks
13       which are not in use by the filesystem. This is useful for solid-state
14       drives (SSDs) and thinly-provisioned storage.
15
16       By default, fstrim will discard all unused blocks in the filesystem.
17       Options may be used to modify this behavior based on range or size, as
18       explained below.
19
20       The mountpoint argument is the pathname of the directory where the
21       filesystem is mounted and is required when -A, -a, --fstab, or --all
22       are unspecified.
23
24       Running fstrim frequently, or even using mount -o discard, might
25       negatively affect the lifetime of poor-quality SSD devices. For most
26       desktop and server systems a sufficient trimming frequency is once a
27       week. Note that not all devices support a queued trim, so each trim
28       command incurs a performance penalty on whatever else might be trying
29       to use the disk at the time.
30

OPTIONS

32       The offset, length, and minimum-size arguments may be followed by the
33       multiplicative suffixes KiB (=1024), MiB (=1024*1024), and so on for
34       GiB, TiB, PiB, EiB, ZiB and YiB (the "iB" is optional, e.g., "K" has
35       the same meaning as "KiB") or the suffixes KB (=1000), MB (=1000*1000),
36       and so on for GB, TB, PB, EB, ZB and YB.
37
38       -A, --fstab
39           Trim all mounted filesystems mentioned in /etc/fstab on devices
40           that support the discard operation. The root filesystem is
41           determined from kernel command line if missing in the file. The
42           other supplied options, like --offset, --length and --minimum, are
43           applied to all these devices. Errors from filesystems that do not
44           support the discard operation, read-only devices, autofs and
45           read-only filesystems are silently ignored. Filesystems with
46           "X-fstrim.notrim" mount option are skipped.
47
48       -a, --all
49           Trim all mounted filesystems on devices that support the discard
50           operation. The other supplied options, like --offset, --length and
51           --minimum, are applied to all these devices. Errors from
52           filesystems that do not support the discard operation, read-only
53           devices and read-only filesystems are silently ignored.
54
55       -n, --dry-run
56           This option does everything apart from actually call FITRIM ioctl.
57
58       -o, --offset offset
59           Byte offset in the filesystem from which to begin searching for
60           free blocks to discard. The default value is zero, starting at the
61           beginning of the filesystem.
62
63       -l, --length length
64           The number of bytes (after the starting point) to search for free
65           blocks to discard. If the specified value extends past the end of
66           the filesystem, fstrim will stop at the filesystem size boundary.
67           The default value extends to the end of the filesystem.
68
69       -I, --listed-in list
70           Specifies a colon-separated list of files in fstab or kernel
71           mountinfo format. All missing or empty files are silently ignored.
72           The evaluation of the list stops after first non-empty file. For
73           example:
74
75           --listed-in /etc/fstab:/proc/self/mountinfo.
76
77           Filesystems with "X-fstrim.notrim" mount option in fstab are
78           skipped.
79
80       -m, --minimum minimum-size
81           Minimum contiguous free range to discard, in bytes. (This value is
82           internally rounded up to a multiple of the filesystem block size.)
83           Free ranges smaller than this will be ignored and fstrim will
84           adjust the minimum if it’s smaller than the device’s minimum, and
85           report that (fstrim_range.minlen) back to userspace. By increasing
86           this value, the fstrim operation will complete more quickly for
87           filesystems with badly fragmented freespace, although not all
88           blocks will be discarded. The default value is zero, discarding
89           every free block.
90
91       -t, --types list
92           Specifies allowed or forbidden filesystem types when used with
93           --all or --fstab. The list is a comma-separated list of the
94           filesystem names. The list follows how mount -t evaluates type
95           patterns. Only specified filesystem types are allowed. All
96           specified types are forbidden if the list is prefixed by "no" or
97           each filesystem prefixed by "no" is forbidden. If the option is not
98           used, then all filesystems (except "autofs") are allowed.
99
100       -v, --verbose
101           Verbose execution. With this option fstrim will output the number
102           of bytes passed from the filesystem down the block stack to the
103           device for potential discard. This number is a maximum discard
104           amount from the storage device’s perspective, because FITRIM ioctl
105           called repeated will keep sending the same sectors for discard
106           repeatedly.
107
108           fstrim will report the same potential discard bytes each time, but
109           only sectors which had been written to between the discards would
110           actually be discarded by the storage device. Further, the kernel
111           block layer reserves the right to adjust the discard ranges to fit
112           raid stripe geometry, non-trim capable devices in a LVM setup, etc.
113           These reductions would not be reflected in fstrim_range.len (the
114           --length option).
115
116       --quiet-unsupported
117           Suppress error messages if trim operation (ioctl) is unsupported.
118           This option is meant to be used in systemd service file or in
119           cron(8) scripts to hide warnings that are result of known problems,
120           such as NTFS driver reporting Bad file descriptor when device is
121           mounted read-only, or lack of file system support for ioctl FITRIM
122           call. This option also cleans exit status when unsupported
123           filesystem specified on fstrim command line.
124
125       -h, --help
126           Display help text and exit.
127
128       -V, --version
129           Print version and exit.
130

EXIT STATUS

132       0
133           success
134
135       1
136           failure
137
138       32
139           all failed
140
141       64
142           some filesystem discards have succeeded, some failed
143
144       The command fstrim --all returns 0 (all succeeded), 32 (all failed) or
145       64 (some failed, some succeeded).
146

AUTHORS

148       Lukas Czerner <lczerner@redhat.com>, Karel Zak <kzak@redhat.com>
149

SEE ALSO

151       blkdiscard(8), mount(8)
152

REPORTING BUGS

154       For bug reports, use the issue tracker at
155       https://github.com/util-linux/util-linux/issues.
156

AVAILABILITY

158       The fstrim command is part of the util-linux package which can be
159       downloaded from Linux Kernel Archive
160       <https://www.kernel.org/pub/linux/utils/util-linux/>.
161
162
163
164util-linux 2.39.2                 2023-06-14                         FSTRIM(8)
Impressum