Manage btrfs volumes

Hi,
I’m trying to understand a bit more how btrfs is working. I would like to use external commands btrfs, for example btrfs subvolume show <path>, but I don’t understand what path I’m supposed to provide to the command.
A more concrete thing is I would like to see quotas defined on btrfs volumes.

/var/snap/lxd/common/lxd/storage-pools/poolbt/ is entirely empty.

LXD 3.5 (snap installed). Ubuntu 18.04.
Storage pool created with lxc storage create poolbt btrfs source=/dev/vdc.

The snap has its own mount namespace, making your btrfs mounts invisible from the host.
You can get into the namespace with nsenter -t $(pgrep daemon.start) -m at which point btrfs subvolume show /var/snap/lxd/common/lxd/storage-pools/poolbr/ should work.

Hum. the nsenter -t $(pgrep daemon.start) -m command works. I’m in the namespace. /var/snap/lxd/common/lxd/storage-pools/poolbt/ is accessible.
But as I’m in the namespace, btrfs binary is not available.
-bash: btrfs: command not found
I’ve tried to copy the binary in my home folder, that seems accessible from the ns, but when I launch it, I have a lib error. Probably not the good way…
./btrfs: error while loading shared libraries: libzstd.so.1: cannot open shared object file: No such file or directory
Reading nsenter man’s page didn’t help me a lot. I have to admit that I’m also highly ignorant about namespaces…

Oh right, that part is always a bit annoying :slight_smile:

What you can do is something like:

cat /proc/$(pgrep daemon.start)/environ | tr '\0' '\n' | sed "s/^/export //g" 

This will print you a shell-compatible version of the environment of the running process.

You can copy/paste all of it into your shell or just the most relevant parts (in your case, you’ll want at least PATH and LD_LIBRARY_PATH).

1 Like

Thanks for your reply. It works !! :slight_smile: I’m able to use the btrfs command !

I’m trying to do the same with lvm, but I’m facing an other shared librarie error.

# lvs
lvs: error while loading shared libraries: libdevmapper-event.so.1.02.1: cannot open shared object file: No such file or directory

I do have copy/paste all the environment variables, and $LD_LIBRARY_PATH contain /snap/lxd/8942/lib/x86_64-linux-gnu that seems to have the right lib:

# echo $LD_LIBRARY_PATH
/var/lib/snapd/lib/gl:/var/lib/snapd/lib/gl32:/var/lib/snapd/void:/snap/lxd/8942/lib:/snap/lxd/8942/lib/x86_64-linux-gnu::/snap/lxd/8942/lib:/snap/lxd/8942/lib/x86_64-linux-gnu

# ls -alht /snap/lxd/8942/lib/x86_64-linux-gnu/libdevmapper-event.so.1.02.1
-rw-r--r-- 1 root root 27K Apr 16  2016 /snap/lxd/8942/lib/x86_64-linux-gnu/libdevmapper-event.so.1.02.1

Any idea of what I’m missing ?