Difference between revisions of "Btrfs"

From ArchWiki
Jump to: navigation, search
(more features)
(Multi-device filsystem and RAID feature: tweak details)
Line 46: Line 46:
  
 
== Btrfs Features ==
 
== Btrfs Features ==
=== Multi-device filsystem and RAID feature ===
+
=== Multi-device filesystem and RAID feature ===
 
====Multi-device filesystem====
 
====Multi-device filesystem====
When creating a btrfs filesystem, you can pass as many as partitions or disk devices you want to ''mkfs.btrfs''. The filesystem will be created across these devices.
+
When creating a ''btrfs'' filesystem, you can pass as many partitions or disk devices as you want to ''mkfs.btrfs''. The filesystem will be created across these devices. You can '''"'''merge'''"''' this way, multiple partitions or devices to get a big ''btrfs'' filesystem.
  
 
You can also add or remove device from an existing btrfs filesystem (caution is mandatory).
 
You can also add or remove device from an existing btrfs filesystem (caution is mandatory).
Line 57: Line 57:
  
 
====RAID features====
 
====RAID features====
When creating multi-device filesystem, you can also specify to use RAID0, RAID1 or RAID10 across the devices you have added to the filesystem.  
+
When creating multi-device filesystem, you can also specify to use RAID0, RAID1 or RAID10 across the devices you have added to the filesystem.
  
 
=== Subvolumes ===
 
=== Subvolumes ===

Revision as of 13:22, 13 July 2012

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary end

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 by Oracle, Red Hat, Fujitsu, Intel, SUSE and many others, Btrfs is licensed under the GPL and open for contribution from anyone.

Recent Developments and News Links

  • Summary of Chris Mason's talk from LFCS 2012
  • On 2012-03-28, btrfs-progs includes btrfsck, a tool that can fix errors on btrfs filesystems.
  • Oracle has packaged this version of btrfs-progs and released it to their customers of Oracle Linux 6 and backported to 5.
  • Arch Linux supplies this version in core/btrfs-progs (since version 0.19.20120328-1).

Installation

Btrfs support is included in the the linux package (as a module). User space utilities are available in btrfs-progs.

For multi-devices support (RAID like feature of btrfs) aka btrfs volume in early boot, you have to enable btrfs mkinitcpio hook (provided by mkinitcpio package) to be able to use, for example, a root btrfs volume. If the btrfs volume is a non-system volume, one can only use USEBTRFS="yes" in /etc/rc.conf

However, if you only use bare btrfs partition, such options are not needed.

For more option/feature, users may want to install mkinitcpio-btrfsAUR from the AUR. This package will install a mkinitcpio hook called btrfs_advanced intended for those who wish to have automatic rollback feature.

Creating a Btrfs Partition

Format a New Partition to Btrfs

# mkfs.btrfs [options] dev [dev ...]

One can select multiple devices to create a RAID. Supported RAID levels include RAID 0, RAID 1 and RAID 10. By default, metadata is mirrored and data is striped.

Convert Ext3/4 to Btrfs

Warning: GRUB Legacy cannot boot with btrfs as root. Users need to install either GRUB or Syslinux. This guide assumes users are aware of this limitation.
  1. Boot a live CD (Arch for example)
  2. Enable [remote-core] and [remote-testing]
  3. Setup the network
  4. modprobe btrfs
  5. Install btrfs-progs (make sure versions of dependencies match: glibc, e2fsprogs)
  6. Run btrfs-convert
  7. Mount the converted partition and modify the /etc/fstab file specifying either auto or btrfs for the partition type.
  8. Chroot into the system and rebuild the GRUB entry (see Install from Existing Linux and GRUB articles, if unfamiliar with this procedure.

Btrfs Features

Multi-device filesystem and RAID feature

Multi-device filesystem

When creating a btrfs filesystem, you can pass as many partitions or disk devices as you want to mkfs.btrfs. The filesystem will be created across these devices. You can "merge" this way, multiple partitions or devices to get a big btrfs filesystem.

You can also add or remove device from an existing btrfs filesystem (caution is mandatory).

A multi-device filesystem is not recognized until

 # btrfs device scan

has been run. This is the purpose of the btrfs mkinitcpio hook or the USEBTRFS variable in /etc/rc.conf

RAID features

When creating multi-device filesystem, you can also specify to use RAID0, RAID1 or RAID10 across the devices you have added to the filesystem.

Subvolumes

One of the features of btrfs is the use of subvolumes. Subvolumes are basically a named btree that holds files and directories. They have inodes inside the tree of tree roots and can have non-root owners and groups. Subvolumes can optionally be given a quota of blocks. All of the blocks and file extents inside of subvolumes are reference counted to allow snapshotting. Similar to the dynamically expanding storage of a virtual machine that will only use as much space on a device as needed. Eliminating several half-filled partitions. One can also mount the subvolumes with different mount options giving more flexibility in security.

To create a subvolume:

# btrfs subvolume create [<dest>/]

For increased flexibility, install your system into a dedicated subvolume, and use:

rootflags=subvol=<whatever you called the subvol>

In the kernel boot parameters. It makes system rollbacks possible.

If using for the root partition, it is advisable to add crc32c to the modules array in /etc/mkinitcpio.conf as well as adding btrfs to the HOOKS.

Snapshots

To create a snapshot:

# btrfs subvolume snapshot <source> [<dest>/]<name>

Snapshots are not recursive, this means that every subvolume inside subvolume will be an empty directory inside the snapshot.

Defragmentation

Btrfs supports online defragmentation. To defragment the metadata of the root folder, simply do:

# btrfs filesystem defragment /

This will not defragment the entire system. For more information, see this page on the btrfs wiki.

Compression

Btrfs supports transparent compression, which means every file on the partition is automatically compressed. This does not only reduce the size of those files, but also improves performance, in particular if using the lzo algorithm. Compression is enabled using the compress=gzip or compress=lzo mount options. Only files created or modified after the mount option is added will be compressed, so to fully benefit from compression it should be enabled during installation. After preparing the hard drive, simply switch to another terminal (Template:Keypress), and run the following command:

# mount -o remount,compress=lzo /dev/sdXY /mnt/target

After the installation is finished, add compress=lzo to the mount options of the root filesystem in /etc/fstab.

Resources