BTRFS Quick Start Guide

A while back I wrote a post about the Most Resilient File Systems For Backups. Since then BTRFS has quickly become my favorite file system. I was a little cautious moving to it but at this point most of my backups are running on BTRFS and I have not had any issues. So I wanted to throw together a quick start guide for BTRFS to show you how to use some of its advance features.

Hard Drives

Contents:

Install the BTRFS command

The first think you might have to do is install the BTRF command to get access to the more advance stuff.

For Debian based distros you do this:

sudo apt install btrfs-progs

For Arch based distros you do this:

sudo pacman -S btrfs-progs

Format a disk to BTRFS.

I tend to use gparted but if you want to do it with the command line you could do this.
sudo mkfs.btrfs /dev/sdz

sudo mkfs.btrfs /dev/sdz

Replace “sdz” with whatever your disk is.

Make Subvolume

Subvolumes look and act a lot like a directory but they are separate spaces in the file system. Its kind of like a file system inside the file system. The main advantage I know of with them is using snapshots. So if you only want to snapshot one folder then make that folder into a subvolume then snapshot away.

At the minimum I make 1 subvolume called “.snapshots” to hold my snapshots and another subvolume called “data” or whatever to put stuff into. Then I make snapshots of the data subvolume and put that into the “.snapshots” subvolume.

With that basic setup I can use and manage snapshots easy for all my data.

sudo btrfs subvolume create /path/to/subvolume/

Show Subvolumes

I keep my setup simple so I don’t need this but if you needed to know what is a directory and what is a subvolume you could use this command.

sudo btrfs subv list /path/to/btrfs/filesystem/

Make a Snapshot

This is one of the big benefits of BTRFS. When I was researching this people made it way over complicated with 3rd party tools but all you need is a simple command.

Using the “.snapshot” subvolume I talked about above you can do this.

sudo btrfs subv snapshot /path/to/subvolume/ /path/to/.snapshots/NAME

This makes a snapshot of the subvolume you pointed it to and puts it into the “.snapshots” subvolume with the name you give it. I like to name mine after the date so I can easily tell when I made the snapshot.

Once a snapshot its made you can browse into it like any other part of the file system.

Note: Snapshots do not take up space at first.

You might be worried about disk space. But the way BTRFS snapshots work is when they are first made they take up no space at all. This works because the snapshot marks the data as being in a snapshot. So when the data is changed the new changes are stored in a new place in the file system and the snapshot data is not changed. So the snapshot size grows based on the amount of changes that are made to the original data.

If 50% of the data has changed then the snapshot would be 50% the size of the original data. If 100% of the original data has changed then the snapshot would be 100% of the size of the original data. Basically its only keeping track of changes. Pretty cool!

Remove Snapshot

When you want to remove old snapshots you can use this command.

sudo btrfs subvolume delete path/to/snapshot

Error Detection and Scrub

One cool thing about BTRFS is it will tell you if it detects data corruption and it will try to fix it for you. This is more successful in a raid setup were there is another copy of the same data somewhere else in the raid it can use.

To check the stats you can use this command.

sudo btrfs device stats /path/to/mountpoint
BTRFS device stats

There is also something called a scrub were you can tell BTRFS to actively look for issues. Depending on the disk size this could take hours. But here are the commands. I tend to do this around once a month on my NAS.

sudo btrfs scrub start /path/to/mountpoint
sudo btrfs scrub status /path/to/mountpoint
sudo btrfs scrub cancel /path/to/mountpoint
BTRFS Scrub

That’s the basics

There are a lot more things like setting up a raid and file compression I might add to this later or make another post about it. But you don’t need that to get started with BTRFS.

Experiment and have fun and if you think there is something good I missed let us all know in the comments below!

Affiliate links

Thanks for reading the post! Before you go I'm testing something new. You may see AI generated affiliate links below this text based on the post contents. If you see something intresting then thats awesome. If its way off topic then just ignore them haha. Thanks!

Leave a Reply

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