Btrfs/de

Btrfs ist Article description::ein copy-on-write (CoW) [[filesystem für Linux, welches die Implementierung erweiterter Funktionen anstrebt und einen Fokus auf Fehlertoleranz, Reparatur und einfache Administration legt.]] Während es von Oracle, Red Hat, Fujitsu, Intel, SUSE, STRATO, und vielen anderen gemeinsam Entwickelt wird, ist btrfs unter der GPL lizenziert und ist für Beiträge offen.

Merkmale
Ext4 ist sicher, stabil und kann große Dateisysteme mit Extents handhaben, also warum sollte man wechseln? Während es richtig ist, dass Btrfs immer noch als experimentell angesehen wird und dessen Stabilität noch wächst, kommt es dessen Übernahme als Standarddateisystem für Linux nahe. Manche Linuxdistributionen haben bereits angefangen, dazu zu wechseln mit deren neuesten Veröffentlichungen. Btrfs hat mit ZFS einige erweiterte Features gemeinsam, welche auch das ZFS-Dateisystem bei BSD-Distributionen und NAS-Geräten so weitverbreitet gemacht haben.


 * Copy on Write (CoW) und snapshotting - Macht das erstellen eines inkrementellen Backups unproblematisch, sogar von einem stark verwendeten Dateisystem oder einer Virtuellen Maschine (VM).
 * Dateilevel-Prüfsummen - Die Metadaten jeder Datei beinhalten eine Prüfsumme, die zum Erkennen und Reparieren von Fehlern verwendet wird.
 * Kompression - Dateien können auf die Schnelle komprimiert und dekomprimiert werden, was die Leseperformance steigert.
 * Auto-Defragmentierung - Die Dateisysteme werden von einem Thread im Hintergrund verwaltet während sie benutzt werden.
 * Subvolumes - Dateisysteme können sich einen einzelnen Speicherpool teilen anstatt auf deren eigenen Partition zu sein.
 * RAID - Btrfs hat dessen eigene Implementierung von RAID, also wird LVM oder nicht für RAID benötigt. Derzeit sind RAID 0, 1 und 10 unterstützt; RAID 5 und 6 werden als Unstabil angesehen.
 * Partitionen sind optional - Obwohl Btrfs mit Partitionen arbeitet, kann es auch direkt auf Rohlaufwerken benutzt werden.
 * Datendeduplizierung - Es gibt bisher nur limitierte Unterstützung für Datendeduplizierung; jedoch wird diese eventuell eine Standardfunktion von Btrfs werden. Dies ermöglicht Btrfs Platz zu sparen, in dem Dateien per binary diffs verglichen werden.

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 can take advantage of Btrfs.

Kernel
Aktiviere folgende Kerneloption, um Btrfs-Unterstützung einzuschalten:

Emerge
Das Paket beinhaltet die Werkzeuge, die zum Arbeiten mit dem Btrfs-Dateisystem nötig sind.

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

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, lzo, and zstd (v5.1.0) compression 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 filesystem, run the following command:

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

As alternatives to lzo it is possible to use the zlib or zstd compression algorithms. Zlib is slower but has a higher compression ratio, whereas zstd has a good ratio between the two.

To force zlib compression across the whole filesystem:

Compression level
Since kernel version 4.15.0, zlib compression can now be set by levels 1-9. Since kernel version 5.1.0 zstd can be set to levels 1-15. For example, to set zlib to maximum compression at mount time:

Or to set minimal compression:

Or adjust compression by remounting:

The compression level should be visible in or by checking the most recent  output using the following command:

Compression ratio and disk usage
The usual userspace tools for determining used and free space like and  may provide inaccurate results on a Btrfs partition due to inherent design differences in the way files are written compared to, for example, ext2/3/4.

It is therefore advised to use the du/df alternatives provided by the btrfs userspace tool. In addition to that, The tool found in the sys-fs/compsize package can be helpful in providing additional information regarding compression ratios and the disk usage of compressed files. The following are example uses of these tools for a btrfs partition mounted under.

