Btrfs/it

Btrfs è un filesystem copy-on-write (CoW) per Linux che mira ad implementare caratteristiche avanzate concentrandosi al contempo sulla tolleranza agli errori, sulla riparazione e sulla facile amministrazione. Sviluppato congiuntamente da Oracle, Red Hat, Fujitsu, Intel, SUSE, STRATO e molti altri, Btrfs è concesso in licenza da GPL ed è aperto al contributo di ognuno.

Caratteristiche
Ext4 è sicuro e stabile e può gestire filesystems di grandi dimensioni con estensioni, quindi perchè cambiare? Mentre è vero che Btrfs è ancora considerato sperimentale e sta crescendo in stabilità, il momento in cui diventerà il filesystem di default per i sistemi Linux si sta avvicinando. Qualche distribuzione Linux ha già iniziato il passaggio ad esso già sui rilasci correnti. Btrfs ha un numero di caratteristiche avanzate in comune con ZFS, il che rende il file system ZFS popolare con le distribuzioni BSD e i dispositivi NAS.


 * Copy on Write (CoW) e snapshotting - Rende i backup incrementali indolori anche da un filesystem "hot" o da una macchina virtuale (VM).
 * File level checksums - Metadata per ogni file include un checksum che è utilizzato per rilevare e correggere gli errori.
 * Compression - I files possono essere compressi e decompressi immediatamente, e così vengono migliorate le performance in velocità di lettura.
 * Auto deframmentazione - I filesystems sono sintonizzati da un thread di fondo mentre sono in uso.
 * Sottovolumi - I filesystems possono condividere un singola parte di spazio del disco invece di essere ripartiti in partizioni.
 * RAID - Btrfs esegue la propria implementazione RAID così che non sono necessari né LVM né per avere il RADI. Ad oggi sono supportati RAID 0 e 1; RAID 5 e 6 sono in fase di sviluppo.
 * Le partitioni sono optional - Mentre Btrfs può lavorare con le partizioni, esso ha ANCHE il potenziale di poter utilizzare i dispositivi direttamente.
 * Deduplicazione dei dati - C'è un supporto limitato alla deduplicazione dei dati; tuttavia, la deduplicazione diventerà una caratteristica standard di Btrfs. Questa abilita Btrfs a salvare spazio confrontando i file tramite diffrazioni binarie.

Per qualsiasi approfondimento e per l'elenco completo di caratteristiche vedere upstream wiki's status page.

I nuovi filesystem raggruppati sfrutteranno facilmente i vantaggi di Btrfs con il suo copy-on-write e le sue altre caratteristiche avanzate. Ceph è un esempio di filesystem raggruppato che sembra essere promettente, e può trarre vantaggio da 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. Each command (besides the initial command) can be reduced to a very short set of instructions. This method is helpful when working from the command line to reduce the amount of characters typed.

For example, to defragment a filesystem located at, the following shows the long command:

Shorten each of the longer commands after the command by reducing them to their unique, shortest prefix. 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 for the  sub-command under the   command.

Creation
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.

Non-root
This section only supports the conversion of a non-root filesystem.

First, unmount the mountpoint:

Check the integrity of the non-root 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.

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:

External resources

 * Btrfs article - As described by the Debian wiki.
 * Btrfs article - As described by the Arch Linux wiki.
 * BTRFS Fun - On the Funtoo wiki.