btrfs-progs: docs: fi defrag, make some paragraphs more visible
[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 filesystem.
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 length 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 NOTE: Directory arguments without '-r' do not defragment files recursively but will
101 defragment certain internal trees (extent tree and the subvolume tree). This has been
102 confusing and could be removed in the future.
103 +
104 For 'start', 'len', 'size' it is possible to append
105 units designator: \'K', \'M', \'G', \'T', \'P', or \'E', which represent
106 KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
107 +
108 `Options`
109 +
110 -v::::
111 be verbose, print file names as they're submitted for defragmentation
112 -c[<algo>]::::
113 compress file contents while defragmenting. Optional argument selects the compression
114 algorithm, 'zlib' (default) or 'lzo'. Currently it's not possible to select no
115 compression. See also section 'EXAMPLES'.
116 -r::::
117 defragment files recursively in given directories
118 -f::::
119 flush data for each file before going to the next file. This will limit the amount
120 of dirty data to current file, otherwise the amount cumulates from several files
121 and may increase system load.
122 -s <start>[kKmMgGtTpPeE]::::
123 defragmentation will start from the given offset, default is beginning of a file
124 -l <len>[kKmMgGtTpPeE]::::
125 defragment only up to 'len' bytes, default is the file size
126 -t <size>[kKmMgGtTpPeE]::::
127 target extent size, do not touch extents bigger than 'size'
128
129 *du* [options] <path> [<path>..]::
130 Calculate disk usage of the target files using FIEMAP. For individual
131 files, it will report a count of total bytes, and exclusive (not
132 shared) bytes. We also calculate a 'set shared' value which is
133 described below.
134 +
135 Each argument to 'btrfs fi du' will have a 'set shared' value
136 calculated for it. We define each 'set' as those files found by a
137 recursive search of an argument. The 'set shared' value
138 then is a sum of all shared space referenced by the set.
139 +
140 'set shared' takes into account overlapping shared extents, hence it
141 isn't as simple as adding up shared extents.
142 +
143 `Options`
144 +
145 -s|--summarize::::
146 display only a total for each argument
147 --raw::::
148 raw numbers in bytes, without the 'B' suffix.
149 --human-readable::::
150 print human friendly numbers, base 1024, this is the default
151 --iec::::
152 select the 1024 base for the following options, according to the IEC standard.
153 --si::::
154 select the 1000 base for the following options, according to the SI standard.
155 --kbytes::::
156 show sizes in KiB, or kB with --si.
157 --mbytes::::
158 show sizes in MiB, or MB with --si.
159 --gbytes::::
160 show sizes in GiB, or GB with --si.
161 --tbytes::::
162 show sizes in TiB, or TB with --si.
163
164 *label* [<dev>|<mountpoint>] [<newlabel>]::
165 Show or update the label of a filesystem. This works on a mounted filesystem or
166 a filesystem image.
167 +
168 The 'newlabel' argument is optional. Current label is printed if the the argument
169 is omitted.
170 +
171 NOTE: the maximum allowable length shall be less than 256 chars and must not contain
172 a newline. The trailing newline is stripped automatically.
173
174 // Some wording are extracted by the resize2fs man page
175 *resize* [<devid>:][+/-]<size>[kKmMgGtTpPeE]|[<devid>:]max <path>::
176 Resize a mounted filesystem identified by 'path'. A particular device
177 can be resized by specifying a 'devid'.
178 +
179 WARNING: If 'path' is a file containing a BTRFS image then resize does not work
180 as expected and does not resize the image. This would resize the underlying
181 filesystem instead.
182 +
183 The 'devid' can be found in the output of *btrfs filesystem show* and
184 defaults to 1 if not specified.
185 The 'size' parameter specifies the new size of the filesystem.
186 If the prefix '+' or '-' is present the size is increased or decreased
187 by the quantity 'size'.
188 If no units are specified, bytes are assumed for 'size'.
189 Optionally, the size parameter may be suffixed by one of the following
190 units designators: \'K', \'M', \'G', \'T', \'P', or \'E', which represent
191 KiB, MiB, GiB, TiB, PiB, or EiB, respectively (case does not matter).
192 +
193 If 'max' is passed, the filesystem will occupy all available space on the
194 device respecting 'devid' (remember, devid 1 by default).
195 +
196 The resize command does not manipulate the size of underlying
197 partition.  If you wish to enlarge/reduce a filesystem, you must make sure you
198 can expand the partition before enlarging the filesystem and shrink the
199 partition after reducing the size of the filesystem.  This can done using
200 `fdisk`(8) or `parted`(8) to delete the existing partition and recreate
201 it with the new desired size.  When recreating the partition make sure to use
202 the same starting partition offset as before.
203 +
204 Growing is usually instant as it only updates the size. However, shrinking could
205 take a long time if there are data in the device area that's beyond the new
206 end. Relocation of the data takes time.
207 +
208 See also section 'EXAMPLES'.
209
210 *show* [options] [<path>|<uuid>|<device>|<label>]::
211 Show the btrfs filesystem with some additional info about devices and space
212 allocation.
213 +
214 If no option none of 'path'/'uuid'/'device'/'label' is passed, information
215 about all the BTRFS filesystems is shown, both mounted and unmounted.
216 +
217 `Options`
218 +
219 -m|--mounted::::
220 probe kernel for mounted BTRFS filesystems
221 -d|--all-devices::::
222 scan all devices under /dev, otherwise the devices list is extracted from the
223 /proc/partitions file. This is a fallback option if there's no device node
224 manager (like udev) available in the system.
225 --raw::::
226 raw numbers in bytes, without the 'B' suffix
227 --human-readable::::
228 print human friendly numbers, base 1024, this is the default
229 --iec::::
230 select the 1024 base for the following options, according to the IEC standard
231 --si::::
232 select the 1000 base for the following options, according to the SI standard
233 --kbytes::::
234 show sizes in KiB, or kB with --si
235 --mbytes::::
236 show sizes in MiB, or MB with --si
237 --gbytes::::
238 show sizes in GiB, or GB with --si
239 --tbytes::::
240 show sizes in TiB, or TB with --si
241
242 *sync* <path>::
243 Force a sync of the filesystem at 'path'. This is done via a special ioctl and
244 will also trigger cleaning of deleted subvolumes. Besides that it's equivalent
245 to the `sync`(1) command.
246
247 *usage* [options] <path> [<path>...]::
248 Show detailed information about internal filesystem usage. This is supposed to
249 replace the *btrfs filesystem df* command in the long run.
250 +
251 The level of detail can differ if the command is run under a regular or the
252 root user (due to use of restricted ioctl). For both there's a summary section
253 with information about space usage:
254 +
255 -------------------------
256 $ btrfs fi usage /path
257 WARNING: cannot read detailed chunk info, RAID5/6 numbers will be incorrect, run as root
258 Overall:
259     Device size:                   1.82TiB
260     Device allocated:              1.17TiB
261     Device unallocated:          669.99GiB
262     Device missing:                  0.00B
263     Used:                          1.14TiB
264     Free (estimated):            692.57GiB      (min: 692.57GiB)
265     Data ratio:                       1.00
266     Metadata ratio:                   1.00
267     Global reserve:              512.00MiB      (used: 0.00B)
268 -------------------------
269 +
270 The root user will also see stats broken down by block group types:
271 +
272 -------------------------
273 Data,single: Size:1.15TiB, Used:1.13TiB
274    /dev/sdb        1.15TiB
275
276 Metadata,single: Size:12.00GiB, Used:6.45GiB
277    /dev/sdb       12.00GiB
278
279 System,single: Size:32.00MiB, Used:144.00KiB
280    /dev/sdb       32.00MiB
281
282 Unallocated:
283    /dev/sdb      669.99GiB
284 -------------------------
285 +
286 `Options`
287 +
288 -b|--raw::::
289 raw numbers in bytes, without the 'B' suffix
290 -h|--human-readable::::
291 print human friendly numbers, base 1024, this is the default
292 -H::::
293 print human friendly numbers, base 1000
294 --iec::::
295 select the 1024 base for the following options, according to the IEC standard
296 --si::::
297 select the 1000 base for the following options, according to the SI standard
298 -k|--kbytes::::
299 show sizes in KiB, or kB with --si
300 -m|--mbytes::::
301 show sizes in MiB, or MB with --si
302 -g|--gbytes::::
303 show sizes in GiB, or GB with --si
304 -t|--tbytes::::
305 show sizes in TiB, or TB with --si
306 -T::::
307 show data in tabular format
308 +
309 If conflicting options are passed, the last one takes precedence.
310
311 EXAMPLES
312 --------
313
314 *$ btrfs filesystem defrag -v -r dir/*
315
316 Recursively defragment files under 'dir/', print files as they are processed.
317 The file names will be printed in batches, similarly the amount of data triggered
318 by defragmentation will be proportional to last N printed files. The system dirty
319 memory throttling will slow down the defragmentation but there can still be a lot
320 of IO load and the system may stall for a moment.
321
322 *$ btrfs filesystem defrag -v -r -f dir/*
323
324 Recursively defragment files under 'dir/', be verbose and wait until all blocks
325 are flushed before processing next file. You can note slower progress of the
326 output and lower IO load (proportional to currently defragmented file).
327
328 *$ btrfs filesystem defrag -v -r -f -clzo dir/*
329
330 Recursively defragment files under 'dir/', be verbose, wait until all blocks are
331 flushed and force file compression.
332
333 *$ btrfs filesystem defrag -v -r -t 64M dir/*
334
335 Recursively defragment files under 'dir/', be verbose and try to merge extents
336 to be about 64MiB. As stated above, the success rate depends on actual free
337 space fragmentation and the final result is not guaranteed to meet the target
338 even if run repeatedly.
339
340 *$ btrfs filesystem resize -1G /path*
341
342 *$ btrfs filesystem resize 1:-1G /path*
343
344 Shrink size of the filesystem's device id 1 by 1GiB. The first syntax expects a
345 device with id 1 to exist, otherwise fails. The second is equivalent and more
346 explicit. For a single-device filesystem it's typically not necessary to
347 specify the devid though.
348
349 *$ btrfs filesystem resize max /path*
350
351 *$ btrfs filesystem resize 1:max /path*
352
353 Let's assume that devid 1 exists, the filesystem does not occupy the whole block
354 device, eg. it has been enlarged and we wan the grow the filesystem. Simply using
355 'max' as size we will achieve that.
356
357 NOTE: There are two ways to minimize the filesystem on a given device. The
358 *btrfs inspect-internal min-dev-size* command, or iteratively shrink in steps.
359
360 EXIT STATUS
361 -----------
362 *btrfs filesystem* returns a zero exit status if it succeeds. Non zero is
363 returned in case of failure.
364
365 AVAILABILITY
366 ------------
367 *btrfs* is part of btrfs-progs.
368 Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for
369 further details.
370
371 SEE ALSO
372 --------
373 `mkfs.btrfs`(8),