Btrfs

Btrfs is a new copy on write (CoW) filesystem for Linux aimed at implementing advanced features while focusing on fault tolerance, repair and easy administration. Jointly developed at Oracle, Red Hat, Fujitsu, Intel, SUSE, STRATO and many others, Btrfs is licensed under the GPL and open for contribution from anyone.

Features
Ext4 is safe and stable and can handle large filesystems with extents, but why switch? While it is true that Btrfs is still considered experimental and unstable, the time is nearing when Btrfs will become the default filesystem for Linux systems. Some Linux distributions have already begun to switch to it with their current releases. Btrfs has a number of advanced features in common with zfs, which is what made the zfs filesystem popular with BSD distributions and NAS devices.


 * Copy on Write (CoW) and snapshotting - Make incremental backups painless even from a "hot" filesystem or virtual machine (VM).
 * File level checksums - Metadata for each file includes a checksum that can be used to detect and repair errors.
 * Compression - Files may be compressed and decompressed on the fly, which speeds up read performance.
 * Autodefrag - The filesystems may be tuned by a background thread while they are being used.
 * Subvolumes - Filesystems can share a single pool of space instead of being put into their own partitions.
 * RAID - Btrfs does its own RAID implementations so LVM or are not required in order to have RAID. Currently RAID 0 and 1 are support; RAID 5 and 6 are upcoming.
 * Partitions are optional - While it can be given partitions to work with, Btrfs has the potential to use raw devices (/dev/ ).
 * Data Deduplication (upcoming) - There is limited data deduplication support, however deduplication will eventually become a standard feature in Btrfs. This enables Btrfs to save space by comparing files via binary diffs.

Down the road, new clustered filesystems will readily take advantage of Btrfs with its copy on write and other advanced features for their object stores. ceph is one example of a clustered filesystem that looks very promising, and it knows how to take advantage of Btrfs.

Kernel
Activate the following kernel option to enable Btrfs support:

Emerge
The package contains the utilities necessary to work with the Btrfs filesystem.

Usage
Typing long Btrfs commands can quickly become a hassle. A tip is that each command (besides the initial command) can be reduced down to being unique. It is helpful to use this method when working from the command-line to reduce the amount of characters typed which speeds up the work process.

For example, to defragment a filesystem located at, instead of typing the long command:

Shorten each of the longer commands after the command by reducing them to down to being unique. In this context, unique means that no other commands will match the command at the command's shortest length. The shortened version of the above command is:

No other commands start with  ;   is the only one. The same goes the  sub-command under the   command.

Using shortened commands can speed up Btrfs management.

Creation
To create an Btrfs filesystem on the partition:

In the example above, replace  with the partition number and   with the disk letter that is to be formatted. For example, if the third partition of the first drive in the system was to be formatted to Btrfs, run:

requires 280 megs or more.

Mount
After creation, filesystems can be mounted in several ways:


 * - Manual mount.
 * - Defining mount points in enables automatic mounts on system boot.
 * Removable media - Automatic mounts on demand (useful for USB drives).
 * AutoFS - Automatic mount on filesystem access.
 * Btrfs/System Root Guide - Use the filesystem as a collection of volumes including one as a system root

Compression
Btrfs supports transparent compression using the zlib and lzo algorithms.

Is possible to compress specific files using the file system attributes.

The  mount option set the default behavior to compress all the newly created files. In order to re-compress the whole file system, run the following command:

Depending on the CPU and Disk capabilities, using lzo compression could improve the overall throughput.

Converting ext* based file systems
It is possible to concert ext2, ext3, and ext4 filesystems to Btrfs using the utility.

Non-root
This section only supports the conversion of a non-root filesystem. First, unmount the mountpoint:

Check the integrity of non-root filesystem using the appropriate tool. In this case the filesystem is ext4:

Use to convert the ext* formatted device into a btrfs formatted device:

Be sure to edit after the device has been formatting in order to change the filesystem column from ext4 to btrfs:

Defragmentation
Another feature of Btrfs is online defragmentation. To defragment a root Btrfs filesystem run:

RAID
Creating RAIDs in btrfs is much easier than creating RAIDs using.

The simplest method is to use the entire device to create a RAID:

Subvolumes
As mentioned above in the features list, Btrfs has the ability to create subvolumes. Subvolumes can be used to better organize and manage data. They become especially powerful when combine with snapshots. Important distinctions must be made between Btrfs subvolumes and subvolumes created by Logical Volume Management (LVM). Btrfs subvolumes are not block level devices, they are POSIX file namespaces. They can be created at any location in the filesystem and will act like any other directory on the system with one special caveat: subvolumes can be mounted and unmounted. Subvolumes are nestable (subvolumes can be created inside other subvolumes), and easily created or removed.

Create
To create a subvolume, issue the following command inside a Btrfs filesystem's name space:

Replace  with the desired destination and subvolume name. For example, if a Btrfs filesystem exists at, a subvolume could be created inside of it using the following command:

List
To see the subvolume(s) that have been created use the  command followed by a Btrfs filesystem location. If the current directory is somewhere inside a Btrfs filesystem, the following command will display the subvolume(s) that exist on the filesystem:

If a Btrfs filesystem with subvolumes exists at the mount point created in the example command above, the output from the list command will look similar to the following:

Remove
Since subvolumes can be properly removed by using the  command followed by the path to the subvolume. All available subvolume paths in a Btrfs filesystem can be seen using the list command above

As stated above, be sure to replace  with the actual path to the subvolume that will be removed. To delete the subvolume used in the examples above, the following command would be issued:

Snapshots
Snapshots are subvolumes that share data and metadata with other subvolumes. This is made possible by Btrfs' Copy on Write (CoW) ability. Snapshots can be used for several purposes, one of which is to create backups of file system structures at specific points in time.

If the root filesystem is Btrfs, it is possible to create a snapshot using the  commands:

The following small shell script can be added to a timed cron job to create a time stamped snapshot backup of a Btrfs formatted root filesystem. The timestamps can be adjusted to whatever is preferred by the user.

Mounting btrfs fails, returns: mount: unknown filesystem type 'btrfs'
Original solution is posted here by Tim.

Solution is to build the kernel manually instead of using genkernel: