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