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
14. Now, check the status of the added device.
# btrfs device stats /mnt/tecmint_btrfs1/
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
Useful Available options in Btrfs
a. To check the disk usage of mount point.
# btrfs filesystem df /mnt/tecmint_btrfs1/
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.
c. To force a sync for the file-system identified by path {/mnt/tecmint_btrfs1/}.
# btrfs filesystem sync /mnt/tecmint_btrfs1/
d. To defragment the files and directory metadata.
# btrfs filesystem defragment -v -r /mnt/tecmint_btrfs1/
- -r = recursively defragment through directories.
- -v = verbose.
- -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
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/
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]* .
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.
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.
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…
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.
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.
aaahh… why would you ever want to put btrfs on top of lvm2 instead of just using btrfs?
you do know that btrfs is inherently a volume manager as well (just like ZFS), so there is absolutely no need for lvm here