Btrfs Filesystem /etc/fstab Entry To Mount It Automatically At Linux System Startup

I‘ve RAID-1 based btrfs store backups on my person system and how do I mount a multi-volume btrfs filesystem using /etc/fstab file when my Linux server comes online?

Tutorial details
Difficulty Easy (rss)
Root privileges Yes
Requirements btrfs
Time 5m
[/donotprint]The file /etc/fstab contains descriptive information about the various file system on a Linux or Unix-like system. It is the duty of the system administrator to properly create and maintain this file. This is also useful if you don’t have an initrd or your initrd does not
scan for a btrfs device on boot. In this tutorial you will learn how to mount a btrfs device using /etc/fstab.

How to format hard disk as a btrfs device?

Warning: mkfs.btrfs command destroy the data and replace the file system with a new one on existing disk. Be careful with the device names. It cannot be stressed enough how important it is to make a backup of your system before you do this.

The syntax is:
# mkfs.btrfs /dev/sdb
To create RAID-1 of /dev/sda and /dev/sdb, enter (no need to create partitions):
# mkfs.btrfs -d raid1 -m raid1 /dev/sda /dev/sdb

Finding information about your btrfs device

You can see the btrfs filesystem with info with the following command:
# btrfs filesystem show /mount/point/
# btrfs filesystem show /dev/DEVICE
# btrfs filesystem show /dev/sda
# btrfs filesystem show

Fig.01 Linux btrfs filesystem show device information command

So, I’ve two devices /dev/sda and /dev/sdb. You can use any one of the device to mount btrfs.
If your btrfs device mounted at /data/, enter:
# btrfs filesystem df /data/
Sample outputs:
Data, RAID1: total=48.00GiB, used=47.51GiB
System, RAID1: total=8.00MiB, used=16.00KiB
Metadata, RAID1: total=3.00GiB, used=1.62GiB
GlobalReserve, single: total=512.00MiB, used=0.00B

mount command syntax

The syntax is:
# mkdir /data/
# mount /dev/sda /data
# btrfs filesystem df /data/

Syntax for /etc/fstab file

First find out UUID of your device, enter:
# blkid /dev/sda
# lsblk --fs /dev/sda
Sample outputs:

NAME FSTYPE LABEL UUID                                 MOUNTPOINT
sda  btrfs        e5b5c118-fb56-4fad-a45d-ff5fad9a649d /data

Edit /etc/fstab, enter:
# vi /etc/fstab
The syntax is as follows to mount btrfs device using UUID at /data/ mount point:

UUID=e5b5c118-fb56-4fad-a45d-ff5fad9a649d /data           btrfs   defaults      0  0

Save and close the file. There you have it, an entry is added to /etc/fstab so the new disk will be mounted automatically at system startup.

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

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

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.