How to Create and Manage Btrfs File System in Linux

Step 2: Adding Devices to Btrfs Filesystem

12. Now we need to extend the mount point size /mnt/tecmint_btrfs1/ for this, we don’t have to extent the logical volume, instead we can add the device to mount point, it will extend the size of file-system.

# btrfs device add /dev/tecmint_vg/tecmint_lv2 /mnt/tecmint_btrfs1/

13. After adding device to btrfs filesytem, now verify the mount point size using ‘df -h‘ command.

# df -h
Add Device to Btrfs
Add Device to Btrfs

14. Now, check the status of the added device.

# btrfs device stats /mnt/tecmint_btrfs1/
Verify Device Status
Verify Device Status

If in-case, you want to remove the logical volume tecmint_lv2 from mount point, you can use the below commands.

# btrfs device delete /dev/tecmint_vg/tecmint_lv2 /mnt/tecmint_btrfs1/
# df -h
Remove LVM Device
Remove LVM Device

Useful Available options in Btrfs

a. To check the disk usage of mount point.

# btrfs filesystem df /mnt/tecmint_btrfs1/
Check Disk Usage
Check Disk Usage

b. To list the btrfs file-system with more information’s. Mounted and unmounted using –all-devices.

# btrfs filesystem show --mounted

Instead of using –mounted we can list every devices using –all-devices.

List Btrfs Filesystems
List Btrfs Filesystems

c. To force a sync for the file-system identified by path {/mnt/tecmint_btrfs1/}.

# btrfs filesystem sync /mnt/tecmint_btrfs1/
Sync Btrfs Filesystems
Sync Btrfs Filesystems

d. To defragment the files and directory metadata.

# btrfs filesystem defragment -v -r /mnt/tecmint_btrfs1/
  1. -r = recursively defragment through directories.
  2. -v = verbose.
  3. -c = to compress the file contents while defragmenting.

c. Checking file-system using btrfsck command to check the btrfs file-system.

# btrfsck /dev/tecmint_vg/tecmint_lv1
Scan Btrfs Filesystems
Scan Btrfs Filesystems

Step 3: Creating Btrfs Subvolumes

Btrfs subvolume are not a block devices, but it will behaves like block devices, not like LVM, ZFS volumes. Subvolumes are thought as a POSIX file namespace, These namespace can be accessed via the top level subvolume of the file-system by b-tree structure that contains directories.

Can create multiple subvolumes inside each subvolumes and we can mount the subvolume using it’s ID without mounting it’s parent subvolumes. We can create, delete the subvolume using simple commands.

Snapshots: This to Create a writeable/readonly snapshot of the subvolume, Snapshots to create the copy of writes but here it will not make copies of files instead it will shared the metadata and data’s of original subvolumes. We can create snapshot by read-only and writeable.

15. Before creating subvolume list if any subvolume existing.

# btrfs subvolume list /mnt/tecmint_btrfs1/

16. To create subvolume we can use the below command. Here i have created two subvolumes.

# btrfs subvolume create /mnt/tecmint_btrfs1/subvol1
# btrfs subvolume create /mnt/tecmint_btrfs1/subvol2

17. Now list and check for the newly created subvolumes.

# btrfs subvolume list /mnt/tecmint_btrfs1/
Create Btrfs Subvolume
Create Btrfs Subvolume

18. Then navigate to mount point /mnt/tecmint_btrfs1/ and list to see the newly created subvolumes what we have created in above steps.

# cd /mnt/tecmint_btrfs1/subvol1/

Copy some of the random files from /etc/ to subvol1.

# cp /etc/[abcde]* .
Verify Btrfs Subvolumes
Verify Btrfs Subvolumes
If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

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.

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

  1. I seen lvm and thought What ?

    I made the mistake of using gpt partition then putting btrfs on that and ouch lost my data later.

    Now I make sure to wipe all the partitions from the drives first. Then I create my btrfs partitions.

    This seems to work best starting with blank drives.

    Reply
  2. 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.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.