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