How to Create and Manage Btrfs File System in Linux

Mounting Btrfs Subvolume

19. First to know the ID of subvolumes list the subvolumes using below command.

# btrfs subvolume list /mnt/tecmint_btrfs1/

20. Then to mount the subvolumes we should umount the parent volume (our mount) /mnt/tecmint_btrfs1/.

# umount /mnt/tecmint_btrfs1/

21. Then mount the subvolume using it’s ID which we get from listing the subvolumes in above step.

# mount -o subvolid=272 /dev/tecmint_vg/tecmint_lv1 /mnt/tecmint_btrfs1/

This will mount the subvol1 using it’s ID to /mnt/tecmint_btrfs1/. Just list the mount point and check.

If we need to make our subvolume default we can use the following command.

# btrfs subvolume set-default 272 /mnt/tecmint_btrfs1/

22. To list the default subvolume we can use the following command.

# btrfs subvolume get-default /mnt/tecmint_btrfs1/
Mounting Btrfs Subvolume
Mounting Btrfs Subvolume

Here I have listed the subvolume1 which I have mounted, Before while listing the mount point we have seen subvol1 & subvol2 inside the mount point /mnt/tecmint_btrfs1/, but here now i have mounted the subvol1 in /mnt/tecmint_btrfs1/ and we can see the files which we have before.

Confirm Btrfs Subvolume
Confirm Btrfs Subvolume

Creating Snapshots

23. To create a snapshot of source we can use below command.

# btrfs subvolume snapshot /source /destination

Here I want to take a snapshot of /mnt/tecmint_btrfs1/ to same location.

# btrfs subvolume snapshot /mnt/tecmint_btrfs1/ /mnt/tecmint_btrfs1/

While listing we can get the snapshot in same location as shown in the below image.

Create Btrfs Snapshots
Create Btrfs Snapshots

24. In above steps I have not given a name for snapshot because of that we get the same name while creating a snapshot inside /mnt/tecmint_btrfs1/. Let we try to create a snapshot with snap_tec into /mnt/tecmint_btrfs1/.

# btrfs subvolume snapshot /mnt/tecmint_btrfs1/ /mnt/tecmint_btrfs1/snap_tec/
# ls -l /mnt/tecmint_btrfs1/snap_tec/tecmint_btrfs1/
Name Btrfs Snapshots
Name Btrfs Snapshots

25. In above snapshots we can read and write any contents, If we need to create a read-only snapshot we can use -r option while we create a snapshot as shown below.

# btrfs subvolume snapshot -r /mnt/tecmint_btrfs1/ /mnt/tecmint_btrfs1/snap_readonly
Create Readonly Btrfs Snapshots
Create Readonly Btrfs Snapshots

Permanent Btrfs Mounting

26. Permanent mounting will be done using fstab entry. Open fstab file using your choice of editor.

# vi /etc/fstab

Next, add the following line to it. save and quit the file.

/dev/tecmint_vg/tecmint_lv1 /mnt/tecmint_btrfs1/ btrfs defaults 0 0
Permanent Btrfs Mounting
Permanent Btrfs Mounting

27. After mounting, verify whether mount are working after exiting from fstab.

# mount -a

To know more about Btrfs use manual.

# man btrfs

That’s it for now, Here we have seen how to setup brtfs file-system in Linux.

Conclusion

Btrfs file-system are still under experimental (testing) not into production, but soon it will be in production. Hope this article help you to know about the btrfs file-system. Let us know from your side through firing some comments below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

3 thoughts on “How to Create and Manage Btrfs File System in Linux”

  1. As the 2 previous posters. No need for LVM with BTRFS and NEVER use “df“, it will give you the wrong information, use “btrfs fylesystem df” instead.

    Reply

Got something to say? Join the discussion.

This site uses Akismet to reduce spam. Learn how your comment data is processed.