0xnhl

BTRFS

/ Update
2 min read

Btrfs (B-tree File System) is a modern GPL-licensed Copy-on-Write (CoW) file system for Linux aimed at implementing advanced features while focusing on fault tolerance, repair, and easy administration. It is designed to address the lack of pooling, snapshots, checksums, and integral multi-device spanning in older Linux file systems.
Developed by Oracle, Red Hat, Intel, and others, it supports large storage capacities, subvolumes, snapshots, compression, and built-in RAID.

Core Features#

  • Copy-on-Write (CoW): When data is modified, it is written to a new location rather than overwriting the old data. This prevents data corruption during power losses.
  • Subvolumes: Essentially independent file trees within the main file system. They look like normal directories but can be mounted separately and snapshot independently.
  • Snapshots: Instantaneous, read-only (or read-write) point-in-time copies of a subvolume, made possible by CoW.
  • Checksumming: Both data and metadata are checksummed (typically using CRC32C) to detect silent data corruption.
  • Self-Healing: If a checksum fails and the system is in a RAID configuration, Btrfs will automatically fetch a good copy of the data from another drive.

Important Commands Reference#

Btrfs administration is centralized under the btrfs command-line utility.

1. File System Creation & Info#

Commands used for formatting drives and checking general file system health.

  • Format a drive:
    mkfs.btrfs /dev/sdX
    bash
  • Format multiple drives (e.g., RAID 1 for data and metadata):
    mkfs.btrfs -m raid1 -d raid1 /dev/sdX /dev/sdY
    bash
  • Show file system usage:
    btrfs filesystem df /mount/point
    bash
  • Show overall Btrfs disk usage and device info:
    btrfs filesystem show
    bash

2. Subvolumes#

Subvolumes are the building blocks of a Btrfs deployment.

  • Create a subvolume:

    btrfs subvolume create /mount/point/subvol_name
    bash
  • Delete a subvolume:

    btrfs subvolume delete /mount/point/subvol_name
    bash
  • List all subvolumes:

    btrfs subvolume list /mount/point
    bash
    Mounting Subvolumes To mount a specific subvolume via /etc/fstab, use its ID or name: mount -o subvol=subvol_name /dev/sdX /mnt/target.

3. Snapshots#

Because of CoW, snapshots take up almost zero space initially. They only grow as the original data changes.

  • Create a snapshot:
    btrfs subvolume snapshot /mount/point/source_subvol /mount/point/snapshot_name
    bash
  • Create a read-only snapshot (ideal for backups):
    btrfs subvolume snapshot -r /mount/point/source_subvol /mount/point/snapshot_name
    bash

4. Device Management#

Btrfs allows you to add or remove drives on the fly without unmounting the file system.

  • Add a device:
    btrfs device add /dev/sdZ /mount/point
    bash
  • Remove a device (Btrfs will safely migrate data off it first):
    btrfs device remove /dev/sdX /mount/point
    bash

5. Maintenance & Repair#

Routine maintenance is crucial for keeping Btrfs healthy and performant.

  • Scrub (Check for and repair data corruption):
    btrfs scrub start /mount/point
    bash
  • Check scrub status:
    btrfs scrub status /mount/point
    bash
  • Balance (Reallocate data chunks across disks): Useful after adding/removing devices, or to reclaim space from partially empty chunks.
    btrfs balance start /mount/point
    bash
  • Defragmentation (Fixes fragmentation caused by CoW):
    btrfs filesystem defragment -r /mount/point
    bash

DOCS#

https://en.wikipedia.org/wiki/Btrfs
https://docs.kernel.org/filesystems/btrfs.html
https://btrfs.readthedocs.io/en/latest/

BTRFS
https://nahil.xyz/vault/linux/btrfs/
Author Nahil Rasheed
Published at March 28, 2026
Disclaimer This content is provided strictly for educational purposes only.