Getting started with BTRFS
BTRFS is a file system with logical volumes capabilities and data integrity features that is getting a lot of attention in the Linux world. Learn how to get started today!
Before you begin
BTRFS strays a lot from normal file system concepts. If you haven’t got a solid grip on this topic I suggest you read this post beforehand. After that you need a reasonably up to date kernel (the more up to date, the better), keep in mind many older versions can cause problems and upgrading to a newer version might not be a simple operation. The only package needed to start is btrfs-tools for debian-based and btrfs-progs redhat-based distros.
Getting started with BTRFS
To initialize a partition you can simply do:
mkfs.btrfs /dev/sdX /dev/sdY
Where X and Y are the actual letters for your devices. No, it’s not a typo, with BTRFS you usually want to use the entire disk instead of partitioning it and creating the file system on top of the partitions. The precedent command actually created a file system that span across the selected devices (RAID0). Be careful: not all operating system can boot from BTRFS directly.
Another interesting feature you can take advantage of is the ext3/4 conversion. Be aware that as of Linux 4.0 kernel this feature has been neglected and not well-tested. Without further ado the commands to do so is:
fsck /dev/sdX # Always run check before converting btrfs-convert /dev/sdX # This is how the conversion is done
This will create a BTRFS subvolume named ext2_saved. This subvolume is crucial to restore the former state of the converted file system, don’t delete it until you’re sure everything is right.
In a BTRFS system you will most likely have multiple devices that enable you to take advantage of built-in RAID configurations. In the precedent example a single BTRFS pool has been created on top of multiple devices, but adding/removing devices is quite simple. Keep in mind that to do so you need to mount the pool beforehand!
# btrfs device add /dev/sdX /mnt # btrfs device delete /dev/sdX /mnt
To list pools (and their devices) you can issue:
# btrfs filesystem show Label: none uuid: bd807f40-773b-4ac1-9e25-a4658f7d51b7 Total devices 3 FS bytes used 112.00KiB devid 1 size 1.00GiB used 275.94MiB path /dev/loop1 devid 2 size 1.00GiB used 110.38MiB path /dev/loop2 devid 3 size 1.00GiB used 263.94MiB path /dev/loop3
One of the most interesting capabilities of BTRFS is subvolumes. Subvolumes are like folder to the operating system, however they’re different entities and are almost treated as block devices (but they are not). To create a subvolume simply do (assuming the pool is mounted on /mnt ):
# btrfs subvolume create /mnt/subvolume1 Create subvolume '/mnt/subvolume1'
To verify you actually created a subvolume:
# btrfs subvolume list /mnt ID 258 gen 6 top level 5 path subvlume1
If you ever need to delete a subvolume the opeartion is pretty simple:
# btrfs subvolume delete /mnt/subvolume1 Delete subvolume '/mnt/subvolume1'
In this tutorial you learnt the basics to operate a BTRFS system. Adding/removing devices, creating new pools and managing subvolumes. In the next tutorial you will learn how to perform advanced operations like setting up RAID levels, snapshots and managing quotas.
Image thanks to Martin Abegglen.
Latest posts by mark (see all)
- 2020 A year in review for Marksei.com - 30 December 2020
- Red Hat pulls the kill switch on CentOS - 16 December 2020
- OpenZFS 2.0 released: unified ZFS for Linux and BSD - 9 December 2020