Btrfs

Install and Use Btrfs on Ubuntu 20.04 LTS

Install and Use Btrfs on Ubuntu 20.04 LTS
Btrfs (B-Tree Filesystem) is a modern copy-on-write (CoW) filesystem for Linux. It aims to implement many advanced filesystem features while focusing on fault tolerance, repair, and easy administration. The Btrfs filesystem is designed to support the requirement of high performance and high-capacity storage servers.

If you want to learn more about the Btrfs filesystem, check my article Introduction to Btrfs Filesystem.
In this article, I am going to show you how to install and use Btrfs on Ubuntu 20.04 LTS. So, let's get started.

Installing Btrfs Filesystem

The Btrfs filesystem package is available in the official package repository of Ubuntu 20.04 LTS, so you can easily install it from there.

First, update the APT package repository cache with the following command:

$ sudo apt update


To install the Btrfs filesystem on Ubuntu 20.04 LTS, run the following command:

$ sudo apt install btrfs-progs -y


The Btrfs filesystem should be installed.

Partitioning the Disk

You don't have to partition your HDD/SSD to create a Btrfs filesystem; you can create it on your bare unpartitioned HDD/SSD. But you may want to partition your HDD/SSD before you format your HDD/SSD with the Btrfs filesystem.
You can list all the storage devices and partitions of your computer with the following command:

$ sudo lsblk -e7


I have an HDD sdb on my computer, as you can see in the screenshot below. I will be partitioning the HDD sdb and formatting the partitions with the Btrfs filesystem for the demonstration in this article.


To partition the HDD sdb, I will use the cfdisk partitioning tool.
You can open the HDD sdb with the cfdisk partitioning tool as follows:

$ sudo cfdisk /dev/sdb


Select gpt and press .


To create a new partition, select Free space, then select [ New ], and press .


Type in the size of the partition you want to create. I will create a 10 GB partition. So, I will type in 10G.

You can use the following symbols to create partitions of different sizes/units:
M - partition size in megabyte unit
G - partition size in gigabyte unit
T - partition size in terabyte unit
S -number of sectors you want to use for the partition
Once you're done, press .


A new partition (sdb1 in my case) should be created.


Let's create another partition.
To do that, select the Free space, then select [ New ], and press .


Type in the size of the partition, and press .


A new partition (sdb2 in my case) should be created.


To write the changes to the disk, select [ Write ] and press .


To confirm the changes, type in yes and press .

The partition table should be saved to the disk.

To quit cfdisk program, select [ Quit ] and press .

Formatting a Disk with Btrfs Filesystem

In this section, I am going to show you how to format a partition with the Btrfs filesystem.
I have created 2 partitions, sdb1 and sdb2, in the earlier section of this article. I will format the partition sdb1 with the Btrfs filesystem for the demonstration.

$ sudo lsblk -e7

To format the partition sdb1 with the Btrfs filesystem, run the following command:

$ sudo mkfs.btrfs -L data /dev/sdb1

NOTE: Here, the -L flag sets the label of the partition. In this case, the partition label is data.

The partition sdb1 should be formatted with the Btrfs filesystem.

Mounting a Btrfs Filesystem

To mount a Btrfs filesystem, you need to create a directory (mount point) where you can mount the Btrfs filesystem.

To create a directory/mount point /data, run the following command:

$ sudo mkdir -v /data

Once the /data mount point is created, you can mount the sdb1 Btrfs filesystem on the /data mount point with the following command:

$ sudo mount /dev/sdb1 /data

The Btrfs partition sdb1 should be mounted in the /data mount point, as you can see in the screenshot below.

$ sudo lsblk -e7

Checking Btrfs Filesystem Usage Information

Checking the usage information of your Btrfs filesystem is very important, and there are many ways to check it. Let's see some of them.

You can use the following command to see the usage summary of all the Btrfs filesystems on your computer:

$ sudo btrfs filesystem show

The usage summary of all the Btrfs filesystems on your computer should be displayed.
You should find the following usage information here:

To find disk usage information about a specific Btrfs filesystem mounted on a specific directory path (e.g., /data), run the following command:

