Btrfs is a very versatile filesystem, and it has a lot of features that don’t exist in any other mainline Linux filesystem. One of the key features of btrfs is the concept of subvolumes. A subvolume can be compared to a disk partition since each subvolume can contain it’s own filesystem tree and size limits. When created, subvolumes are shown as directories in the directory they were created.
Creating a subvolume is as easy as creating a directory:
|
|
The same can be said of deleting a subvolume:
|
|
As each subvolume can contain a different filesystem, you can even mount a subvolume as it was a partition:
|
|
But, if it has sibling subvolumes, let’s say subvol1 and subvol2 created under <mount_point>, when mounting subvol2 especially the user can’t reach subvol1 in the same <mount_point>. Let’s see an example:
|
|
As you can see, two files were created. But, if the user mounts a specific subvolume under /mnt it won’t be able to reach the other subvolume by the same mount point.
|
|
By the code above, subvol1 can’t be reached anymore, but it’s listed by subvolume list. Up until now, to remove a subvolume, the user should be able to reach it from the mount point. With the given example, the only way to delete the subvolume is to mount the filesystem in another mount point and delete subvol1:
|
|
Recent commits in Linux kernel and btrfs-progs package changed this situation. By using the --subvolid argument a user can specify subvolume to be deleted:
|
|
A new ioctl, BTRFS_IOC_SNAP_DESTROY_V2, was added in Linux kernel, and support for this ioctl was added in btrfs-progs and libbtrfsutil to make it possible. One possible user of this new feature is snapper, which has to deal with subvolume creation and deletion from time to time.
If you want to dig deeper into the details of this feature, take a look at the feature request and in the commits in Linux Kernel, btrfs-progs and a test at xfstests.
Thanks for reading!