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
Babin Lonston
I'm Working as a System Administrator for last 10 year's with 4 years experience with Linux Distributions, fall in love with text based operating systems.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

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

  1. It is very very sad this is the number one search result for creating a btrfs volume. While there might be a reason to use LVM with BTRFS, it is a very niche condition. 99% of users should not be using LVM if they are using btrfs, it is just adding complexity and another point of failure.

    Reply
  2. As LVM supports caching, you can set up your btrfs logical volumes with an SSD cache. This also open’s up all the LVM tools to you. So, for some, there might be perfectly legitimate reasons to use LVM.

    Reply
  3. Please revise this guide and remove the LVM parts. It’s so unnecessary!

    You wouldn’t put ZFS on LVM, now would you?

    BTFS is easy:

    Install btrfs-progs and make sure kernel module is loaded…

    mkfs.btrfs [-L <label of disk if wanted] /dev/
    mount /dev/ 
    tail -n1 /etc/mtab >> /etc/fstab
    
    Reply
  4. 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
  5. 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.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.