btrfs-progs: docs: fix spelling errors
[platform/upstream/btrfs-progs.git] / Documentation / btrfs-filesystem.asciidoc
1 btrfs-filesystem(8)
2 ===================
3
4 NAME
5 ----
6 btrfs-filesystem - command group of btrfs that usually work on the whole filesystem
7
8 SYNOPSIS
9 --------
10 *btrfs filesystem* <subcommand> <args>
11
12 DESCRIPTION
13 -----------
14 *btrfs filesystem* is used to do the whole filesystem level tasks, including
15 all the regular filesystem operations like resizing, space stats, label
16 setting/getting, and defragmentation.
17
18 SUBCOMMAND
19 ----------
20 *df* [options] <path>::
21 Show a terse summary information about allocation of block group types of a given
22 mount point. The original purpose of this command was a debugging helper. The
23 output needs to be further interpreted and is not suitable for quick overview.
24 +
25 --
26 An example with description:
27
28 * device size: '1.9TiB', one device, no RAID
29 * filesystem size: '1.9TiB'
30 * created with: 'mkfs.btrfs -d single -m single'
31 --
32 +
33 ------------------------------
34 $ btrfs filesystem df /path
35 Data, single: total=1.15TiB, used=1.13TiB
36 System, single: total=32.00MiB, used=144.00KiB
37 Metadata, single: total=12.00GiB, used=6.45GiB
38 GlobalReserve, single: total=512.00MiB, used=0.00B
39 ------------------------------
40 +
41 --
42 * 'Data', 'System' and 'Metadata' are separate block group types.
43 'GlobalReserve' is an artificial and internal emergency space, see below.
44 * 'single' -- the allocation profile, defined at mkfs time
45 * 'total' -- sum of space reserved for
46 all allocation profiles of the given type, ie. all Data/single. Note that it's
47 not total size of filesystem.
48 * 'used' -- sum of used space of the above, ie. file extents, metadata blocks
49 --
50 +
51 'GlobalReserve' is an artificial and internal emergency space. It is used eg.
52 when the filesystem is full. Its 'total' size is dynamic based on the
53 filesystem size, usually not larger than 512MiB, 'used' may fluctuate.
54 +
55 The global block reserve is accounted within Metadata. In case the filesystem
56 metadata are exhausted, 'GlobalReserve/total + Metadata/used = Metadata/total'.
57 +
58 `Options`
59 +
60 -b|--raw::::
61 raw numbers in bytes, without the 'B' suffix
62 -h|--human-readable::::
63 print human friendly numbers, base 1024, this is the default
64 -H::::
65 print human friendly numbers, base 1000
66 --iec::::
67 select the 1024 base for the following options, according to the IEC standard
68 --si::::
69 select the 1000 base for the following options, according to the SI standard
70 -k|--kbytes::::
71 show sizes in KiB, or kB with --si
72 -m|--mbytes::::
73 show sizes in MiB, or MB with --si
74 -g|--gbytes::::
75 show sizes in GiB, or GB with --si
76 -t|--tbytes::::
77 show sizes in TiB, or TB with --si
78 +
79 If conflicting options are passed, the last one takes precedence.
80
81 *defragment* [options] <file>|<dir> [<file>|<dir>...]::
82 Defragment file data on a mounted filesytem.
83 +
84 If '-r' is passed, files in dir will be defragmented recursively.
85 The start position and the number of bytes to defragment can be specified by
86 start and len using '-s' and '-l' options below.
87 Extents bigger than value given by '-t' will be skipped, otherwise this value
88 is used as a target extent size, but is only advisory and may not be reached
89 if the free space is too fragmented.
90 Use 0 to take the kernel default, which is 256kB but may change in the future.
91 You can also turn on compression in defragment operations.
92 +
93 WARNING: Defragmenting with Linux kernel versions < 3.9 or ≥ 3.14-rc2 as well as
94 with Linux stable kernel versions ≥ 3.10.31, ≥ 3.12.12 or ≥ 3.13.4 will break up
95 the ref-links of COW data (for example files copied with `cp --reflink`,
96 snapshots or de-duplicated data).
97 This may cause considerable increase of space usage depending on the broken up
98 ref-links.
99 +
100 `Options`
101 +
102 -v::::
103 be verbose, print file names as they're submitted for defragmentation
104 -c[<algo>]::::
105 compress file contents while defragmenting. Optional argument selects the compression
106 algorithm, 'zlib' (default) or 'lzo'. Currently it's not possible to select no
107 compression. See also section 'EXAMPLES'.
108 -r::::
109 defragment files recursively in given directories
110 -f::::
111 flush data for each file before going to the next file. This will limit the amount
112 of dirty data to current file, otherwise the amount cumulates from several files
113 and may increase system load.
114 -s <start>[kKmMgGtTpPeE]::::
115 defragmentation will start from the given offset, default is beginning of a file
116 -l <len>[kKmMgGtTpPeE]::::
117 defragment only up to 'len' bytes, default is the file size
118 -t <size>[kKmMgGtTpPeE]::::
119 target extent size, do not touch extents bigger than 'size'
120 +
121 For 'start', 'len', 'size' it is possible to append
122 units designator: \'K', \'M', \'G', \'T', \'P', or \'E', which represent
123 KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
124 +
125 NOTE: Directory arguments without '-r' do not defragment files recursively but will
126 defragment certain internal trees (extent tree and the subvolume tree). This has been
127 confusing and could be removed in the future.
128
129 *label* [<dev>|<mountpoint>] [<newlabel>]::
130 Show or update the label of a filesystem. This works on a mounted filesystem or
131 a filesystem image.
132 +
133 The 'newlabel' argument is optional. Current label is printed if the the argument
134 is omitted.
135 +
136 NOTE: the maximum allowable length shall be less than 256 chars and must not contain
137 a newline. The trailing newline is stripped automatically.
138
139 // Some wording are extracted by the resize2fs man page
140 *resize* [<devid>:][+/-]<size>[kKmMgGtTpPeE]|[<devid>:]max <path>::
141 Resize a mounted filesystem identified by 'path'. A particular device
142 can be resized by specifying a 'devid'.
143 +
144 WARNING: If 'path' is a file containing a BTRFS image then resize does not work
145 as expected and does not resize the image. This would resize the underlying
146 filesystem instead.
147 +
148 The 'devid' can be found in the output of *btrfs filesystem show* and
149 defaults to 1 if not specified.
150 The 'size' parameter specifies the new size of the filesystem.
151 If the prefix '+' or '-' is present the size is increased or decreased
152 by the quantity 'size'.
153 If no units are specified, bytes are assumed for 'size'.
154 Optionally, the size parameter may be suffixed by one of the following
155 units designators: \'K', \'M', \'G', \'T', \'P', or \'E', which represent
156 KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
157 +
158 If 'max' is passed, the filesystem will occupy all available space on the
159 device respecting 'devid' (remember, devid 1 by default).
160 +
161 The resize command does not manipulate the size of underlying
162 partition.  If you wish to enlarge/reduce a filesystem, you must make sure you
163 can expand the partition before enlarging the filesystem and shrink the
164 partition after reducing the size of the filesystem.  This can done using
165 `fdisk`(8) or `parted`(8) to delete the existing partition and recreate
166 it with the new desired size.  When recreating the partition make sure to use
167 the same starting partition offset as before.
168 +
169 Growing is usually instant as it only updates the size. However, shrinking could
170 take a long time if there are data in the device area that's beyond the new
171 end. Relocation of the data takes time.
172 +
173 See also section 'EXAMPLES'.
174
175 *show* [options] [<path>|<uuid>|<device>|<label>]::
176 Show the btrfs filesystem with some additional info about devices and space
177 allocation.
178 +
179 If no option none of 'path'/'uuid'/'device'/'label' is passed, information
180 about all the BTRFS filesystems is shown, both mounted and unmounted.
181 +
182 `Options`
183 +
184 -m|--mounted::::
185 probe kernel for mounted BTRFS filesystems
186 -d|--all-devices::::
187 scan all devices under /dev, otherwise the devices list is extracted from the
188 /proc/partitions file. This is a fallback option if there's no device node
189 manager (like udev) available in the system.
190 --raw::::
191 raw numbers in bytes, without the 'B' suffix
192 --human-readable::::
193 print human friendly numbers, base 1024, this is the default
194 --iec::::
195 select the 1024 base for the following options, according to the IEC standard
196 --si::::
197 select the 1000 base for the following options, according to the SI standard
198 --kbytes::::
199 show sizes in KiB, or kB with --si
200 --mbytes::::
201 show sizes in MiB, or MB with --si
202 --gbytes::::
203 show sizes in GiB, or GB with --si
204 --tbytes::::
205 show sizes in TiB, or TB with --si
206
207 *sync* <path>::
208 Force a sync of the filesystem at 'path'. This is done via a special ioctl and
209 will also trigger cleaning of deleted subvolumes. Besides that it's equivalent
210 to the `sync`(1) command.
211
212 *usage* [options] <path> [<path>...]::
213 Show detailed information about internal filesystem usage. This is supposed to
214 replace the *btrfs filesystem df* command in the long run.
215 +
216 The level of detail can differ if the command is run under a regular or the
217 root user (due to use of restricted ioctl). For both there's a summary section
218 with information about space usage:
219 +
220 -------------------------
221 $ btrfs fi usage /path
222 WARNING: cannot read detailed chunk info, RAID5/6 numbers will be incorrect, run as root
223 Overall:
224     Device size:                   1.82TiB
225     Device allocated:              1.17TiB
226     Device unallocated:          669.99GiB
227     Device missing:                  0.00B
228     Used:                          1.14TiB
229     Free (estimated):            692.57GiB      (min: 692.57GiB)
230     Data ratio:                       1.00
231     Metadata ratio:                   1.00
232     Global reserve:              512.00MiB      (used: 0.00B)
233 -------------------------
234 +
235 The root user will also see stats broken down by block group types:
236 +
237 -------------------------
238 Data,single: Size:1.15TiB, Used:1.13TiB
239    /dev/sdb        1.15TiB
240
241 Metadata,single: Size:12.00GiB, Used:6.45GiB
242    /dev/sdb       12.00GiB
243
244 System,single: Size:32.00MiB, Used:144.00KiB
245    /dev/sdb       32.00MiB
246
247 Unallocated:
248    /dev/sdb      669.99GiB
249 -------------------------
250 +
251 `Options`
252 +
253 -b|--raw::::
254 raw numbers in bytes, without the 'B' suffix
255 -h|--human-readable::::
256 print human friendly numbers, base 1024, this is the default
257 -H::::
258 print human friendly numbers, base 1000
259 --iec::::
260 select the 1024 base for the following options, according to the IEC standard
261 --si::::
262 select the 1000 base for the following options, according to the SI standard
263 -k|--kbytes::::
264 show sizes in KiB, or kB with --si
265 -m|--mbytes::::
266 show sizes in MiB, or MB with --si
267 -g|--gbytes::::
268 show sizes in GiB, or GB with --si
269 -t|--tbytes::::
270 show sizes in TiB, or TB with --si
271 -T::::
272 show data in tabular format
273 +
274 If conflicting options are passed, the last one takes precedence.
275
276 EXAMPLES
277 --------
278
279 *$ btrfs filesystem defrag -v -r dir/*
280
281 Recursively defragment files under 'dir/', print files as they are processed.
282 The file names will be printed in batches, similarly the amount of data triggered
283 by defragmentation will be proportional to last N printed files. The system dirty
284 memory throttling will slow down the defragmentation but there can still be a lot
285 of IO load and the system may stall for a moment.
286
287 *$ btrfs filesystem defrag -v -r -f dir/*
288
289 Recursively defragment files under 'dir/', be verbose and wait until all blocks
290 are flushed before processing next file. You can note slower progress of the
291 output and lower IO load (proportional to currently defragmented file).
292
293 *$ btrfs filesystem defrag -v -r -f -clzo dir/*
294
295 Recursively defragment files under 'dir/', be verbose, wait until all blocks are
296 flushed and force file compression.
297
298 *$ btrfs filesystem defrag -v -r -t 64M dir/*
299
300 Recursively defragment files under 'dir/', be verbose and try to merge extents
301 to be about 64MiB. As stated above, the success rate depends on actual free
302 space fragmentation and the final result is not guaranteed to meet the target
303 even if run repeatedly.
304
305 *$ btrfs filesystem resize -1G /path*
306
307 *$ btrfs filesystem resize 1:-1G /path*
308
309 Shrink size of the filesystem's device id 1 by 1GiB. The first syntax expects a
310 device with id 1 to exist, otherwise fails. The second is equivalent and more
311 explicit. For a single-device filesystem it's typically not necessary to
312 specify the devid though.
313
314 *$ btrfs filesystem resize max /path*
315
316 *$ btrfs filesystem resize 1:max /path*
317
318 Let's assume that devid 1 exists, the filesystem does not occupy the whole block
319 device, eg. it has been enlarged and we wan the grow the filesystem. Simply using
320 'max' as size we will achieve that.
321
322 NOTE: There are two ways to minimize the filesystem on a given device. The
323 *btrfs inspect-internal min-dev-size* command, or iteratively shrink in steps.
324
325 EXIT STATUS
326 -----------
327 *btrfs filesystem* returns a zero exit status if it succeeds. Non zero is
328 returned in case of failure.
329
330 AVAILABILITY
331 ------------
332 *btrfs* is part of btrfs-progs.
333 Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
334 further details.
335
336 SEE ALSO
337 --------
338 `mkfs.btrfs`(8),