btrfs – a toolbox to manage btrfs filesystems
| Use Case | Command | Description |
|---|---|---|
| Scan for devices | btrfs device scan | Scan all devices for BTRFS filesystems |
| Show filesystem info | btrfs filesystem show | Display basic information about BTRFS filesystems |
| Disk usage overview | btrfs filesystem df /mnt | Show space usage per block group |
| Start balance | btrfs balance start /mnt | Re‑distribute chunks across devices |
| Convert data profile | btrfs balance start -dconvert=raid1 /mnt | Change data profile with balancing |
| Add a device | btrfs device add /dev/sdb /mnt | Add a new device to the filesystem |
| Remove a device | btrfs device delete /dev/sdb /mnt | Remove a device (data will be relocated) |
| Replace a device | btrfs replace start /dev/old /dev/new /mnt | Replace a failing device |
| Offline check | btrfs check /dev/sda | Check and optionally repair a filesystem |
| Scrub | btrfs scrub start /mnt | Verify data integrity and repair if possible |
| Create subvolume | btrfs subvolume create /mnt/@data | Create a new subvolume |
| Delete subvolume | btrfs subvolume delete /mnt/@data | Delete a subvolume |
| List subvolumes | btrfs subvolume list /mnt | List all subvolumes of a filesystem |
| Snapshot | btrfs subvolume snapshot /mnt/@src /mnt/@snap | Create a read‑write snapshot |
| Send / receive | btrfs send /mnt/@snap | btrfs receive /backup | Send snapshot incrementally to another location |
| Mount with compression | mount -o compress=zstd /dev/sda /mnt | Enable transparent compression |
| Mount subvolume | mount -o subvol=@ /dev/sda /mnt | Mount a specific subvolume |
| Mount degraded | mount -o degraded /dev/sda /mnt | Allow mount with missing devices |
| Create swapfile | truncate -s 0 swapfile && chattr +C swapfile && fallocate -l 2G swapfile && mkswap swapfile && swapon swapfile | Prepare and activate a swapfile on BTRFS |
btrfs <command> [<args>]
The btrfs utility is a toolbox for managing btrfs filesystems. There are command groups to work with subvolumes, devices, for whole filesystem or other specific actions. See section COMMANDS.
There are also standalone tools for some tasks like btrfs-convert or btrfstune that were separate historically and/or haven’t been merged to the main utility. See section STANDALONE TOOLS for more details.
For other topics (mount options, etc) please refer to the separate manual page btrfs(5).
Any command name can be shortened so long as the shortened form is unambiguous, however it is recommended to use full command names in scripts. All command groups have their manual page named btrfs-<group>.
For example: it is possible to run btrfs sub snaps instead of btrfs subvolume snapshot. But btrfs file s is not allowed, because file s may be interpreted both as filesystem show and as filesystem sync.
If the command name is ambiguous, the list of conflicting options is printed.
For an overview of a given command use btrfs command --help or btrfs [command...] --help --full to print all available options.
balance — Balance btrfs filesystem chunks across single or several devices. See btrfs-balance(8) for details.check — Do off‑line check on a btrfs filesystem. See btrfs-check(8) for details.device — Manage devices managed by btrfs, including add/delete/scan and so on. See btrfs-device(8) for details.filesystem — Manage a btrfs filesystem, including label setting/sync and so on. See btrfs-filesystem(8) for details.inspect-internal — Debug tools for developers/hackers. See btrfs-inspect-internal(8) for details.property — Get/set a property from/to a btrfs object. See btrfs-property(8) for details.qgroup — Manage quota group (qgroup) for btrfs filesystem. See btrfs-qgroup(8) for details.quota — Manage quota on btrfs filesystem like enabling/rescan and etc. See btrfs-quota(8) and btrfs-qgroup(8) for details.receive — Receive subvolume data from stdin/file for restore and etc. See btrfs-receive(8) for details.replace — Replace btrfs devices. See btrfs-replace(8) for details.rescue — Try to rescue damaged btrfs filesystem. See btrfs-rescue(8) for details.restore — Try to restore files from a damaged btrfs filesystem. See btrfs-restore(8) for details.scrub — Scrub a btrfs filesystem. See btrfs-scrub(8) for details.send — Send subvolume data to stdout/file for backup and etc. See btrfs-send(8) for details.subvolume — Create/delete/list/manage btrfs subvolume. See btrfs-subvolume(8) for details.New functionality could be provided using a standalone tool. If the functionality proves to be useful, then the standalone tool is declared obsolete and its functionality is copied to the main tool. Obsolete tools are removed after a long (years) depreciation period.
Tools that are still in active use without an equivalent in btrfs:
btrfs-convert — in‑place conversion from ext2/3/4 filesystems to btrfsbtrfstune — tweak some filesystem properties on an unmounted filesystembtrfs-select-super — rescue tool to overwrite primary superblock from a spare copybtrfs-find-root — rescue helper to find tree roots in a filesystemDeprecated and obsolete tools:
btrfs-debug-tree — moved to btrfs inspect-internal dump-tree. Removed from source distribution.btrfs-show-super — moved to btrfs inspect-internal dump-super, standalone removed.btrfs-zero-log — moved to btrfs rescue zero-log, standalone removed.For space‑constrained environments, it’s possible to build a single binary with functionality of several standalone tools. This follows the concept of busybox where the file name selects the functionality. This works for symlinks or hardlinks. The full list can be obtained by btrfs help --box.
btrfs returns a zero exit status if it succeeds. Non zero is returned in case of failure.
btrfs is part of btrfs-progs. Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for further details.
btrfs(5), btrfs-balance(8), btrfs-check(8), btrfs-convert(8), btrfs-device(8), btrfs-filesystem(8), btrfs-inspect-internal(8), btrfs-property(8), btrfs-qgroup(8), btrfs-quota(8), btrfs-receive(8), btrfs-replace(8), btrfs-rescue(8), btrfs-restore(8), btrfs-scrub(8), btrfs-send(8), btrfs-subvolume(8), btrfstune(8), mkfs.btrfs(8)
btrfs‑man5 – topics about the BTRFS filesystem (mount options, supported file attributes and other)
This document describes topics related to BTRFS that are not specific to the tools. Currently covers:
This section describes mount options specific to BTRFS. For generic mount options please refer to mount(8). Options are sorted alphabetically (discarding the no prefix).
Note — most mount options apply to the whole filesystem and only options in the first mounted subvolume will take effect. This is due to lack of implementation and may change in the future. This means that (for example) you can’t set per‑subvolume nodatacow, nodatasum, or compress using mount options. This should eventually be fixed, but it has proved to be difficult to implement correctly within the Linux VFS framework.
Mount options are processed in order, only the last occurrence of an option takes effect and may disable other options due to constraints (see eg. nodatacow and compress). The output of mount command shows which options have been applied.
(default: on)
Enable/disable support for Posix Access Control Lists (ACLs). See the acl(5) manual page for more information about ACLs.
The support for ACL is build‑time configurable (BTRFS_FS_POSIX_ACL) and mount fails if acl is requested but the feature is not compiled in.
(since: 3.0, default: off)
Enable automatic file defragmentation. When enabled, small random writes into files (in a range of tens of kilobytes, currently it’s 64K) are detected and queued up for the defragmentation process. Not well suited for large database workloads.
The read latency may increase due to reading the adjacent blocks that make up the range for defragmentation, successive write will merge the blocks in the new location.
Warning — Defragmenting with Linux kernel versions < 3.9 or >= 3.14‑rc2 as well as with Linux stable kernel versions >= 3.10.31, >= 3.12.12 or >= 3.13.4 will break up the reflinks of COW data (for example files copied with cp --reflink, snapshots or de‑duplicated data). This may cause considerable increase of space usage depending on the broken up reflinks.
(default: on)
Ensure that all IO write operations make it through the device cache and are stored permanently when the filesystem is at its consistency checkpoint. This typically means that a flush command is sent to the device that will synchronize all pending data and ordinary metadata blocks, then writes the superblock and issues another flush.
The write flushes incur a slight hit and also prevent the IO block scheduler to reorder requests in a more effective way. Disabling barriers gets rid of that penalty but will most certainly lead to a corrupted filesystem in case of a crash or power loss. The ordinary metadata blocks could be yet unwritten at the time the new superblock is stored permanently, expecting that the block pointers to metadata were stored permanently before.
On a device with a volatile battery‑backed write‑back cache, the nobarrier option will not lead to filesystem corruption as the pending blocks are supposed to make it to the permanent storage.
(since: 3.0, default: off)
These debugging options control the behavior of the integrity checking module (the BTRFS_FS_CHECK_INTEGRITY config option required). The main goal is to verify that all blocks from a given transaction period are properly linked.
check_int enables the integrity checker module, which examines all block write requests to ensure on‑disk consistency, at a large memory and CPU cost.
check_int_data includes extent data in the integrity checks, and implies the check_int option.
check_int_print_mask takes a bitmask of BTRFSIC_PRINT_MASK_* values as defined in fs/btrfs/check-integrity.c, to control the integrity checker module behavior.
Force clearing and rebuilding of the disk space cache if something has gone wrong. See also: space_cache.
(since: 3.12, default: 30)
Set the interval of periodic transaction commit when data are synchronized to permanent storage. Higher interval values lead to larger amount of unwritten data, which has obvious consequences when the system crashes. The upper bound is not forced, but a warning is printed if it’s more than 300 seconds (5 minutes). Use with care.
(default: off, level support since: 5.1)
Control BTRFS file data compression. Type may be specified as zlib, lzo, zstd or no (for no compression, used for remounting). If no type is specified, zlib is used. If compress‑force is specified, then compression will always be attempted, but the data may end up uncompressed if the compression would make them larger.
Both zlib and zstd (since version 5.1) expose the compression level as a tunable knob. Zlib accepts the range [1, 9] and zstd accepts [1, 15]. If no level is set, both use a default level of 3. The value 0 is an alias for the default level.
Otherwise some simple heuristics are applied to detect an incompressible file. If the first blocks written to a file are not compressible, the whole file is permanently marked to skip compression. As this is too simple, the compress‑force is a workaround that will compress most of the files at the cost of some wasted CPU cycles on failed attempts. Since kernel 4.15, a set of heuristic algorithms have been improved by using frequency sampling, repeated pattern detection and Shannon entropy calculation to avoid that.
Note — If compression is enabled, nodatacow and nodatasum are disabled.
(default: on)
Enable data copy‑on‑write for newly created files. Nodatacow implies nodatasum, and disables compression. All files created under nodatacow are also set the NOCOW file attribute (see chattr(1)).
Note — If nodatacow or nodatasum are enabled, compression is disabled. Updates in‑place improve performance for workloads that do frequent overwrites, at the cost of potential partial writes, in case the write is interrupted (system crash, device failure).
(default: on)
Enable data checksumming for newly created files. Datasum implies datacow, ie. the normal mode of operation. All files created under nodatasum inherit the “no checksums” property, however there’s no corresponding file attribute (see chattr(1)).
Note — If nodatacow or nodatasum are enabled, compression is disabled. There is a slight performance gain when checksums are turned off, the corresponding metadata blocks holding the checksums do not need to be updated. The cost of checksumming of the blocks in memory is much lower than the IO, modern CPUs feature hardware support of the checksumming algorithm.
(default: off)
Allow mounts with less devices than the RAID profile constraints require. A read‑write mount (or remount) may fail when there are too many devices missing, for example if a stripe member is completely missing from RAID0.
Since 4.14, the constraint checks have been improved and are verified on the chunk level, not at the device level. This allows degraded mounts of filesystems with mixed RAID profiles for data and metadata, even if the device number constraints would not be satisfied for some of the profiles.
Example: metadata – raid1, data – single, devices – /dev/sda, /dev/sdb. Suppose the data are completely stored on sda, then missing sdb will not prevent the mount, even if 1 missing device would normally prevent (any) single profile to mount. In case some of the data chunks are stored on sdb, then the constraint of single/data is not satisfied and the filesystem cannot be mounted.
Specify a path to a device that will be scanned for BTRFS filesystem during mount. This is usually done automatically by a device manager (like udev) or using the btrfs device scan command (eg. run from the initial ramdisk). In cases where this is not possible the device mount option can help.
Note — booting eg. a RAID1 system may fail even if all filesystem’s device paths are provided as the actual device nodes may not be discovered by the system at that point.
(default: off, async support since: 5.6)
Enable discarding of freed file blocks. This is useful for SSD devices, thinly provisioned LUNs, or virtual machine images; however, every storage layer must support discard for it to work.
In the synchronous mode (sync or without option value), lack of asynchronous queued TRIM on the backing device TRIM can severely degrade performance, because a synchronous TRIM operation will be attempted instead. Queued TRIM requires newer than SATA revision 3.1 chipsets and devices.
The asynchronous mode (async) gathers extents in larger chunks before sending them to the devices for TRIM. The overhead and performance impact should be negligible compared to the previous mode and it’s supposed to be the preferred mode if needed.
If it is not necessary to immediately discard freed blocks, then the fstrim tool can be used to discard all free blocks in a batch. Scheduling a TRIM during a period of low system activity will prevent latent interference with the performance of other operations.
(default: off)
Enable verbose output for some ENOSPC conditions. It’s safe to use but can be noisy if the system reaches near‑full state.
(since: 3.4, default: bug)
Action to take when encountering a fatal error.
bug — BUG() on a fatal error, the system will stay in the crashed state and may be still partially usable, but reboot is required for full operation.panic — panic() on a fatal error, depending on other system configuration, this may be followed by a reboot. Please refer to the documentation of kernel boot parameters, eg. panic, oops or crashkernel.(default: off)
This option forces any data dirtied by a write in a prior transaction to commit as part of the current commit, effectively a full filesystem sync.
This makes the committed state a fully consistent view of the file system from the application’s perspective (i.e. it includes all completed file system operations). This was previously the behavior only when a snapshot was created.
When off, the filesystem is consistent but buffered writes may last more than one transaction commit.
(depends on compile‑time option BTRFS_DEBUG, since: 4.4, default: off)
A debugging helper to intentionally fragment given type of block groups. The type can be data, metadata or all. This mount option should not be used outside of debugging environments.
(default: off, even read‑only)
The tree‑log contains pending updates to the filesystem until the full commit. The log is replayed on next mount, this can be disabled by this option. See also treelog. Note that nologreplay is the same as norecovery.
Warning — currently, the tree log is replayed even with a read‑only mount! To disable that behaviour, mount also with nologreplay.
(default: min(2048, page size))
Specify the maximum amount of space that can be inlined in a metadata B‑tree leaf. The value is specified in bytes, optionally with a K suffix (case insensitive). In practice this value is limited by the filesystem block size (named sectorsize at mkfs time) and memory page size of the system. In case of sectorsize limit, there’s some space unavailable due to leaf headers. For example, a 4k sectorsize, maximum size of inline data is about 3900 bytes.
Inlining can be completely turned off by specifying 0. This will increase data block slack if file sizes are much smaller than block size but will reduce metadata consumption in return.
(default: 0, internal logic)
Specifies that 1 metadata chunk should be allocated after every value data chunks. Default behaviour depends on internal logic, some percent of unused metadata space is attempted to be maintained but is not always possible if there’s not enough space left for chunk allocation. The option could be useful to override the internal logic in favor of the metadata allocation if the expected workload is supposed to be metadata intense (snapshots, reflinks, xattrs, inlined files).
(since: 4.5, default: off)
Do not attempt any data recovery at mount time. This will disable logreplay and avoids other write operations. Note that this option is the same as nologreplay.
(since: 3.12, default: off)
Force check and rebuild procedure of the UUID tree. This should not normally be needed.
(since: 5.9)
Modes allowing mount with damaged filesystem structures.
usebackuproot (since: 5.9, replaces standalone option usebackuproot)nologreplay (since: 5.9, replaces standalone option nologreplay)ignorebadroots, ibadroots (since: 5.11)ignoredatacsums, idatacsums (since: 5.11)all (since: 5.9)(since: 3.3, default: off)
Skip automatic resume of an interrupted balance operation. The operation can later be resumed with btrfs balance resume, or the paused state can be removed with btrfs balance cancel. The default behaviour is to resume an interrupted balance immediately after a volume is mounted.
(nospace_cache since: 3.2, space_cache=v1 and space_cache=v2 since 4.5, default: space_cache=v1)
Options to control the free space cache. The free space cache greatly improves performance when reading block group free space into memory. However, managing the space cache consumes some resources, including a small amount of disk space.
There are two implementations. The original v1 is the safe default. The v1 space cache can be disabled at mount time with nospace_cache without clearing.
On very large filesystems (many terabytes) and certain workloads, the performance of the v1 space cache may degrade drastically. The v2 implementation adds a new B‑tree called the free space tree. Once enabled, the v2 space cache will always be used and cannot be disabled unless it is cleared. Use clear_cache,space_cache=v1 or clear_cache,nospace_cache. If v2 is enabled, kernels without v2 support will only be able to mount the filesystem in read‑only mode.
The btrfs-check(8) and mkfs.btrfs(8) commands have full v2 free space cache support since v4.19.
(default: SSD autodetected)
Options to control SSD allocation schemes. By default, BTRFS will enable or disable SSD optimizations depending on whether a device reports as rotational (contents of /sys/block/DEV/queue/rotational). If it is 0, the ssd option is turned on.
The ssd_spread mount option attempts to allocate into bigger and aligned chunks of unused space, and may perform better on low‑end SSDs. ssd_spread implies ssd. The option nossd will disable all SSD options while nossd_spread only disables ssd_spread.
Mount subvolume from path rather than the toplevel subvolume. The path is always treated as relative to the toplevel subvolume. This mount option overrides the default subvolume set for the given filesystem.
Mount subvolume specified by a subvolid number rather than the toplevel subvolume. You can use btrfs subvolume list or btrfs subvolume show to see subvolume ID numbers. This mount option overrides the default subvolume set for the given filesystem.
Note — if both subvolid and subvol are specified, they must point at the same subvolume, otherwise the mount will fail.
(default: min(NRCPUS + 2, 8))
The number of worker threads to start. NRCPUS is number of on‑line CPUs detected at the time of mount. Small number leads to less parallelism in processing data and metadata, higher numbers could lead to a performance hit due to increased locking contention, process scheduling, cache‑line bouncing or costly data transfers between local CPU memories.
(default: on)
Enable the tree logging used for fsync and O_SYNC writes. The tree log stores changes without the need of a full filesystem sync. The log operations are flushed at sync and transaction commit. If the system crashes between two such syncs, the pending tree log operations are replayed during mount.
Warning — currently, the tree log is replayed even with a read‑only mount! To disable that behaviour, also mount with nologreplay.
(since: 4.6, default: off)
Enable autorecovery attempts if a bad tree root is found at mount time. Currently this scans a backup list of several previous tree roots and tries to use the first readable. This can be used with read‑only mounts as well.
(default: off)
Allow subvolumes to be deleted by their respective owner. Otherwise, only the root user can do that.
Note — historically, any user could create a snapshot even if he was not owner of the source subvolume, the subvolume deletion has been restricted for that reason. The subvolume creation has been restricted but this mount option is still required. Since 4.18, the rmdir(2) syscall can delete an empty subvolume just like an ordinary directory.
List of mount options that have been removed, kept for backward compatibility.
(since: 3.2, default: off, deprecated since: 4.5)
Note — this option has been replaced by usebackuproot and should not be used but will work on 4.5+ kernels.
(removed in: 5.11, since: 3.0, default: off)
Note — the functionality has been removed in 5.11, any stale data created by previous use of the inode_cache option can be removed by btrfs check --clear-ino-cache.
Some general mount options from mount(8) that affect BTRFS and are worth mentioning.
noatime — under read intensive workloads, specifying noatime significantly improves performance because no new access time information needs to be written. Without this option, the default is relatime, which only reduces the number of inode atime updates. The worst case for atime updates under relatime occurs when many files are read whose atime is older than 24h and which are freshly snapshotted. In that case the atime is updated and COW happens – for each file – in bulk. Note that noatime may break applications that rely on atime uptimes like the venerable Mutt (unless you use maildir mailboxes).
The basic set of filesystem features gets extended over time. Backward compatibility is maintained and the features are optional, need to be explicitly asked for so accidental use will not create incompatibilities.
There are several classes and the respective tools to manage the features:
btrfs inspect-internal dump-super device will dump a superblock, you can map the value of incompat_flags to the features listed below./sys/fs/btrfs/UUID/features/, one file per feature. The value 1 is for enabled and active, while 0 means the feature was enabled at mount time but turned off afterwards.List of features (see also mkfs.btrfs(8) section FILESYSTEM FEATURES):
big_metadata (since: 3.4) — the filesystem uses nodesize for metadata blocks, this can be bigger than the page sizecompress_lzo (since: 2.6.38) — the lzo compression has been used on the filesystemcompress_zstd (since: 4.14) — the zstd compression has been used on the filesystemdefault_subvol (since: 2.6.34) — the default subvolume has been setextended_iref (since: 3.7) — increased hardlink limit per file in a directory to 65536free_space_tree (since: 4.5) — free space representation using a dedicated b‑tree (v2 space cache)metadata_uuid (since: 5.0) — the main filesystem UUID is stored only in the superblock while all metadata blocks still have the UUID set at mkfs timemixed_backref (since: 2.6.31) — the last major disk format change, improved backreferencesmixed_groups (since: 2.6.37) — mixed data and metadata block groupsno_holes (since: 3.14) — improved representation of file extents where holes are not explicitly stored as an extentraid1c34 (since: 5.5) — extended RAID1 mode with copies on 3 or 4 devices respectivelyraid56 (since: 3.9) — the filesystem contains or contained a raid56 profile of block groupsrmdir_subvol (since: 4.18) — indicates that rmdir(2) can delete an empty subvolumeskinny_metadata (since: 3.10) — reduced‑size metadata for extent referencessend_stream_version (since: 5.10) — number of the highest supported send stream versionsupported_checksums (since: 5.5) — list of checksum algorithms supported by the kernel modulesupported_sectorsizes (since: 5.13) — list of values accepted as sector sizes by the running kernelsupported_rescue_options (since: 5.11) — list of values for the mount option rescuezoned (since: 5.12) — zoned mode is allocation/write friendly to host‑managed zoned devicesThe swapfile is supported since kernel 5.0. Use swapon(8) to activate it. There are some limitations:
The limitations come from the COW‑based design and mapping layer that allows advanced features. With active swapfiles, the following whole‑filesystem operations will skip swapfile extents or may fail:
To create and activate a swapfile run:
# truncate -s 0 swapfile
# chattr +C swapfile
# fallocate -l 2G swapfile
# chmod 0600 swapfile
# mkswap swapfile
# swapon swapfile
Add the following entry to /etc/fstab:
/path/swapfile none swap defaults 0 0
Several checksum algorithms are supported. The default and backward compatible is crc32c. Since kernel 5.5 there are three more with different characteristics.
The digest size affects overall size of data block checksums stored. The metadata blocks have a fixed area up to 256bits, so no increase.
Approximate relative performance (measured against CRC32C using reference software implementations on a 3.5GHz intel CPU):
| Digest | Cycles/4KiB | Ratio | Implementation |
|---|---|---|---|
| CRC32C | 1700 | 1.00 | CPU instruction |
| XXHASH | 2500 | 1.44 | reference impl. |
| SHA256 | 105000 | 61 | reference impl. |
| SHA256 | 36000 | 21 | libgcrypt/AVX2 |
| SHA256 | 63000 | 37 | libsodium/AVX2 |
| BLAKE2b | 22000 | 13 | reference impl. |
| BLAKE2b | 19000 | 11 | libgcrypt/AVX2 |
| BLAKE2b | 19000 | 11 | libsodium/AVX2 |
Many kernels are configured with SHA256 as built‑in and not as a module. Accelerated versions are provided by modules and must be loaded explicitly (modprobe sha256) before mounting the filesystem.
Btrfs supports transparent file compression. Three algorithms are available: ZLIB, LZO and ZSTD (since v4.14). Compression is on a file by file basis.
To enable compression, mount with compress or compress‑force. Please refer to section MOUNT OPTIONS.
Basic characteristics:
| Algorithm | Properties | Details |
|---|---|---|
| ZLIB | slower, higher compression ratio | levels: 1‑9, default 3; good backward compatibility |
| LZO | faster compression and decompression, worse ratio | no levels; good backward compatibility |
| ZSTD | compression comparable to zlib with higher speeds | levels: 1‑15; since 4.14, levels since 5.1 |
If the first portion of data being compressed is not smaller than the original, compression of the file is disabled – unless the filesystem is mounted with compress‑force. A flag (NOCOMPRESS) is set and it’s sticky. The flag can also be set by chattr +m or by properties.
The heuristics perform quick statistical tests on the data before compressing: data sampling, long repeated pattern detection, byte frequency, Shannon entropy.
Compression is done using the COW mechanism so it’s incompatible with nodatacow. Direct IO works on compressed files but will fall back to buffered writes. Currently nodatasum and compression don’t work together.
There are several operations that affect the whole filesystem and cannot be run in parallel. Attempt to start one while another is running will fail.
Since kernel 5.10 the currently running operation can be obtained from /sys/fs/UUID/exclusive_operation with values:
balancedevice adddevice deletedevice replaceresizeswapfile activatenoneEnqueuing is supported for several btrfs subcommands so they can be started at once and then serialized.
255PATH_MAX)extref feature is on (default), roughly 100 otherwisemixed‑bg about 109MiB, with mixed‑bg 16MiBGRUB2 (https://www.gnu.org/software/grub) has the most advanced support of booting from BTRFS.
U‑boot (https://www.denx.de/wiki/U-Boot/) has decent support but not all BTRFS features are implemented.
EXTLINUX (from https://syslinux.org) can boot but does not support all features.
The first 1MiB on each device is unused with the exception of primary superblock at offset 64KiB spanning 4KiB.
The btrfs filesystem supports setting file attributes or flags. There are old and new interfaces:
FS_IOC_GETFLAGS and FS_IOC_SETFLAGS)FS_IOC_FSGETXATTR and FS_IOC_FSSETXATTR), no standard tool but supported via xfs_io -c chattra — append only, new writes are always written at the end of the fileA — no atime updatesc — compress data, all data written after this attribute is set will be compressed. When set on a directory, newly created files inherit this attribute. Cannot be set with m at the same time.C — no copy‑on‑write, file data modifications are done in‑place. When set on a directory, newly created files inherit this attribute. Note: due to implementation limitations, this flag can be set/unset only on empty files.d — no dump, makes sense with 3rd party tools like dump(8)D — synchronous directory updatesi — immutable, no file data and metadata changes allowed even to the root userm — no compression, permanently turn off compression on the given file. When set on a directory, newly created files inherit this attribute. Cannot be set with c at the same time. (chattr support added in 1.46.2)S — synchronous updatesNo other attributes are supported. For the complete list please refer to the chattr(1) manual page.
Overlap of letters assigned to the bits with attributes, this list refers to what xfs_io(8) provides:
i — immutable, same as the attributea — append only, same as the attributes — synchronous updates, same as the attribute SA — no atime updates, same as the attributed — no dump, same as the attributeSince version 5.12 btrfs supports so called zoned mode. This is a special on‑disk format and allocation/write strategy that’s friendly to zoned devices (SMR/ZBC/ZNS in host‑managed mode). The zone size depends on the device, typical sizes are 256MiB or 1GiB, and must be a power of two.
The main constraint of zoned devices is lack of in‑place update, incompatible with:
nodatacow — overwrite in‑placefallocate — preallocating space for in‑place first writemixed‑bg — unordered writes to data and metadataInitial support lacks some features: only single profile is supported, and fstrim due to dependency on v1 free space cache.
The super block is handled as a ring buffer in two consecutive zones, starting from offsets 0, 512G and 4TiB. Each new super block is appended to the end of the zone; once filled, the zone is reset and writes continue to the next one.
There’s a character special device /dev/btrfs‑control with major/minor 10 and 234.
$ ls -l /dev/btrfs-control
crw------- 1 root root 10, 234 Jan 1 12:00 /dev/btrfs-control
The device accepts ioctl calls for: scanning devices, waiting for scan finish, getting supported features. It is created when btrfs is initialized. If accidentally deleted, it can be recreated by:
# mknod --mode=600 /dev/btrfs-control c 10 234
or (since 5.11) by # btrfs rescue create-control-device.
It is possible that a btrfs filesystem contains multiple block group profiles of the same type. This could happen when a profile conversion using balance filters is interrupted. Some btrfs commands print a warning like:
WARNING: Multiple block group profiles detected, see 'man btrfs(5)'.
WARNING: Data: single, raid1
WARNING: Metadata: single, raid1
The corresponding output of btrfs filesystem df might show multiple lines per type. This state is OK but most likely needs the user to finish the interrupted tasks. Restarting the balance with convert=raid1 will continue and end up with all block group profiles RAID1.
Note — If you’re familiar with balance filters, you can use convert=raid1,profiles=single,soft to only convert the unconverted single profiles, speeding up the conversion.
Having just one profile is desired as this also clearly defines the profile of newly allocated block groups. When multiple profiles are present, the order of selection is RAID6, RAID5, RAID10, RAID1, RAID0 as long as device number constraints are satisfied.
The COW mechanism and multiple devices enable a seeding device: extending a read‑only filesystem with another device that captures all writes. The seeding device starts as a normal filesystem, once the contents is ready, btrfstune -S 1 flags it as a seeding device. Mounting such device will not allow any writes, except adding a new device by btrfs device add. Then the filesystem can be remounted as read‑write.
Example:
# mkfs.btrfs /dev/sda
# mount /dev/sda /mnt/mnt1
# ... fill mnt1 with data
# umount /mnt/mnt1
# btrfstune -S 1 /dev/sda
# mount /dev/sda /mnt/mnt1
# btrfs device add /dev/sdb /mnt
# mount -o remount,rw /mnt/mnt1
# ... /mnt/mnt1 is now writable
The writable device can be decoupled from the seeding device and used independently:
# btrfs device delete /dev/sda /mnt/mnt1
Several things to note: it’s recommended to use only single device for the seeding device; block group profiles single and dup support the usecases above; the label is copied from the seeding device and can be changed; each new mount of the seeding device gets a new random UUID.
The RAID56 feature provides striping and parity over several devices, same as traditional RAID5/6. There are some implementation and design deficiencies that make it unreliable for some corner cases and the feature should not be used in production, only for evaluation or testing. The power failure safety for metadata with RAID56 is not 100%.
Do not use raid5 nor raid6 for metadata. Use raid1 or raid1c3 respectively. Recovering from one missing device will only need to access the remaining copy, unlike striped profiles that would need all devices all the time.
When RAID56 is on the same filesystem with different raid profiles, the space reporting may be inaccurate. Scrub on a RAID56 filesystem is started on all devices, degrading performance; workaround is to start it on each device separately. The write hole problem.
A storage model captures key physical aspects of data structure in a data store. BTRFS is based on a COW (copy on write) mode, not updating data in place but writing a new copy and atomically switching pointers.
The following assumptions about storage devices are considered (sorted by importance):
No or partial atomicity (1) — Problem: partial block contents (torn write). Detection: checksum mismatch on read. Repair: use another copy or rebuild from multiple blocks.
The flush command does not flush (2) — the most serious problem, impossible to mitigate perfectly. Writes from one generation could bleed to another, leaving data inconsistent after a crash.
Data get silently changed on write (3) — Detection: checksum mismatch. Repair: use another copy or rebuild.
Data written to another offset (ghost write) — filesystem has no information when it happens. Metadata blocks have an embedded block number for verification.
Data structures and raw data blocks are temporarily stored in computer memory before writing. Memory bit flips can have vast consequences. ECC memory lowers the chances, but not always available. Run memtest, particularly under heavy load.
DMA transfers performed by device drivers may accidentally corrupt other pages. Use up‑to‑date kernels; quirks are added when found.
Rotational HDDs typically fail at the level of individual sectors. Read failures return EIO. Check smartctl for potential issues. Cables can cause problems if not attached properly.
Data stored in cells grouped in blocks with limited number of resets. Firmware tries to avoid unnecessary resets. Observations show that the whole electronic fails at once or affects a lot of data. Run smartctl or self‑tests. Metadata writes tend to be the biggest component of lifetime writes; DUP profiles may affect reliability in both ways depending on device class.
Persistent memory usually connected over a system bus, an order of magnitude faster than SSD. Errors may exhibit as random bit flips or IO failures. Self‑tests via smartctl can help.
Firmware bugs can cause a wide range of corruptions. Check for firmware updates, use up‑to‑date kernels.
Low power flash memory in detachable card package. Adding redundancy like DUP profiles can help, but a full backup may be the best option once problems appear.
If you use unreliable hardware and don’t know about that, don’t blame the filesystem when it tells you.
acl(5), btrfs(8), chattr(1), fstrim(8), ioctl(2), mkfs.btrfs(8), mount(8), swapon(8)
Generated by phpman v4.9.26-1-g511901d Author: Che Dong Under GNU General Public License
2026-08-09 09:59 @2600:1f28:365:80b0:50b3:453e:ff52:20f7
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format