Btrfs
Contents
Btrfs
Btrfs (B-tree File System, often pronounced as "butter FS", "better FS", or "B-tree FS") is a modern copy-on-write (COW) file system for Linux. It is designed to address the shortcomings of traditional Linux filesystems like ext4 and XFS, offering advanced features such as snapshots, built-in RAID, checksumming, and transparent compression.
Originally developed by Oracle Corporation in 2007, Btrfs is now maintained by multiple contributors, including SUSE and Facebook, and is integrated into the Linux kernel.
Key Features
- Copy-on-Write (COW) – All data and metadata modifications are written to new locations, enabling safe snapshots and data integrity.
- Snapshots and Subvolumes – Lightweight snapshots allow instant backups and rollbacks. Subvolumes can function like independent mountable directories.
- Built-in RAID Support – Supports RAID 0, 1, 10, and experimental RAID 5/6 modes without external tools.
- Checksumming – Data and metadata are checksummed independently to detect and correct silent corruption.
- Transparent Compression – Supports zlib, LZO, and zstd compression algorithms.
- Online Resizing – Allows volumes to be grown or shrunk while mounted.
- Cloning – Efficiently creates duplicates of files and directories using block-level reference.
Usage
To create a Btrfs filesystem:
<syntaxhighlight lang="bash"> mkfs.btrfs /dev/sdX1 </syntaxhighlight>
To mount a Btrfs partition:
<syntaxhighlight lang="bash"> mount -t btrfs /dev/sdX1 /mnt </syntaxhighlight>
To create a snapshot:
<syntaxhighlight lang="bash"> btrfs subvolume snapshot /mnt /mnt/snapshot1 </syntaxhighlight>
To check the filesystem:
<syntaxhighlight lang="bash"> btrfs check /dev/sdX1 </syntaxhighlight>
Subvolumes and Snapshots
Btrfs supports subvolumes and snapshots natively:
- Subvolumes are logical divisions of the filesystem that can be managed independently.
- Snapshots are read-only or read-write clones of a subvolume at a given point in time, useful for backups and system rollback.
RAID Support
Btrfs can manage multiple devices without LVM or mdadm:
<syntaxhighlight lang="bash"> mkfs.btrfs -m raid1 -d raid1 /dev/sdb /dev/sdc </syntaxhighlight>
> Note: As of 2024, RAID 5 and 6 are still considered **unstable** in production environments.
Limitations
- RAID 5/6 is experimental and not recommended for production.
- Lower performance under heavy fragmentation compared to ext4/XFS.
- Recovery from serious corruption can be complex.
- Less mature compared to ZFS for enterprise data storage use cases.
Comparison with Other Filesystems
Feature | Btrfs | ext4 | XFS | ZFS | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Copy-on-write | Yes | No | No | Yes | Snapshots | Yes | No | No | Yes | Compression | Yes | No | No | Yes | Checksumming | Yes | Metadata only | Metadata only | Yes | Built-in RAID | Yes | No | No | Yes | Max file size | 16 EiB | 16 TiB | 8 EiB | 16 EiB | Online resize | Yes (grow/shrink) | Yes (grow/shrink) | Yes (grow only) | Yes (grow only) | Platform | Linux only | Linux | Linux | Linux, FreeBSD | Development maturity | Active | Stable | Mature | Mature |
Common Use Cases
- Linux desktops and laptops (especially with snapshots for rollback)
- NAS devices and home servers
- Container storage (e.g., Docker, LXC)
- Backup systems
Distributions Supporting Btrfs
- Fedora (default for Workstation)
- openSUSE and SUSE Linux Enterprise
- Ubuntu (optional during installation)
- Debian (optional filesystem choice)