Btrfs party 3: gain space (almost) free

Published by TheJoe on

Estimated reading time: 2 minutes

We have reached the last chapter of our Btrfs trilogy. After securing your data and scheduling backups, today we talk about how to optimize every single byte on the disk. If you think that space is a finite resource, Btrfs will change your mind thanks to transparent compression and to deduplication.

1. Transparent compression: more GB, less wear

Transparent compression is one of the most underrated features. In practice, Btrfs compresses data before writing it to disk and decompresses it on the fly when you read it. All this happens at such a low level that the operating system and your applications don't notice anything. If the computer is not brand new, the CPU notices it.

My favorite algorithm is STD. It offers a perfect balance between speed and compression ratio.

How to activate it (immediately)

No need to format. You can enable it by changing the mount options in the file /etc/fstab:

# Esempio di riga in fstab
UUID=tuo-uuid / btrfs defaults,compress=zstd:3 0 0

The makeup: If you want to compress existing files, run this command:
sudo btrfs filesystem defragment -r -v -czstd /

As well as saving space (often from 20% to the 50% to text file, log e database), you will reduce physical writes to your SSD, extending his life.

2. Deduplication: goodbye duplicates

Have you ever thought about how much space ten copies of the same downloaded file take up in different folders? Or three virtual machines based on the same Linux distribution? Deduplication analyzes blocks of data and, identical ones can be found, li “combines” physically on the disk but leaving them distinct for the user.

Unlike ZFS, Btrfs uses deduplication out-of-band. This means it doesn't slow down your system while you write, but you can launch it whenever you like (maybe at night).

Look here:  VNC over SSH for secure connections

Recommended tools:

  • Duperemove: Scans the file system and merges duplicate blocks.
  • Bees: A daemon that works in the background to maintain the disk “clean”.
# Esempio veloce con duperemove
sudo duperemove -dr /percorso/dati

3. Discs of different sizes? No problem

Traditional RAID is rigid: if you have a 1TB disk and a 2TB disk, in 90% In some cases you will only use 1TB per disk. Btrfs breaks this rule. Thanks to block management, Btrfs can distribute data to take advantage of almost every corner of available storage, even if the discs are not identical.

Just add the new disk and launch a balance:

sudo btrfs device add /dev/sdc /punto/di/mount
sudo btrfs balance start /punto/di/mount

Conclusions: the triad is complete

We have transformed a normal file system and now it is unrecognizable from before:

Btrfs still has some rough edges (avoid RAID 5/6 come to fish!), but for standard desktop or server use it is, in my opinion, the best choice today on Linux. I hope this series has been helpful in taming your discs!


TheJoe

I keep this blog as a hobby by 2009. I am passionate about graphic, technology, software Open Source. Among my articles will be easy to find music, and some personal thoughts, but I prefer the direct line of the blog mainly to technology. For more information contact me.

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.