Btrfs is an open-source, general-purpose file system for Linux. The name derives from the use of B-trees to store internal file system structures. Different names are used for the file system, including “Butter F S” and “B-tree F S.” Development of Btrfs began at Oracle in 2007, and now a number of companies (including Red Hat, Fujitsu, Intel, SUSE, and many others) are contributing to the development effort. Btrfs is included in the mainline Linux kernel.
Creating a Btrfs File System
1. The Btrfs utilities are provided by the btrfs-progs software package. Use the following command to list the files provided by the package.
# rpm –ql btrfs-progs
2. Use the mkfs.btrfs command to create a Btrfs file system. The syntax is:
# mkfs.btrfs [options] block_device [block_device ...]
You can create a Btrfs file system on a single device or on multiple devices. Devices can be disk partitions, loopback devices (disk images in memory), multipath devices, or LUNs that implement RAID in hardware. Some of the available options for the mkfs.btrfs command are:
|-A offset||Specify the offset from the start of the device for the file system. The default is 0, which is the start of the device.|
|-b size||Specify the size of the file system. The default is all the available storage.|
|-d type||Specify how the file system data is spanned across the devices. The type argument must be raid0, raid1, raid10, or single.|
|-l size||Specify the leaf size, the least data item in which Btrfs stores data. The default is the page size.|
|-L name||Specify a label name for the file system.|
|-m profile||Specify how the file system metadata is spanned across the devices. The profile argument must be raid0, raid1, raid10, single, or dup.|
|-M||Mix data and metadata chunks together for more efficient space utilization. This option affects performance for larger file systems, and is recommended only for file systems that are 1 GB or smaller.|
|-n size||Specify the node size. The default is the page size.|
|-s size||Specify the sector size, which is the minimum block allocation.|
|-V||Print the mkfs.btrfs version and exit.|
Creating btrfs filesystem – mkfs.btrfs Examples
1. To create a Btrfs file system on a single block device (for example, /dev/sdb):
# mkfs.btrfs /dev/sdb
2. To create a Btrfs file system on two block devices (for example, /dev/sdb and /dev/sdc):
# mkfs.btrfs /dev/sdb /dev/sdc
The default configuration for a file system with multiple devices is:
-d raid0 – Stripe the file system data across all devices.
-m raid1 – Mirror the file system metadata across all devices.
3. To create a Btrfs file system with multiple devices (/dev/sdb and /dev/sdc) and stripe both the data and the metadata:
# mkfs.btrfs –m raid0 /dev/sdb /dev/sdc
4. To create a Btrfs file system with multiple devices (/dev/sdb and /dev/sdc) and mirror both the data and the metadata:
# mkfs.btrfs –d raid1 /dev/sdb /dev/sdc
5. When you specify a single device, metadata is duplicated on that device unless you specify only a single copy. To create a Btrfs file system on a single block device (for example, /dev/sdb) and to specify not to duplicate the metadata:
# mkfs.btrfs –m single /dev/sdb
6. For RAID-10 data or metadata, you must specify an even number of at least four devices. To create a Btrfs file system and stripe the data and metadata across mirrored devices (RAID-10):
# mkfs.btrfs –d raid10 –m raid10 /dev/sd[bcde]
Mounting the File System
Use the mount command or make an entry in /etc/fstab as you would when mounting any other type of Linux file system.
You can reference either device when your file system contains multiple devices. You can also reference the file system label or the UUID.
# mount /dev/sdb /btrfs
Make sure you have the entry in /etc/fstab (Example below uses UUID of the Btrfs device):
# vi /etc/fstab UUID=e7e5c123-fg76-5gxx-a87d-gt5fed9r768e /data btrfs defaults 0 0