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

Posted on in Categories , , last updated September 13, 2015

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?

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
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
OR
# 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.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Leave a Comment