FileSystem > Btrfs
Btrfs is intended to address the lack of pooling, snapshots, checksums, and integral multi-device spanning in Linux file systems, these features being crucial as the use of Linux scales upward into larger storage configurations. Btrfs is designed to be a multipurpose filesystem, scaling well on very large block devices.
Even though Btrfs has been in the kernel since 2.6.29, the developers state that "as of 2.6.31, we only plan to make forward compatible disk format changes". Please note that "forward compatible changes" means that booting a newer kernel, then booting into an older kernel is risky (further citations needed). The workaround is to mount the btrfs volume read-only while testing the newer kernel. When using a kernel from backports, this means your rescue disk will also need a kernel at least as recent as the one in backports. With every release the developers are improving the user/management tools and are making them easier to use. For more information about Btrfs, follow the links in See also section.
Ext2/3/4 filesystems should be upgradable to Btrfs, but this is not recommended because members of linux-btrfs have noted that a number of issues have been linked to conversions, and that the convert utility needs further work (Btrfs Wiki, Conversion from Ext3). Preparation for a rewrite of btrfs-convert has already begun (Btrfs progs release 4.4).
In the near future this wiki article will be updated with recommendations on how to limit your risk when testing btrfs, along with workarounds for common issues. For example, you are substantially less likely to run into issues with a simple two disk mirror mounted noatime than an n-disk RAID6 mounted with compress=lzo and autodefrag. Many people have reported years of btrfs usage without issue, and this wiki will soon contain recommended configuration parameters for achieving this end. eg: the number of snapshots per volume and per subvolume must be carefully monitored and/or automatically pruned, because too many snapshots can wedge the filesystem into an out of space condition or gravely degrade performance (Duncan, 2016-02-16, linux-btrfs). There are also reports that IO becomes sluggish and lags with far fewer snapshots, eg: only 86/subvolume on linux-4.0.4; this might be fixed in a newer kernel (Pete, 2016-03-11, linux-btrfs).
DebianSqueeze and later support Btrfs. This means that they include a compatible kernel and tools. More up-to-date btrfs code is available through Backports. (In my personal and professional opinion, btrfs before linux-4.4 and btrfs-progs-v4.4 is not worth it --NicholasDSteeves)
A Btrfs volume created on a raw partition can be used to boot using grub-pc. If booting with EFI firmware, please consult UEFI for ESP partitioning requirements. As of 2016-03-14 it is highly recommended to use a swap partition rather than a manually configured swap file through a loop-device; classic swap files are not supported (Btrfs Wiki Btrfs FAQ).
The DebianInstaller can format and install to single-disk Btrfs volumes. The way that Btrfs combines multiple disks to create a single volume is not compatible with the data model of the current installer (#686097). Various people have described ways of installing Debian onto a RAID1 Btrfs without too much trouble. It is also possible to install normally, then add another disk, then rebalance as RAID1 (Btrfs Wiki, Converting to RAID).
As of linux-4.4.5 the official upstream status of btrfs is "Btrfs is under heavy development, and is not suitable for any uses other than benchmarking and review" (git.kernel.org). In a linux-btrfs thread where a user is unable to rebalance his btrfs volume due to out of space errors, there is a discussion about changing this to "you should have backups and be prepared to use them if you're using btrfs, and...it's not suitable for production systems yet" (Duncan, 2016-03-06, linux-btrfs). Please refer to BackupAndRecovery if you do not yet have a backup strategy in place.
Subvolumes cannot currently, as of linux-4.4.5, be mounted with different btrfs-specific options; the first btrfs line for a given volume in /etc/fstab takes effect. eg: you cannot mount / with noatime and /var with nodatacow,compress=lzo (Btrfs Wiki, Mount options).
- Which package contains the tools?
- Does btrfs really protect me from hard drive corruption?
Yes, but this requires at least two disks in raid1 profile. (eg: -m raid1 -d raid1). Additionally, like for "mdadm or lvm raid, you need to make sure that the SCSI command timer (a kernel setting per block device) is longer than the drive's SCT ERC setting...If the command timer is shorter, bad sectors will not get reported as read errors for proper fixup, instead there will be a link reset and it's just inevitable there will be worse problems" (Chris Murphy, 2016-04-27, linux-btrfs). The Debian bug for this issue can be found here. For now do the following for all drives in the array, and then configure your system to change the SCSI command timer automatically on boot:
cat /sys/block/<dev>/device/timeout smartctl -l scterc /dev # echo -n the scterc value+10 to /sys/block/<dev>/device/timeout
- Does it support SSD optimizations?
Yes, Debian Jessie and later automatically detect non-rotational hard disks and ssd is added to the btrfs mount options. For more details on using SSDs with Debian, refer to SSDOptimization.
- What are the recommended options for installing on a pendrive, a SD card or a slow SSD drive?
When installing, use manual partitioning and select btrfs as file system. In the first boot, edit /etc/fstab with this options, so you can expect a very good speed and responsiveness improvement:
/dev/sdaX / btrfs x-systemd.device-timeout=0,noatime,compress=lzo,commit=0,ssd_spread,autodefrag 0 0
- But I have a super-small pendrive and keep running out of space! Now what?
Using another system, you can try something like this If Your Device is Small:
mkdir /tmp/pendrive mount /dev/sdX -o noatime,ssd_spread,compress /tmp/pendrive btrfs sub snap -r /tmp/pendrive /tmp/pendrive/tmp_snapshot btrfs send /tmp/pendrive/tmp_snapshot > /tmp/pendrive_snapshot.btrfs umount /tmp/pendrive wipefs -a /dev/sdX mkfs.btrfs --mixed /dev/sdX mount /dev/sdX -o noatime,ssd_spread,compress /tmp/pendrive btrfs receive -f /tmp/pendrive_snapshot.btrfs /tmp/pendrive sync btrfs fi sync /tmp/pendrive/
Now follow the procedure for converting a read-only snapshot to a live system and/or enabling / on a subvolume. Also, the bootloader needs to be reinstalled (Needs to be written --NicholasDSteeves).
- Does it support compression?
Yes, by adding compress=lzo or compress=zlib (depending on the level of compression or speed, lzo being faster and zlib having more compression):
/dev/sdaX / btrfs defaults,compress=lzo 0 1
- But if what you want is to just compress the files in a directory?
You can do this by applying the following two commands (for example for /var):
btrfs filesystem defragment -r -v -clzo /var chattr +c /var
By adding the +c attribute you ensure that any new file created inside the folder is compressed.
Changing /dev/sdaX with your actual root device (UUID support in btrfs is a work-in-progress, but it works for mounting volumes; use the command blkid to get the UUID of all filesystems). If fact, there are many other more options you can add, just look here. (Remember: all fstab mount options must be comma separated but NOT space separated, so do not insert a space after the comma or the equal symbol).
In order to check if you have written the options correctly before rebooting and therefore before being in trouble, run this command as root:
mount -o remount /
If no error is reported, everything is OK. Never try to boot with a troubled options fstab file or you'll have to manually try to recover it, a procedure that is more complicated.
- What are the recommended options for a rotational hard disk?
In fstab :
UUID=<the_device_uuid> /mount/point/ btrfs noauto,compress=lzo,noatime,autodefrag 0 0
The noauto option will prevent the system to freeze at boot in the case of a non system and (likely) un-plugged device/partition. Alternatively, if you are using systemd and want to limit boot delay to 10 seconds in case of a missing device, and if that device is necessary for normal functioning of the system you can try this. System boot will halt with an error if the device is not f ound:
UUID=<the_device_uuid> /mount/point btrfs x-systemd.device-timeout=10,noatime,compress=lzo,autodefrag 0 0
- Can I encrypt a btrfs installation?
Yes, you can by selecting manual partitioning and creating an encryption volume and then a btrfs file system on top of that. For the moment, btrfs does not support direct encryption so the installer uses cryptsetup, but is a planned feature, and experimental patches have recently been submitted to enable this (Anand Jain, linux-btrfs, Add btrfs encryption support)
- Does it work on RaspberryPi?
Yes, improving filesystem I/O responsiveness a lot. You may have to convert the filesystem to btrfs first from a PC and change the /etc/fstab type of filesystem from ext4 to btrfs (just by changing the name) before the first boot. Look above for recommended sdcard options in /etc/fstab.
- Fsck.btrfs doesn't do anything, how to I verify the integrity of my filesystem?
Rather than a fsck, btrfs has two methods to detect and repair corruption. The first method executes as a background process for a mounted volume. It has a default IO priority of idle, and it strives to minimize the impact on other active processes; nevertheless, like any IO-intensive background job, it is best to run it at a time when the system is not busy. To run it:
btrfs scrub start /btrfs_mountpoint
To monitor its progress:
btrfs scrub status /btrfs_mountpoint
The second method checks an umounted filesystem. It verifies that the metadata and filesystem structures of the volume are intact and uncorrupted. It should not usually be necessary to run this type of check. Please note that it runs read-only; this is by design, and there are usually better methods to recover a corrupted btrfs volume than to use the dangerous "--repair" option. Please do not use "--repair" unless someone has assured you that it is absolutely necessary. To run a standard read-only metadata and filesystem structures verification:
btrfs check -p /dev/sdX
btrfs check -p /dev/disk/by-partuuid/UUID
- How can I quickly check to see if my btrfs volume has experienced errors, with per-device accounting of any possible errors?
If you have a new enough copy of btrfs-progs you get an at-a-glance overview of all devices in your pool by running the following:
btrfs dev stats /btrfs_mountpoint
For a healthy two device RAID1 volume this command will output something like:
[/dev/sdb1].write_io_errs 0 [/dev/sdb1].read_io_errs 0 [/dev/sdb1].flush_io_errs 0 [/dev/sdb1].corruption_errs 0 [/dev/sdb1].generation_errs 0 [/dev/sdc1].write_io_errs 0 [/dev/sdc1].read_io_errs 0 [/dev/sdc1].flush_io_errs 0 [/dev/sdc1].corruption_errs 0 [/dev/sdc1].generation_errs 0
- COW on COW: Don't do it!
This includes overlayfs, unionfs, cowbuilder, databases that do their own COW, and virtual machine disk images. Please disable COW in the application if possible. For example, for QEMU, refer to qemu-img(1). If this is not possible, you can disable COW on a single directory like this
mkdir directory chattr +C directory
New files in this directory will inherit the nodatacow attribute. Alternatively, nodatacow can be applied to a single file, but only for empty files
touch file chattr +C file
As of 2016-04-17, nodatacow implies nodatasum; this means that anything with the nodatacow attribute does not receive the benefits of btrfs' checksum protection and self-healing (for RAID levels greater >= 1). Consequently, it is almost always preferable to disable COW in the application.
- Write HOWTO for sbuild + schroot + btrfs, either here or somewhere else. (where should it go? --NicholasDSteeves)
Btrfs wiki: https://btrfs.wiki.kernel.org/
Primary manpages: btrfs(5) btrfs(8) mkfs.btrfs(8) btrfs-balance(8) btrfs-device(8) btrfs-filesystem(8) btrfs-property(8) btrfs-scrub(8) btrfs-show(8) btrfs-subvolume(8) btrfstune(8), and others from btrfs-tools.
Btrfs on Wikipedia
Btrfs mailing list: firstname.lastname@example.org