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