$ sudo btrfs filesystem usage /data

As you can see, a lot of disk usage information about the Btrfs partition mounted on the /data mount point is displayed.

On the top, you should find the total disk size of the Btrfs filesystem.

You should also find the amount of disk space the Btrfs filesystem has allocated (reserved for storing data) and the amount of disk space that is used from the allocated/reserved disk space.

You should also find the amount of disk space the Btrfs filesystem did not allocate (did not reserve for storing data) yet and the estimated amount of disk space (allocated and unallocated) that is still available for storing new data.

On the bottom, you should find the following information:

On the bottom, you should also find the method (i.e., single, DUP) that is used to allocate disk space for the data, metadata, and system data:

To see the summary of the disk space allocated and used for the data, metadata, and system of a Btrfs filesystem mounted in the /data directory, run the following command:

$ sudo btrfs filesystem df /data

You can also list the disk usage information of each of the files and directories of the Btrfs filesystem mounted on the /data directory as follows:

$ sudo btrfs filesystem du /data

In the end, the disk usage summary of all the files and directories of the /data btrfs filesystem should be displayed.

To only see the disk usage summary of the files and directories of the Btrfs filesystem mounted on the /data directory, run the following command:

$ sudo btrfs filesystem du -s /data

Adding More Storage Devices to a Btrfs Filesystem

If you need more disk space on your Btrfs filesystem, you can add more storage devices or partitions to the Btrfs filesystem to expand the disk space of the filesystem.

For example, to add the partition sdb2 on the Btrfs filesystem mounted on the /data directory, run the following command:

$ sudo btrfs device add /dev/sdb2 /data

As you can see, the new partition sdb2 is added to the Btrfs filesystem mounted on the /data directory.

$ sudo btrfs device usage /data

As you can see, the size of the Btrfs filesystem mounted on the /data directory has increased.

$ df -h -x squashfs -x tmpfs -x devtmpfs

Mounting a Btrfs Filesystem at Boot Time

Once you have set up a Btrfs filesystem, you don't want to mount it manually every time you boot your computer, rather mount it in automatically. Let's see how to do that.

First, find the UUID of the Btrfs filesystem mounted on the /data directory as follows:

$ sudo btrfs filesystem show /data

In my case, the UUID of the Btrfs filesystem is c9333c36-f8bf-4825-9706-8b5f28cb4e34. It will be different for you. So, make sure to replace it with yours from now on.

Open the /etc/fstab file with the nano text editor as follows:

$ sudo nano /etc/fstab

At the end of the /etc/fstab file, type in the following line:

UUID=c9333c36-f8bf-4825-9706-8b5f28cb4e34 /data btrfs defaults 0 0

Once you're done, press + X, followed by Y, and then to save the /etc/fstab file.

For the changes to take effect, reboot your computer with the following command:

$ sudo reboot

Once your computer boots, you should see that the Btrfs filesystem is correctly mounted in the /data directory at boot time, as you can see in the screenshot below.

$ df -h -x squashfs -x tmpfs -x devtmpfs

Conclusion

In this article, I have shown you how to install and use the Btrfs filesystem on Ubuntu 20.04 LTS. This information imparted here should help you get started with the Btrfs filesystem on Ubuntu 20.04 LTS.

Ubuntu'da Oynanacak En İyi 10 Oyun
Windows platformu, günümüzde doğal olarak Windows'u desteklemek için geliştirilen oyunların büyük bir yüzdesi nedeniyle oyun oynamak için hakim platfo...
Linux için En İyi 5 Arcade Oyunu
Günümüzde bilgisayarlar oyun oynamak için kullanılan ciddi makinelerdir. Yeni yüksek puanı alamazsan, ne demek istediğimi anlayacaksın. Bu yazıda, bug...
Wesnoth 1 Savaşı.13.6 Geliştirme Yayınlandı
Wesnoth 1 Savaşı.13.Geçen ay yayınlanan 6. sürüm, 1. sürümdeki altıncı geliştirme sürümüdür.13.x serisi ve özellikle kullanıcı arayüzü için bir dizi i...