mkfs.btrfs is a utility used to create a Btrfs (short for “B-tree file system”) file system on a storage device. By default, mkfs.btrfs creates a RAID1 file system, meaning that data is stored in two identical copies, each located on a separate storage device. This provides data redundancy, allowing the file system to continue functioning even if one of the storage devices fails. The RAID1 layout is specified with the -d raid1 option, and it can be changed to other Btrfs RAID levels (e.g. RAID0, RAID10) if desired. Note that creating a Btrfs file system requires unmounting the target device, and all existing data on the device will be destroyed.
If you encounter the below error while running the command mkfs.btrfs:
mkfs.btrfs: command not found
you may try installing the below package as per your choice of distribution:
Distribution | Command |
---|---|
Debian | apt-get install btrfs-progs |
Ubuntu | apt-get install btrfs-progs |
Alpine | apk add btrfs-progs |
Arch Linux | pacman -S btrfs-progs |
Kali Linux | apt-get install btrfs-progs |
CentOS | yum install btrfs-progs |
Fedora | dnf install btrfs-progs |
Raspbian | apt-get install btrfs-progs |
mkfs.btrfs Command Examples
1. Create a btrfs filesystem on a single device:
# sudo mkfs.btrfs --metadata single --data single /dev/sda
2. Create a btrfs filesystem on multiple devices with raid1:
# sudo mkfs.btrfs --metadata raid1 --data raid1 /dev/sda /dev/sdb /dev/sdN
3. Set a label for the filesystem:
# sudo mkfs.btrfs --label "label" /dev/sda [/dev/sdN]