Btrfs

From LinuxReviews
Jump to navigationJump to search

BTRFS, short for B-Tree File System, is a modern Linux Copy On Write (CoW) filesystem developed by Oracle, Fujitsu and SUSE et cetera[1].

Features[edit]

Btrfs has a design and feature-set which differs from other filesystems like ext4 and jfs.

  • btrfs is somewhat self-healing thanks to its copy-on-write nature.
  • online defragmentation is supposed. It is not enabled by default; a autodefrag mount option is required (and desired).
  • mounted volumes can be grown and shrunk (ext4 can also do this, xfs volumes can not be shrunk)
  • block devices can be added and removed from volumes while they are mounted
  • RAID 0, RAID1 and RAID10 is natively supported by btrfs. Having RAID1 built-in instead of using mdadm+ext4 has some advantages.
  • btrfs volumes support subvolumes
  • Transparent file system compression using LZO, zlib and zstd is supported for both entire volumes and single files
  • volume snapshots is supported
  • Supports block discarding (for SSDs and VMs)
  • Supports doing incremental backups

the HOWTO[edit]

This wiki gives you the know-how as well as the know-why – so here is how to manage the BTR file system on a harddisk's partition: If you start headlong into the B-tree file system, it may well be advisable to go fully manual: use btrfs bash lines to snapshot and edit the grub lines at boot time. It can be done! The automatic snapshotting may confuse you, break, or make you run out of disk space fast. It may already be OK to have 1 or 2 decent snapshots and not worry about any automatism-failures – but always have a bootable disk in this fashion. Start with an empty BTRFS partition and create and delete stuff as user "root" to get the hang of it. Once there, you will never want any other fs save maybe ZFS.

Do not mismatch the mount options ssd and nossd ! Mounting with "ssd" on a spinning hard disk comes with a significant performance penalty. But you can always transmogrify even the compression mode (consider ZSTD which is cool!) with "defragment" (both file and subvol mode) , balance et cetera.

btrfs Tips and Tricks[edit]

Most people use ext4FS rather than BTRfs, but with btrfs you can snapshot a partition in about 1 second, then later boot into it (what takes time is the freeing up of space, actually), if your data is screwed up. So you can almost always rollback to an earlier working state of your harddisk without much loss of data. It is important to understand, however, that e.g. snapper does not keep a bit-perfect copy of a prior disk state, since some subdirectories are not useful to back up, hence they are ignored while snapshooting. see SuSE for details.

  • sudo timeshift-launcher to make snapshots.
  • sudo Snapper-GUI works excellent in the openSuSE-Distro, but breaks everywhere else. No one has put the effort in to keep it from breaking, like SUSE did with their own great distro. So avoid snapper, just use timeshift.

To properly clone or back up a BTRFS disk takes special softwarez, unless you wanna screw up your data or waste space.

cloning a btrfs partition[edit]

To make a trans-disk-clone of your partition, mount both drives and type in a bash Konsole:

  btrfs send   /mnt/zDRV/ATdir/snappos/517/snapshot/   |   btrfs receive  /mnt/Bpartn2/for_clone

This copies your disk at a speed of roughly 200 Gigabytes per hour, so dd may be a bit faster. Also run grub-install to be able to boot that disk, if the target disk was not yet bootable. Or manually adapt the partition’s UUID in fstab and the grub.cfg lines – et voilá, the clone boots up like a charm!

freeing up disk space[edit]

BTR people remember: in a COW fs, you get free disk space back (which you paid dearly for) only after the last reference to it was removed. Meaning that all those snapshots will act as disk space hogs! So:

Users of btrfs have to learn some bash lines to take full advantage of the file system. One important task is to get rid of old snapshots in order to free up disk space. To achieve this, you must first set the subvolume on READ-WRITE from the normal READ-ONLY mode:


 btrfs property set -ts ./MyClone/       ro false   
 btrfs property set -ts ./MyClone/@home  ro false   

Now use

cd ./MyClone/ && rm -rf * 

to delete stuff.


 btrfs subvolume delete ./MyClone   

gets rid of the whole subvolume for good, but only if you emptied it before already.

defragment the harddisk[edit]

To speed up your harddrive, you can get rid of file fragmentation in a recursive fashion like so:

 btrfs   filesystem defragment -r  ./@home      
more btrfs instructions[edit]

If you use btrfs bash lines instead of snapper or timeshift for snapshooting, do not prepend a "btrfs subvol create @SECONDARY_ROOT" line, just snapshot into @SECONDARY_ROOT right away, lest the files will go into a ……/subdir/ which is undesirable. Of interest among the bash lines furthermore is:


 btrfs check /dev/sda3       

while the drive is not mounted as root.

this is gonna take much time (like 4 hours):


 btrfs balance  start  -v   /mnt/PartnWithBTR      


 btrfs balance  status      /mnt/PartnWithBTR      
security[edit]

btrfs scrub will checksum all your files. If you also run NixOS you can re-check against the server binaries. With this double-check, it will be hard for NSA to patch your binaries without you noticing it!

web Guide links[edit]

Critique[edit]

Btrfs is not new (though this discussion was ongoing in 2009 already!) as of 2019 and it is no longer experimental, but it is relatively new compared to ext4 and xfs which have been around since forever. Btrfs is not widely deployed because it is not "mature" as in old and not as well tested. This does not mean that using it is unsafe but it does mean that the ’perceived safety’ of filesystems that have stood the test of time is considered ’higher’. Btrfs is often seen as "ZFS made by Linux" even though ZFS clearly has even better features and stability. Some say its ’like a Mazda Miata wanting to be a Ferrari GTO’. Then again, it is made by good people and not such a guy as in ReiserFS, who killed his wifey. Well, maybe she messed up his ’mental file structure’.

see also[edit]

  • btrfs [2] kernel wiki
  • Ubuntu and SE
  • de-duplicate the fs at pypi and wiki
  • mailing list
  • screenshot to the right
    Https---de.opensuse.org-images-9-98-Snapper.png
  • KaOS KaOS ISOs are not only GTK free but are Qt4 & KDE 4 free too; KaOS is as pure a Qt 5/Plasma 5 ISO as possible.

notes[edit]