Multiple devices (RAID)
Btrfs can be used with multiple block devices in order to create RAIDs. Using Btrfs to create filesystems that span multiple devices is much easier than creating using since there is no initialization time needed for creation.

BTRFS handles data and metadata separately. This is an important factor to keep in mind when using a multi-device filesystem. It is possible to use separate profiles for data and metadata block groups. For example, metadata could be configured across multiple devices in RAID1, while data could be configured to RAID5. This is profile possible when using three or more block devices, since RAID5 requires a minimum of 3 block devices.

This type of profile offers the benefit of redundancy for metadata on each device and striping for data across devices, which increases read speeds. The drawback of this profile is more space than necessary is used for metadata, and write speeds are reduced for data blocks, since RAID5 uses a parity bit.

Creation
The simplest method is to use the entirety of unpartitioned block devices to create a filesystem spanning multiple devices. For example, to create a filesystem in RAID1 mode across two devices:

Conversion
Converting between RAID profiles is possible with the balance sub-command. For example, say three block devices are presently configured for RAID1 and mounted at. It is possible to convert the data in this profile from RAID1 to RAID5 with using the following command:

Conversion can be performed while the filesystem is online and in use. Possible RAID modes in btrfs include RAID0, RAID1, RAID5, RAID6, and RAID10. See the upstream BTRFS wiki for more information.

By device path
Block devices (disks) can be removed from multi-device filesystems using the btrfs device remove subcommand:

By device ID
Use the usage subcommand to determine the device IDs:

Next use the device ID to remove the device, in this case will be removed:

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:

Using with VM disk images
When using Btrfs with virtual machine disk images, it is best to disable copy-on-write on the disk images in order to speed up IO performance. This can only be performed on files that are newly created. It also possible to disable CoW on all files created within a certain directory. For example, using the command:

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 high amounts of snapshots), a lot of memory can be consumed 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 bootet nicht
Genkernel's initramfs lädt btrfs nicht so wie sie generiert wurde:

Kompiliere die Unterstützung für btrfs direkt in den Kernel anstatt eines Kernelmoduls oder Dracut, um die initramfs zu generieren.

Siehe auch

 * Btrfs snapshots - Skript, der Schnappschüsse erstellt sobald sich Dateien geändert haben
 * Btrfs/System Root Guide - Benutzen des Btrfs-Dateisystem als Sammlung von Subvolumes inklusive eines, welches als Wurzeldateisystem verwendet wird.
 * Btrfs native system root guide - Eine Alternativanleitung bezüglich der Nutzung eines Subvolumes auf einem Btrfs-Dateisystem als das Systemwurzeldateisystem.
 * Btrbk - Ein Backuptool für Btrfs-Subvolumes, welches Btrfs-spezifische Features benutzt, um einzelne Backups zu erstellen und diese auf bestimmte Backuporte zu übertragen.
 * Samba shadow copies - Benutzen von Samba um Schattenkopien als "Vorgängeversionen" auf Windowsclients anzeigen zu lassen.
 * Samba shadow copies - Benutzen von Samba um Schattenkopien als "Vorgängeversionen" auf Windowsclients anzeigen zu lassen.

Externe Ressourcen

 * https://wiki.debian.org/Btrfs - Beschreibung der Debian Wiki.
 * https://wiki.archlinux.org/index.php/Btrfs Btrfs-Artikel - Beschreibung der Arch Linux Wiki.
 * http://www.funtoo.org/BTRFS_Fun - BTRFS Fun auf der Funtoo Wiki.
 * http://marc.merlins.org/perso/btrfs/post_2014-05-04_Fixing-Btrfs-Filesystem-Full-Problems.html - Tipps und Tricks, um sehr spezifische Probleme des Btrfs-Dateisystems in manchen Situationen zu beheben.