]> git.ipfire.org Git - thirdparty/util-linux.git/blame - sys-utils/fstrim.8
Manual pages: Standardize on EXIT STATUS as section title
[thirdparty/util-linux.git] / sys-utils / fstrim.8
CommitLineData
374baa6f 1.TH FSTRIM 8 "May 2019" "util-linux" "System Administration"
d9e2d0dd
LC
2.SH NAME
3fstrim \- discard unused blocks on a mounted filesystem
4.SH SYNOPSIS
5.B fstrim
c5b8909f 6.RB [ \-Aa ]
d9e2d0dd
LC
7.RB [ \-o
8.IR offset ]
9.RB [ \-l
10.IR length ]
11.RB [ \-m
c372860d 12.IR minimum-size ]
d9e2d0dd
LC
13.RB [ \-v ]
14.I mountpoint
15
16.SH DESCRIPTION
17.B fstrim
18is used on a mounted filesystem to discard (or "trim") blocks which are not in
19use by the filesystem. This is useful for solid-state drives (SSDs) and
20thinly-provisioned storage.
21.PP
22By default,
23.B fstrim
24will discard all unused blocks in the filesystem. Options may be used to
25modify this behavior based on range or size, as explained below.
26.PP
27The
28.I mountpoint
29argument is the pathname of the directory where the filesystem
30is mounted.
004ff2d6
KZ
31.PP
32Running
33.B fstrim
c372860d 34frequently, or even using
1c4c6024 35.BR "mount \-o discard" ,
c372860d 36might negatively affect the lifetime of poor-quality SSD devices. For most
bbe6f3cf 37desktop and server systems a sufficient trimming frequency is once a week.
c372860d
BS
38Note that not all
39devices support a queued trim, so each trim command incurs a performance penalty
40on whatever else might be trying to use the disk at the time.
d9e2d0dd
LC
41
42.SH OPTIONS
c372860d
BS
43The \fIoffset\fR, \fIlength\fR, and \fIminimum-size\fR arguments may be
44followed by the multiplicative suffixes KiB (=1024),
45MiB (=1024*1024), and so on for GiB, TiB, PiB, EiB, ZiB and YiB (the "iB"
46is optional, e.g., "K" has the same meaning as "KiB") or the suffixes
47KB (=1000), MB (=1000*1000), and so on for GB, TB, PB, EB, ZB and YB.
48
c5b8909f
KZ
49.IP "\fB\-A, \-\-fstab\fP"
50Trim all mounted filesystems mentioned in \fI/etc/fstab\fR on devices that support the
410d12e5
KZ
51discard operation. The root filesystem is determined from kernel command line if missing
52in the file.
c5b8909f
KZ
53The other supplied options, like \fB\-\-offset\fR, \fB\-\-length\fR and
54\fB-\-minimum\fR, are applied to all these devices.
6466959d
KZ
55Errors from filesystems that do not support the discard operation,
56read-only devices and read-only filesystems are silently ignored.
36c370cb 57.IP "\fB\-a, \-\-all\fP"
d6bbe804
BS
58Trim all mounted filesystems on devices that support the discard operation.
59The other supplied options, like \fB\-\-offset\fR, \fB\-\-length\fR and
60\fB-\-minimum\fR, are applied to all these devices.
6466959d
KZ
61Errors from filesystems that do not support the discard operation,
62read-only devices and read-only filesystems are silently ignored.
26b6525a 63.IP "\fB\-n, \-\-dry\-run\fP"
fda0e2cf 64This option does everything apart from actually call FITRIM ioctl.
d9e2d0dd 65.IP "\fB\-o, \-\-offset\fP \fIoffset\fP"
c372860d
BS
66Byte offset in the filesystem from which to begin searching for free blocks
67to discard. The default value is zero, starting at the beginning of the
d9e2d0dd
LC
68filesystem.
69.IP "\fB\-l, \-\-length\fP \fIlength\fP"
c372860d
BS
70The number of bytes (after the starting point) to search for free blocks
71to discard. If the specified value extends past the end of the filesystem,
d9e2d0dd 72.B fstrim
c372860d
BS
73will stop at the filesystem size boundary. The default value extends to
74the end of the filesystem.
75.IP "\fB\-m, \-\-minimum\fP \fIminimum-size\fP"
d9e2d0dd 76Minimum contiguous free range to discard, in bytes. (This value is internally
bbe6f3cf 77rounded up to a multiple of the filesystem block size.) Free ranges smaller
ce3d198d
WS
78than this will be ignored and fstrim will adjust the minimum if it's smaller than
79the device's minimum, and report that (fstrim_range.minlen) back to userspace.
80By increasing this value, the fstrim operation will complete more quickly for
81filesystems with badly fragmented freespace, although not all blocks will be
82discarded. The default value is zero, discarding every free block.
d9e2d0dd 83.IP "\fB\-v, \-\-verbose\fP"
c372860d 84Verbose execution. With this option
d9e2d0dd
LC
85.B fstrim
86will output the number of bytes passed from the filesystem
c372860d 87down the block stack to the device for potential discard. This number is a
d9e2d0dd
LC
88maximum discard amount from the storage device's perspective, because
89.I FITRIM
90ioctl called repeated will keep sending the same sectors for discard repeatedly.
c372860d 91.sp
d9e2d0dd
LC
92.B fstrim
93will report the same potential discard bytes each time, but only sectors which
94had been written to between the discards would actually be discarded by the
95storage device. Further, the kernel block layer reserves the right to adjust
96the discard ranges to fit raid stripe geometry, non-trim capable devices in a
97LVM setup, etc. These reductions would not be reflected in fstrim_range.len
98(the
1c4c6024 99.B \-\-length
d9e2d0dd 100option).
c372860d 101.TP
ef89802e
KZ
102.B \-\-quiet\-unsupported
103Suppress error messages if trim operation (ioctl) is unsupported. This option
104is meant to be used in systemd service file or in cron scripts to hide warnings
105that are result of known problems,
6466959d 106such as NTFS driver
374baa6f
SK
107reporting
108.I Bad file descriptor
109when device is mounted read-only, or lack of file system support for ioctl
110FITRIM call.
111.TP
c372860d
BS
112.BR \-V , " \-\-version"
113Display version information and exit.
114.TP
115.BR \-h , " \-\-help"
116Display help text and exit.
d9e2d0dd 117
7e765c93 118.SH EXIT STATUS
36c370cb
KZ
119.IP 0
120success
121.IP 1
122failure
123.IP 32
124all failed
125.IP 64
d6bbe804 126some filesystem discards have succeeded, some failed
36c370cb
KZ
127.PP
128The command
1c4c6024 129.B fstrim \-\-all
c372860d 130returns 0 (all succeeded), 32 (all failed) or 64 (some failed, some succeeded).
36c370cb 131
a8d0d330 132.SH AUTHORS
d9e2d0dd
LC
133.nf
134Lukas Czerner <lczerner@redhat.com>
135Karel Zak <kzak@redhat.com>
136.fi
137.SH SEE ALSO
f053ff1e
MK
138.BR blkdiscard (8),
139.BR mount (8)
d9e2d0dd 140.SH AVAILABILITY
601d12fb 141The fstrim command is part of the util-linux package and is available from
d673b74e 142https://www.kernel.org/pub/linux/utils/util-linux/.