btrfs-progs: check: introduce traversal function for fsck
[platform/upstream/btrfs-progs.git] / Documentation / btrfs-man5.asciidoc
1 btrfs-man5(5)
2 ==============
3
4 NAME
5 ----
6 btrfs-man5 - topics about the BTRFS filesystem (mount options, supported file attributes and other)
7
8 DESCRIPTION
9 -----------
10 This document describes topics related to BTRFS that are not specific to the
11 tools.  Currently covers:
12
13 1. mount options
14
15 2. file attributes
16
17 3. control device
18
19 MOUNT OPTIONS
20 -------------
21
22 This section describes mount options specific to BTRFS.  For the generic mount
23 options please refer to `mount`(8) manpage. The options are sorted alphabetically
24 (discarding the 'no' prefix).
25
26 *acl*::
27 *noacl*::
28 (default: on)
29 +
30 Enable/disable support for Posix Access Control Lists (ACLs).  See the
31 `acl`(5) manual page for more information about ACLs.
32 +
33 The support for ACL is build-time configurable (BTRFS_FS_POSIX_ACL) and
34 mount fails if 'acl' is requested but the feature is not compiled in.
35
36 *alloc_start='bytes'*::
37 (default: 1M, minimum: 1M)
38 +
39 Debugging option to force all block allocations above a certain
40 byte threshold on each block device.  The value is specified in
41 bytes, optionally with a K, M, or G suffix (case insensitive).
42 +
43 This option was used for testing and has no practical use, it's slated to be
44 removed in the future.
45
46 *autodefrag*::
47 *noautodefrag*::
48 (since: 3.0, default: off)
49 +
50 Enable automatic file defragmentation.
51 When enabled, small random writes into files (in a range of tens of kilobytes,
52 currently it's 64K) are detected and queued up for the defragmentation process.
53 Not well suited for large database workloads.
54 +
55 The read latency may increase due to reading the adjacent blocks that make up the
56 range for defragmentation, successive write will merge the blocks in the new
57 location.
58 +
59 WARNING: Defragmenting with Linux kernel versions < 3.9 or ≥ 3.14-rc2 as
60 well as with Linux stable kernel versions ≥ 3.10.31, ≥ 3.12.12 or
61 ≥ 3.13.4 will break up the ref-links of CoW data (for example files
62 copied with `cp --reflink`, snapshots or de-duplicated data).
63 This may cause considerable increase of space usage depending on the
64 broken up ref-links.
65
66 *barrier*::
67 *nobarrier*::
68 (default: on)
69 +
70 Ensure that all IO write operations make it through the device cache and are stored
71 permanently when the filesystem is at it's consistency checkpoint. This
72 typically means that a flush command is sent to the device that will
73 synchronize all pending data and ordinary metadata blocks, then writes the
74 superblock and issues another flush.
75 +
76 The write flushes incur a slight hit and also prevent the IO block
77 scheduler to reorder requests in a more effective way. Disabling barriers gets
78 rid of that penalty but will most certainly lead to a corrupted filesystem in
79 case of a crash or power loss. The ordinary metadata blocks could be yet
80 unwritten at the time the new superblock is stored permanently, expecting that
81 the block pointers to metadata were stored permanently before.
82 +
83 On a device with a volatile battery-backed write-back cache, the 'nobarrier'
84 option will not lead to filesystem corruption as the pending blocks are
85 supposed to make it to the permanent storage.
86
87 *check_int*::
88 *check_int_data*::
89 *check_int_print_mask='value'*::
90 (since: 3.0, default: off)
91 +
92 These debugging options control the behavior of the integrity checking
93 module (the BTRFS_FS_CHECK_INTEGRITY config option required). +
94 +
95 `check_int` enables the integrity checker module, which examines all
96 block write requests to ensure on-disk consistency, at a large
97 memory and CPU cost. +
98 +
99 `check_int_data` includes extent data in the integrity checks, and
100 implies the check_int option. +
101 +
102 `check_int_print_mask` takes a bitmask of BTRFSIC_PRINT_MASK_* values
103 as defined in 'fs/btrfs/check-integrity.c', to control the integrity
104 checker module behavior. +
105 +
106 See comments at the top of 'fs/btrfs/check-integrity.c'
107 for more info.
108
109 *clear_cache*::
110 Force clearing and rebuilding of the disk space cache if something
111 has gone wrong. See also: 'space_cache'.
112
113 *commit='seconds'*::
114 (since: 3.12, default: 30)
115 +
116 Set the interval of periodic commit. Higher
117 values defer data being synced to permanent storage with obvious
118 consequences when the system crashes. The upper bound is not forced,
119 but a warning is printed if it's more than 300 seconds (5 minutes).
120
121 *compress*::
122 *compress='type'*::
123 *compress-force*::
124 *compress-force='type'*::
125 (default: off)
126 +
127 Control BTRFS file data compression.  Type may be specified as 'zlib',
128 'lzo' or 'no' (for no compression, used for remounting).  If no type
129 is specified, 'zlib' is used.  If 'compress-force' is specified,
130 all files will be compressed, whether or not they compress well. Otherwise
131 some simple heuristics are applied to detect an incompressible file. If the
132 first blocks written to a file are not compressible, the whole file is
133 permanently marked to skip compression.
134 +
135 NOTE: If compression is enabled, 'nodatacow' and 'nodatasum' are disabled.
136
137 *datacow*::
138 *nodatacow*::
139 (default: on)
140 +
141 Enable data copy-on-write for newly created files.
142 'Nodatacow' implies 'nodatasum', and disables 'compression'. All files created
143 under 'nodatacow' are also set the NOCOW file attribute (see `chattr`(1)).
144 +
145 NOTE: If 'nodatacow' or 'nodatasum' are enabled, compression is disabled.
146
147 *datasum*::
148 *nodatasum*::
149 (default: on)
150 +
151 Enable data checksumming for newly created files.
152 'Datasum' implies 'datacow', ie. the normal mode of operation. All files created
153 under 'nodatasum' inherit the "no checksums" property, however there's no
154 corresponding file attribute (see `chattr`(1)).
155 +
156 NOTE: If 'nodatacow' or 'nodatasum' are enabled, compression is disabled.
157
158 *degraded*::
159 (default: off)
160 +
161 Allow mounts with less devices than the raid profile constraints
162 require.  A read-write mount (or remount) may fail with too many devices
163 missing, for example if a stripe member is completely missing from RAID0.
164
165 *device='devicepath'*::
166 Specify a path to a device that will be scanned for BTRFS filesystem during
167 mount. This is usually done automatically by a device manager (like udev) or
168 using the *btrfs device scan* command (eg. run from the initial ramdisk). In
169 cases where this is not possible the 'device' mount option can help.
170 +
171 NOTE: booting eg. a RAID1 system may fail even if all filesystem's 'device'
172 paths are provided as the actual device nodes may not be discovered by the
173 system at that point.
174
175 *discard*::
176 *nodiscard*::
177 (default: off)
178 +
179 Enable discarding of freed file blocks using TRIM operation.  This is useful
180 for SSD devices, thinly provisioned LUNs or virtual machine images where the
181 backing device understands the operation. Depending on support of the
182 underlying device, the operation may severely hurt performance in case the TRIM
183 operation is synchronous (eg. with SATA devices up to revision 3.0).
184 +
185 If discarding is not necessary to be done at the block freeing time, there's
186 `fstrim` tool that lets the filesystem discard all free blocks in a batch,
187 possibly not much interfering with other operations. Also, the the device may
188 ignore the TRIM command if the range is too small, so running the batch discard
189 can actually discard the blocks.
190
191 *enospc_debug*::
192 *noenospc_debug*::
193 (default: off)
194 +
195 Enable verbose output for some ENOSPC conditions. It's safe to use but can
196 be noisy if the system reaches near-full state.
197
198 *fatal_errors='action'*::
199 (since: 3.4, default: bug)
200 +
201 Action to take when encountering a fatal error.
202 +
203 *bug*::::
204 'BUG()' on a fatal error, the system will stay in the crashed state and may be
205 still partially usable, but reboot is required for full operation
206 +
207 *panic*::::
208 'panic()' on a fatal error, depending on other system configuration, this may
209 be followed by a reboot. Please refer to the documentation of kernel boot
210 parameters, eg. 'panic', 'oops' or 'crashkernel'.
211
212 *flushoncommit*::
213 *noflushoncommit*::
214 (default: on)
215 +
216 This option forces any data dirtied by a write in a prior transaction to commit
217 as part of the current commit.  This makes the committed state a fully
218 consistent view of the file system from the application's perspective (i.e., it
219 includes all completed file system operations).  This was previously the
220 behavior only when a snapshot was created.
221 +
222 Disabling flushing may improve performance but is not crash-safe.
223
224 *fragment='type'*::
225 (depends on compile-time option BTRFS_DEBUG, since: 4.4, default: off)
226 +
227 A debugging helper to intentionally fragment given 'type' of block groups. The
228 type can be 'data', 'metadata' or 'all'. This mount option should not be used
229 outside of debugging environments and is not recognized if the kernel config
230 option 'BTRFS_DEBUG' is not enabled.
231
232 *inode_cache*::
233 *noinode_cache*::
234 (since: 3.0, default: off)
235 +
236 Enable free inode number caching. Not recommended to use unless files on your
237 filesystem get assigned inode numbers that are approaching 2^64^. Normally, new
238 files in each subvolume get assigned incrementally (plus one from the last
239 time) and are not reused. The mount option turns on caching of the existing
240 inode numbers and reuse of inode numbers of deleted files.
241 +
242 This option may slow down your system at first run, or after mounting without
243 the option.
244 +
245 NOTE: Defaults to off due to a potential overflow problem when the free space
246 checksums don't fit inside a single page.
247
248 *logreplay*::
249 *nologreplay*::
250 (default: on, even read-only)
251 +
252 Enable/disable log replay at mount time. See also 'treelog'.
253 +
254 WARNING: currently, the tree log is replayed even with a read-only mount! To
255 disable that behaviour, mount also with 'nologreplay'.
256
257 *max_inline='bytes'*::
258 (default: min(2048, page size) )
259 +
260 Specify the maximum amount of space, in bytes, that can be inlined in
261 a metadata B-tree leaf.  The value is specified in bytes, optionally
262 with a K suffix (case insensitive).  In practice, this value
263 is limited by the filesystem block size (named 'sectorsize' at mkfs time),
264 and memory page size of the system. In case of sectorsize limit, there's
265 some space unavailable due to leaf headers.  For example, a 4k sectorsize,
266 maximum size of inline data is about 3900 bytes.
267 +
268 Inlining can be completely turned off by specifying 0. This will increase data
269 block slack if file sizes are much smaller than block size but will reduce
270 metadata consumption in return.
271 +
272 NOTE: the default value has changed to 2048 in kernel 4.6.
273
274 *metadata_ratio='value'*::
275 (default: 0, internal logic)
276 +
277 Specifies that 1 metadata chunk should be allocated after every 'value' data
278 chunks. Default behaviour depends on internal logic, some percent of unused
279 metadata space is attempted to be maintained but is not always possible if
280 there's not enough space left for chunk allocation. The option could be useful to
281 override the internal logic in favor of the metadata allocation if the expected
282 workload is supposed to be metadata intense (snapshots, reflinks, xattrs,
283 inlined files).
284
285 *recovery*::
286 (since: 3.2, default: off, deprecated since: 4.5)
287 +
288 NOTE: this option has been replaced by 'usebackuproot' and should not be used
289 but will work on 4.5+ kernels.
290
291 *norecovery*::
292 (since: 4.5, default: off)
293 +
294 Do not attempt any data recovery at mount time. This will disable 'logreplay'
295 and avoids other write operations.
296 +
297 NOTE: The opposite option 'recovery' used to have different meaning but was
298 changed for consistency with other filesystems, where 'norecovery' is used for
299 skipping log replay. BTRFS does the same and in general will try to avoid any
300 write operations.
301
302 *rescan_uuid_tree*::
303 (since: 3.12, default: off)
304 +
305 Force check and rebuild procedure of the UUID tree. This should not
306 normally be needed.
307
308 *skip_balance*::
309 (since: 3.3, default: off)
310 +
311 Skip automatic resume of interrupted balance operation after mount.
312 May be resumed with *btrfs balance resume* or the paused state can be removed
313 by *btrfs balance cancel*. The default behaviour is to start interrutpd balance.
314
315 *space_cache*::
316 *space_cache=v2*::
317 *nospace_cache*::
318 ('nospace_cache' since: 3.2, 'space_cache=v2' since 4.5, default: on)
319 +
320 Options to control the free space cache.  This affects performance as searching
321 for new free blocks could take longer if the space cache is not enabled. On the
322 other hand, managing the space cache consumes some resources.  It can be
323 disabled without clearing at mount time.
324 +
325 There are two implementations of how the space is tracked. The safe default is
326 'v1'.  On large filesystems (many-terabytes) and certain workloads the 'v1'
327 performance may degrade.  This problem is addressed by 'v2', that is based on
328 b-trees, sometimes referred to as 'free-space-tree'.
329 +
330 'Compatibility notes:'
331 +
332 * the 'v2' has to be enabled manually at mount time, once
333 * kernel without 'v2' support will be able to mount the filesystem in read-only mode
334 * 'v2' can be removed by mounting with 'clear_cache'
335
336 *ssd*::
337 *nossd*::
338 *ssd_spread*::
339 (default: SSD autodetected)
340 +
341 Options to control SSD allocation schemes.  By default, BTRFS will
342 enable or disable SSD allocation heuristics depending on whether a
343 rotational or non-rotational disk is in use (contents of
344 '/sys/block/DEV/queue/rotational').  The 'ssd' and 'nossd' options
345 can override this autodetection.
346 +
347 The 'ssd_spread' mount option attempts to allocate into bigger and aligned
348 chunks of unused space, and may perform better on low-end SSDs.  'ssd_spread'
349 implies 'ssd', enabling all other SSD heuristics as well.
350
351 *subvol='path'*::
352 Mount subvolume from 'path' rather than the toplevel subvolume. The
353 'path' is absolute (ie. starts at the toplevel subvolume).
354 This mount option overrides the default subvolume set for the given filesystem.
355
356 *subvolid='subvolid'*::
357 Mount subvolume specified by a 'subvolid' number rather than the toplevel
358 subvolume.  You can use *btrfs subvolume list* to see subvolume ID numbers.
359 This mount option overrides the default subvolume set for the given filesystem.
360 +
361 NOTE: if both 'subvolid' and 'subvol' are specified, they must point at the
362 same subvolume, otherwise mount will fail.
363
364 *subvolrootid='objectid'*::
365 (irrelevant since: 3.2, formally deprecated since: 3.10)
366 +
367 A workaround option from times (pre 3.2) when it was not possible to mount a
368 subvolume that did not reside directly under the toplevel subvolume.
369
370 *thread_pool='number'*::
371 (default: min(NRCPUS + 2, 8) )
372 +
373 The number of worker threads to allocate. NRCPUS is number of on-line CPUs
374 detected at the time of mount. Small number leads to less parallelism in
375 processing data and metadata, higher numbers could lead to a performance hit
376 due to increased locking contention, cache-line bouncing or costly data
377 transfers between local CPU memories.
378
379 *treelog*::
380 *notreelog*::
381 (default: on)
382 +
383 Enable the tree logging used for 'fsync' and 'O_SYNC' writes. The tree log
384 stores changes without the need of a full filesystem sync. The log operations
385 are flushed at sync and transaction commit. If the system crashes between two
386 such syncs, the pending tree log operations are replayed during mount.
387 +
388 WARNING: currently, the tree log is replayed even with a read-only mount! To
389 disable that behaviour, mount also with 'nologreplay'.
390 +
391 The tree log could contain new files/directories, these would not exist on
392 a mounted filesystem if the log is not replayed.
393
394 *usebackuproot*::
395 *nousebackuproot*::
396 +
397 Enable autorecovery attempts if a bad tree root is found at mount time.
398 Currently this scans a backup list of several previous tree roots and tries to
399 use the first readable. This can be used with read-only mounts as well.
400 +
401 NOTE: This option has replaced 'recovery'.
402
403 *user_subvol_rm_allowed*::
404 (default: off)
405 +
406 Allow subvolumes to be deleted by their respective owner. Otherwise, only the
407 root user can do that.
408
409 FILE ATTRIBUTES
410 ---------------
411 The btrfs filesystem supports setting the following file attributes using the
412 `chattr`(1) utility:
413
414 *a*::
415 'append only', new writes are always written at the end of the file
416
417 *A*::
418 'no atime updates'
419
420 *c*::
421 'compress data', all data written after this attribute is set will be compressed.
422 Please note that compression is also affected by the mount options or the parent
423 directory attributes.
424 +
425 When set on a directory, all newly created files will inherit this attribute.
426
427 *C*::
428 'no copy-on-write', file modifications are done in-place
429 +
430 When set on a directory, all newly created files will inherit this attribute.
431 +
432 NOTE: due to implementation limitations, this flag can be set/unset only on
433 empty files.
434
435 *d*::
436 'no dump', makes sense with 3rd party tools like `dump`(8), on BTRFS the
437 attribute can be set/unset on no other special handling is done
438
439 *D*::
440 'synchronous directory updates', for more details search `open`(2) for 'O_SYNC'
441 and 'O_DSYNC'
442
443 *i*::
444 'immutable', no file data and metadata changes allowed even to the root user as
445 long as this attribute is set (obviously the exception is unsetting the attribute)
446
447 *S*::
448 'synchronous updates', for more details search `open`(2) for 'O_SYNC' and
449 'O_DSYNC'
450
451 *X*::
452 'no compression', permanently turn off compression on the given file, other
453 compression mount options will not affect that
454 +
455 When set on a directory, all newly created files will inherit this attribute.
456
457 No other attributes are supported.  For the complete list please refer to the
458 `chattr`(1) manual page.
459
460 CONTROL DEVICE
461 --------------
462
463 There's a character special device `/dev/btrfs-control` with major and minor
464 numbers 10 and 234 (the device can be found under the 'misc' category).
465
466 --------------------
467 $ ls -l /dev/btrfs-control
468 crw------- 1 root root 10, 234 Jan  1 12:00 /dev/btrfs-control
469 --------------------
470
471 The device accepts some ioctl calls that can perform following actions on the
472 filesyste module:
473
474 * scan devices for btrfs filesytem (ie. to let multi-device filesystems mount
475   automatically) and register them with the kernel module
476 * similar to scan, but also wait until the device scanning process is finished
477   for a given filesystem
478 * get the supported features (can be also found under '/sys/fs/btrfs/features')
479
480
481 The device is usually created by ..., but can be created manually:
482
483 --------------------
484 # mknod --mode=600 c 10 234 /dev/btrfs-control
485 --------------------
486
487 The device is not strictly required but the device scanning will not work and a
488 workaround would need to be used to mount a multi-device filesystem. The mount
489 option 'device' can trigger the device scanning during mount.
490
491 SEE ALSO
492 --------
493 `acl`(5),
494 `btrfs`(8),
495 `chattr`(1),
496 `fstrim`(8),
497 `ioctl`(2),
498 `mkfs.btrfs`(8),
499 `mount`(8)