On 13/07/2019 01.17, Ulli Horlacher wrote:
> I need to find (all) subvolume directories.
> I know, btrfs subvolumes root directories have inode #256, but a
> "find / -inum 256" is horrible slow!

Having all required frameworks for this in btrbk, implementing a "list
all subvolumes below <path>" command was quite easy to implement:

https://github.com/digint/btrbk/commit/e12d980502

 - get mounted filesystems from /proc/self/mountinfo
 - fetch subvolumes using "btrfs subvolume list" (fast, needs root)
 - filter and print subvolumes below mount point

Note that this approach needs root, as "btrfs subvolume list" requires
"cap_sys_admin" and "cap_dac_read_search".


Try it:

Download btrbk from "action-ls" feature branch (no dependencies needed):

# cd /tmp
# wget https://raw.githubusercontent.com/digint/btrbk/action-ls/btrbk
# chmod +x /tmp/btrbk


List subvolumes below /home:

# ./btrbk ls /home
# ./btrbk ls /home -t


Comprehensive list of all accessible subvolumes:

# ./btrbk ls / --format=long


Show commands run by btrbk:

# ./btrbk ls / -l debug


If you need to run this as a regular user (and if you are brave), you
can install setcap enabled btrfs binaries from:
https://github.com/digint/btrfs-progs-btrbk

Hope this helps,

- Axel

Reply via email to