How to Manage and Create Btrfs File System on Linux

Wondering how to manage and create Btrfs file system on Linux? Don’t worry, we got you covered!

File systems are methods used by operating systems to store data on a system. They are responsible for storing, retrieving, and managing the files that are present in the permanent storage of a system.

Many file systems exist for Linux distributions, with each file system focusing on one feature more than the other. An example of such a file system is Btrfs.

This guide will help you learn how to manage and create Btrfs file system on Linux. We will go over the file system’s basics, installation methods, and some additional information. That being said, let’s begin!


What is Btrfs?

The B-Tree File System, better known as Btrfs is one of the more recent file systems that are available for the Linux Kernel. Like any other file system, Btrfs is also responsible for managing different files that are present in the system’s storage.

Btrfs has some features that distinguish it from other file systems for Linux. A list of these features is given below:

  • Availability of mkfs metadata features from kernel version 3.10.
  • Can repair corrupted files and file systems with precision.
  • Displays progress via the convert option.
  • Lost plus found is a feature to link or attach lost files to a path.
  • Display file system usage.
  • Improved documentation and fewer bugs.
  • Allows creating subvolumes within the file system.

Now that we’ve already discussed the basics of the file system, let’s move on to the installation process.


Installing Btrfs File System on Linux.

Although the Btrfs file system is available in most Linux distributions by default, we’ve provided a method to install it in case it is unavailable.

The installation process for Btrfs file system is fairly simple and uses the Command Terminal. 

For this tutorial, we’ll be using Ubuntu 20.04 LTS on our system. However, the process shouldn’t differ from any other Linux distribution.

Follow these steps to install the Btrfs file system on Linux:

  1. Start by opening the Command Terminal. You can press Ctrl + Alt + T on your keyboard.
  2. Once that’s finished, proceed to type the following:
$ sudo apt update
How to Manage and Create Btrfs File System on Linux

This command will ensure that all your repositories and packages are up to date.

  1. Once the update is finished, type the following in the Command Terminal.
$ sudo apt install btrfs-tools -y
How to Manage and Create Btrfs File System on Linux

Or 

$ sudo apt install btrfs-progs -y

In case you’re using a RedHat-based Linux distribution, type the following command:

$ yum install btrfs-progs -y

This will proceed to install the Btrfs file system. 

Here’s a list of useful options that you can use with $btrfs.

How to Manage and Create Btrfs File System on Linux

If you’ve done the steps correctly, you are one step closer to learning how to manage and create Btrfs file system on Linux. The next sections of the guide will cover some useful commands for the file system.


Creating Subvolumes With Btrfs.

Subvolumes refer to a division within a file system that has its own hierarchy for files/directories. 

This section will cover how you can use the Btrfs file system to create subvolumes.

Follow these steps:

  1. First, open the Command Terminal by pressing Ctrl + Alt + T on your keyboard.
  2. Next, type the following command:
$ btrfs subvolume create /btrfs/<name of subvolume>

In our case,

$ btrfs subvolume create /btrfs/SubVol1

This command will create a subvolume titled SubVol1 in the directory /btrfs

If you followed the steps correctly, you should now have created a btrfs subvolume on your system. You can view your created subvolumes with the following steps:

  1. Begin by opening the Command Terminal.
  2. Once that’s done, proceed to type the following command:
$ btrfs subvolume list /btrfs

This will display all the subvolumes that are available in /btrfs.


Accessing Btrfs Subvolumes via Snapshots.

Btrfs subvolumes do not have any read/write privileges associated with them by default. However, the subvolumes can get read/write privileges by using the snapshot command.

Follow these steps to access subvolumes with Btrfs snapshots.

  1. Start by opening the Command Terminal by pressing Ctrl + Alt + T on your keyboard.
  2. Once that’s done, proceed to type the following:
$ btrfs subvolume snapshot /btrfs/<name of subvolume> /btrfs/<name of subvolume>-snap

In our case,

$ btrfs subvolume snapshot /btrfs/SubVol1 /btrfs/SubVol1-snap

If you followed the steps correctly, you should now have a snapshot with read/write permissions.

In case you’re wondering how to make a snapshot with read-only permissions, follow these steps:

  1. First, open the Command Terminal.
  2. Next, type the following command:
$ btrfs subvolume snapshot –r /btrfs/SubVol1 /btrfs/SubVol1-rosnap

This will create a read-only snap for the subvolume.


Utilities of the Btrfs File System.

To manage the files that are present on the file system, Btrfs provides certain commands that work as utilities.

The first command that you can use is the $df. When paired with Btrfs, it can highlight the details about storage space in a file system that would otherwise be incorrect or unavailable. The syntax of the command is as follows:

$ btrfs filesystem df /btrfs 

To display the file system’s structure, use the following command:

$ btrfs filesystem show

To sync the contents of a file system, use the following command:

$ btrfs filesystem sync /btrfs

Another useful command is $btrfs defragment. As the name suggests, this command is used to defragment the drive to boost performance. The syntax for the command is as follows:

$ btrfs filesystem defragment <options> <file> <directories>

Some other useful commands include:

$ btrfs filesystem resize Used to reallocate space to a file system
$ btrfs device <options> Commands to manage additional devices
$ btrfs device <options> Commands to manage additional devices

While Btrfs is great for file management, you may be looking to switch over to a different file system for different features. In case you’re looking for file compression, then the ZFS file system is a great choice for you. Learning how to enable ZFS compression on Linux is a great option if you’re looking for a file system that saves up on storage.

This concludes our guide on how to manage and create Btrfs file system on Linux. If you have any questions, comments, or suggestions, please let us know in the comment section down below.

If this guide helped you, please share it. 🙂

Leave a Reply

Your email address will not be published.

Previous Post

How to Install Wine on Ubuntu 22.04 LTS

Next Post

How to Kill Zombie Processes in Ubuntu

Related Posts