Btrfs/es

"Btrfs" es un Article description::sistema de ficheros copy-on-write (CoW) para Linux enfocado a implementar características novedosas y avanzadas y, a la vez, centrado en la tolerancia a fallos, reparación y facilidad de administración. Desarrollado conjuntamente en Oracle, Red Hat, Fujitsu, Intel, SUSE, STRATO, y muchos más, Btrfs está publicado bajo la licencia GPL y se encuentra abierto a contribuciones por parte de cualquier persona.

Características
Ext4 es seguro y estable y es capaz de manejar sistemas de ficheros muy grandes sin problemas, entonces ¿Por qué cambiar?. Si bien es verdad que Btrfs aún es considerado experimental y está creciendo en cuanto a estabilidad, el momento en el que se convierta en el sistema de ficheros d por defecto en los sistemas Linux se va acercando. Algunas distribuciones ya han comenzado a cambiar en sus últimos lanzamientos. Btrfs tiene un gran número de características avanzadas en común con ZFS, las cuales hicieron que ZFS fuera tan popular entre las distribuciones de BSD y los dispositivos NAT.


 * Copy on Write (CoW) y snapshotting - Facilitar la creación de backups incluso desde un sistema de ficheros "en caliente" o de una máquina virtual.
 * Checksums a nivel de fichero - Los metadatos de cada fichero incluyen un checksum que es usado para detectar y reparar errores.
 * Compresión - Los ficheros pueden estar comprimidos o descomprimidos en vuelo, lo que aumenta la velocidad de lectura.
 * Auto-Desfragmentación - Los sistemas de ficheros son optimizados por un proceso en segundo plano "mientras" están en uso.
 * Subvolumenes - Los sistemas de ficheros pueden compartir un determinado espacio en vez de tener que utilizar sus propias particiones.
 * RAID - Btrfs tiene sus propias implementaciones de RAID de manera que LVM o no son necesarios para tener un RAID. De momento RAID 0 y 1 están soportados; RAID 5 y 6 están de camino.
 * Las particiones son opcionales - Si bien Btrfs puede trabajar con particiones, también es capaz de utilizar volumenes sin formato directamente.
 * Deduplicación de datos - El soporte de deduplicación de datos es limitado; sin embargo, eventualmente se convertirá en una característica estándar en Btrfs. Ésto permite reducir el espacio ocupado mediante la comparación binaria de ficheros.

Con el tiempo, los nuevos sistemas de ficheros en cluster tomarán ventaja de Btrfs mediante el uso de copy on write y otras características avanzadas referentes al almacenamiento de objetos. Ceph es un ejemplo de un sistema de ficheros en cluster que se ve realmente prometedor, y es capaz de aprovechar las ventajas de Btrfs.

Kernel
Active las siguientes opciones del kernel para habilitar el soporte para Btrfs:

Emerge
El paquete contiene las utilidades necesarias para trabajar con el sistema de ficheros Btrfs.

Uso
Escribir largos comandos de Btrfs se puede convertir rápidamente en un incordio. Cada comando (además del inicial) puede ser reducido a un pequeño conjunto de instrucciones. Este método es de gran ayuda cuando se trabaja desde la línea de comandos ya que ayuda a reducir el número de caracteres a teclear.

Por ejemplo, para defragmentar un sistema de ficheros localizado en, la manera larga sería:

Acorte cada uno de los comandos largos a base de reducirlos a su prefijo único. En este contexto único significa que no existe una pareja de comandos que hagan cosas diferentes, por mínimas que sean, que concidan en la forma mínima del comando. La versión acortada del comando anterior es:

Ningún otro comando de comienza con  ;   es el único. Lo mismo se aplica al comando, el cual es un subcomando del comando.

Creación
To create a 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, to format the third partition of the first drive in the system with Btrfs, run:

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.

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

The following instructions only supports the conversion of filesystems that are unmounted. To convert the root partition, boot to a system rescue disk (SystemRescueCD works nicely) and run on the conversion commands on the root partition.

First be sure the the mount point is unmounted:

Check the integrity of the filesystem using the appropriate tool. In the next example, 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 formatted to change the filesystem column from ext4 to Btrfs:

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

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

It is possible to compress specific files using the file attributes:

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

Depending on the CPU and disk performance, using lzo compression could improve the overall throughput.

It is possible to use the zlib compression algorithm instead of lzo. Zlib is slower but has a higher compression ratio:

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 can create subvolumes. Subvolumes can be used to better organize and manage data. They become especially powerful when combined 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 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 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
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 above, replace  with the actual path to the subvolume to 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 timestamped snapshot backup of a Btrfs formatted root filesystem. The timestamps can be adjusted to whatever is preferred by the user.

Mounting
A subvolume can be mounted in a location different from where it was created, or users can choose to not mount them at all. For example, a user could create a Btrfs filesystem in and create  and  subvolumes. The subvolumes could then be mounted at and, with the original top level subvolume left unmounted. This results in a configuration where the subvolumes' relative path from the top level subvolume is different from their actual path.

To mount a subvolume, perform the following command, where  is the relative path of the subvolume from the top level subvolume, obtainable through the   command:

Similarly, one can update the filesystem tab to mount their Btrfs subvolumes like so:

Clear the free space cache
It is possible to clear Btrfs' free space cache by mounting the filesystem with the  mount option. For example:

Btrfs hogging memory (disk cache)
When utilizing some of Btrfs' special abilities (like making many  copies or creating a crazy amount of snapshots), lot of memory can be eaten and not freed fast enough by the kernel's inode cache. This issue can go undiscovered since memory dedicated to the disk cache might not be clearly visible in traditional system monitoring utilities. The utility (available as part of the  package) was specifically created to determine how much memory kernel objects are consuming:

If the inode cache is consuming too much memory, the kernel can be manually instructed to drop the cache by echoing an integer value to the file.

To be safe, and to help the kernel determine the maximum amount of freeable memory, be sure to run a before running the  commands below:

Most of the time Btrfs users will probably want to to reclaim just the slab objects (dentries and btrfs_inodes):

To clear the entire disk cache (slab objects and the page cache) use instead:

More information on kernel slabs can be found in this dedoimedo blog entry.

Mounting Btrfs fails, returning mount: unknown filesystem type 'btrfs'
The original solution by Tim on Stack Exchange inspired the following solution: build the kernel manually instead of using genkernel:

Btrfs root doesn't boot
Genkernel's initramfs as created with the command below doesn't load btrfs:

Compile support for btrfs in the kernel rather than as a module, or use genkernel-next or Dracut to generate the initramfs.

External resources

 * https://wiki.debian.org/Btrfs - As described by the Debian wiki.
 * https://wiki.archlinux.org/index.php/Btrfs Btrfs article - As described by the Arch Linux wiki.
 * http://www.funtoo.org/BTRFS_Fun - BTRFS Fun on the Funtoo wiki.
 * http://marc.merlins.org/perso/btrfs/post_2014-05-04_Fixing-Btrfs-Filesystem-Full-Problems.html - Tips and tricks on fixing niche Btrfs filesystem problems in some situations.