btrfs-mkfs
A Rust implementation of mkfs.btrfs that creates btrfs filesystems by
constructing B-tree nodes as raw byte buffers and writing them directly to
block devices or image files with pwrite. No ioctls or mounted filesystem
required.
Usage
btrfs-mkfs [OPTIONS] <DEVICE>...
Examples
# Create a filesystem on a single device (metadata DUP, data SINGLE)
# Create on a file-backed image
# Two-device RAID1 metadata
# Custom label, xxhash checksums, block-group-tree feature
# Force overwrite an existing btrfs filesystem
Options
| Flag | Description |
|---|---|
-d, --data <PROFILE> |
Data block group profile (single, dup, raid0, raid1, raid1c3, raid1c4) |
-m, --metadata <PROFILE> |
Metadata block group profile (default: DUP single-device, RAID1 multi-device) |
-L, --label <LABEL> |
Filesystem label (max 255 bytes) |
-n, --nodesize <SIZE> |
B-tree node size (default 16 KiB, max 64 KiB) |
-s, --sectorsize <SIZE> |
Sector size (default 4 KiB) |
-b, --byte-count <SIZE> |
Limit filesystem size per device |
--checksum <TYPE> |
Checksum algorithm: crc32c (default), xxhash, sha256, blake2 |
-O, --features <LIST> |
Comma-separated feature flags (prefix ^ to disable) |
-U, --uuid <UUID> |
Set filesystem UUID |
-f, --force |
Force overwrite existing filesystem |
-K, --nodiscard |
Skip TRIM/discard before writing |
-q, --quiet |
Suppress progress output |
What's implemented
- Single and multi-device filesystems (up to N devices)
- Metadata profiles: SINGLE, DUP, RAID1, RAID1C3, RAID1C4
- Data profiles: SINGLE, DUP, RAID0, RAID1, RAID1C3, RAID1C4
- All four checksum algorithms: CRC32C, xxhash64, SHA256, BLAKE2b
- Free-space-tree and block-group-tree feature flags
- Device validation: mounted check, existing FS detection, TRIM
- Minimum device size enforcement (~133 MiB)
- Default features: extref, skinny-metadata, no-holes, free-space-tree
- Output passes
btrfs checkwith zero errors
What's not yet implemented
--rootdir(populate filesystem from a directory tree)- RAID0/5/6/10 profiles
- Zoned device support
- Mixed data+metadata mode (
-M)
Testing
Unit tests cover checksum algorithms, superblock construction, and leaf building.
Privileged integration tests create filesystem images, verify them with
btrfs check, then mount and exercise read/write operations.
# Run unit tests
# Run integration tests (requires root and btrfs-progs installed)
License
Licensed under the GNU General Public License v2.0.