bcachefs

On this page 8

bcachefs is a copy-on-write filesystem for Linux that combines data checksumming, transparent compression, native encryption, snapshots, replication and multi-device storage tiering in a single kernel filesystem. It grew out of bcache, the block-layer caching driver, and reuses its core idea: a fast, general-purpose key-value store built on B+ trees, with the filesystem implemented as a layer on top of that store.

In the Linux filesystem landscape, bcachefs targets the same feature space as Btrfs and ZFS while aiming for the predictable performance of ext4 and XFS. It was merged into the mainline kernel in Linux 6.7 as an experimental filesystem, later marked as externally maintained, and removed from the mainline tree in Linux 6.18; it is now distributed mainly as an out-of-tree DKMS module together with the userspace package bcachefs-tools.

How bcachefs stores data and metadata

bcachefs stores all metadata in B+ trees keyed by inode number, offset and snapshot ID, rather than in fixed on-disk tables. Separate trees hold extents, inodes, directory entries, extended attributes, allocation information and snapshot records, and a write-ahead journal records recent updates so that tree nodes can be written lazily and in large batches.

Tree nodes are large, typically 256 KiB, and are themselves log-structured: new keys are appended to a node until it is compacted, which keeps random metadata writes cheap. Data space is divided into buckets, the allocation unit inherited from bcache, and a background process called copygc moves live data out of fragmented buckets so they can be reused.

Because every write goes to a new location, bcachefs is copy-on-write: existing data is never overwritten in place, which makes atomic updates, snapshots and checksums natural rather than bolted on. The table below summarizes the main structures.

StructureRolePractical effect
Extents btreeMaps file offsets to physical locationsLarge contiguous extents, low fragmentation
Inodes btreeStores file metadata and optionsPer-file compression and replication settings
JournalRecords metadata updates before tree writesFast commits and crash consistency
BucketsFixed allocation units on each deviceEfficient space reuse via copygc
Snapshots btreeTracks the snapshot tree and IDsCheap, scalable snapshots of subvolumes
Core on-disk structures in bcachefs

Key features and mount options of bcachefs

Most bcachefs features are controlled by options that can be set filesystem-wide, per directory or per file, which is unusual among Linux filesystems. Options are given to bcachefs format, as mount options or later through extended attributes, and child files inherit them from their parent directory.

OptionTypical valuesWhat it controls
data_checksumcrc32c (default), crc64, xxhash, noneEnd-to-end integrity of file data
compressionlz4, gzip, zstd, noneInline compression of new writes
background_compressionzstd at a higher levelRecompression when data moves to slow tiers
data_replicas1 to 4Number of copies of file data
metadata_replicasOften 2 on multi-device setsCopies of btree metadata
encryptedSet at format timeChaCha20/Poly1305 authenticated encryption
Commonly used bcachefs options

Native encryption uses ChaCha20 for confidentiality and Poly1305 as a message authentication code, so encrypted data is also authenticated against tampering. Encryption must be chosen when the filesystem is created and is unlocked with bcachefs unlock before mounting.

Erasure coding with Reed-Solomon stripes is implemented but has long been described as experimental, so most production setups rely on plain replication instead.

Multi-device pools and storage tiering

A single bcachefs filesystem can span several block devices of different speeds and sizes, mounted with a colon-separated list such as mount -t bcachefs /dev/nvme0n1:/dev/sda:/dev/sdb /mnt. Devices can be grouped by labels such as ssd and hdd, and target options decide where each kind of I/O lands.

  • foreground_target receives new writes, usually the fast SSD group.
  • background_target is where data is moved later by the rebalance thread, usually the large HDD group.
  • promote_target holds cached copies of frequently read data.
  • metadata_target keeps btree nodes on fast media for quick lookups.

Each device also has a durability value: a device with durability 0 acts as a pure cache, while durability 2 can represent a hardware RAID volume. This tiering inside the filesystem replaces the separate LVM cache or bcache layer that would otherwise sit below ext4 or XFS.

How bcachefs compares with other Linux filesystems

bcachefs is most often compared with Btrfs and ZFS, the other copy-on-write filesystems used on Linux, and with the conventional journaling filesystems that most distributions install by default.

FilesystemDesignStrengthsMain caveat
bcachefsCopy-on-write, btree key-value storeTiering, per-file options, native encryptionOut of mainline, younger code base
BtrfsCopy-on-write, B-treeMainline, mature snapshots and send/receiveRAID 5 and 6 still not recommended
ZFSCopy-on-write, pooled storageVery mature integrity and RAID-ZOut-of-tree for licensing reasons
ext4Journaling, in-place updatesSimplicity and wide toolingNo data checksums or snapshots
XFSJournaling, extent-basedScales to very large filesNo native snapshots or compression
bcachefs and related Linux filesystems

Unlike ZFS, bcachefs is GPL-licensed and was designed for the Linux kernel, so its out-of-tree status is a maintenance and process question, not a licensing one.

Administering bcachefs in practice

Day-to-day administration uses the bcachefs command from bcachefs-tools, which covers formatting, device management, repair and subvolume handling. The decision table below lists common tasks.

TaskCommandNote
Create a filesystembcachefs format --compression=zstd /dev/sdXOptions can also be set later
Add a devicebcachefs device add /mnt /dev/sdYWorks on a mounted filesystem
Remove a devicebcachefs device evacuate then device removeData is migrated first
Create a snapshotbcachefs subvolume snapshot /mnt/a /mnt/a-snapSnapshots are subvolumes
Check and repairbcachefs fsck /dev/sdXOnline fsck is also supported
Show usagebcachefs fs usage -h /mntPer-device and per-replica breakdown
Common bcachefs administration tasks

Because the module is now distributed outside the kernel tree, administrators must make sure the DKMS module rebuilds for every new kernel and is included in the initramfs if the root filesystem is bcachefs; otherwise the system will not boot after an upgrade.

Limitations and risks of bcachefs

The main risk is maturity and support status, not the design itself. Expert administrators weigh the following points before using bcachefs for important data.

  • No mainline kernel support since Linux 6.18, so distribution kernels may not ship the module.
  • Fewer years of field use than ext4, XFS, Btrfs or ZFS, and on-disk format versions still evolve.
  • Erasure coding remains experimental; replication is the safer redundancy choice.
  • Copy-on-write fragmentation can affect databases and virtual machine images with heavy random writes.
  • Backups remain mandatory: checksums detect corruption but replicas, not checksums, repair it.

A plain-language summary

bcachefs is a way for a Linux computer to organize files on its drives. It never overwrites old data directly. Instead, it writes changes to a new spot and then switches over, so a power cut does not leave files half-changed.

It also checks every piece of data with a fingerprint called a checksum, can shrink files with compression, can lock them with encryption, and can treat a small fast SSD and a big slow hard drive as one storage pool. New files land on the fast drive first and are moved to the big drive later. The main caveat is that it is still a young filesystem and no longer ships with the standard Linux kernel.

An example from practice

A home lab administrator builds a media and backup server from one 1 TB NVMe SSD and two 8 TB hard drives. Formatting all three as one bcachefs filesystem, the administrator labels the SSD as ssd and the disks as hdd, sets foreground_target and promote_target to ssd, background_target to hdd, and sets data_replicas=2 with zstd background compression.

New uploads are written at SSD speed, then the rebalance thread moves them to both hard drives, compressed. Frequently watched files are promoted back to the SSD cache. When one hard drive later develops bad sectors, checksums flag the damaged extents and bcachefs reads the healthy replica instead, so no files are lost while the failing disk is replaced with bcachefs device add and device remove.