mkfs.bcachefs: Create a bcached filesystem


mkfs.bcachefs: Create a bcached filesystem inside a partition

Section overview

  • What it does
  • Quick start: a simple example
  • Common options and labeling
  • Pitfalls and best practices
  • Verification tips

What is bcached (bcachefs)?

  • bcached filesystem (bcachefs) is designed for layering cache over slower storage. It’s built to be flexible and robust, but it’s less commonly used than ext4, xfs, or btrfs. Make sure you understand your setup and have backups before creating a new filesystem on a drive or partition.

Quick start: one partition, one filesystem This creates a bcached filesystem inside a given partition. Replace /dev/sdXY with your target partition (for example /dev/sdb1).

sudo mkfs.bcachefs /dev/sdXY

If you want to give the filesystem a human-friendly label, add the -L/—fs_label option followed by the label string. The label can help you recognize the filesystem in tools like lsblk and df.

sudo mkfs.bcachefs -L my_bcachefs /dev/sdXY

Important notes and common pitfalls

  • Ensure the target partition is correct: running mkfs.bcachefs will erase all data on that partition.
  • Unmount the partition if it is mounted. Creating the filesystem while mounted is not supported and will fail or produce inconsistent results.
  • Back up important data before proceeding. There is no undo for mkfs.
  • If you’re experimenting, consider using a virtual disk or loopback file to learn safely.
  • Verify the device path carefully (e.g., /dev/sdXn). A mistaken path can wipe the wrong drive.

Guidance for real-world use

  • Plan where the cache filesystem fits in your storage topology. bcachefs can be used with a cache drive and a backing device; this post covers the basic creation step.
  • After creating the filesystem, you’ll typically need to mount it and format it with your preferred options, then tune it via bcache-tools specific to your use case.
  • Check the documentation for any distribution-specific considerations or kernel requirements.

Verifying the filesystem

  • List block devices and verify the new filesystem appears as a bcachefs filesystem:
lsblk -f
  • Mount the filesystem to a mount point and create a test file:
sudo mkdir -p /mnt/bcachefs_test
sudo mount -t bcachefs /dev/sdXY /mnt/bcachefs_test
sudo sh -c 'echo hello > /mnt/bcachefs_test/hello.txt'
cat /mnt/bcachefs_test/hello.txt

Cleanup notes

  • If you need to remove the filesystem, unmount first and then use your distro’s normal tools to wipe the partition or reuse it for another filesystem.

Further reading

See Also