Lxd 2.15 , I can snapshot insinde container use btrfs , but can not show subvolume

Hi all , I am a lxd newbie.

Today I try to create a container use btrfs as backend storage.

In the guest container , I can do snapshot use btrfs command .
ex : btrfs subvolume create /test , btrfs subvolume snapshot /test /test/snapshot

I can show how many subvolumes in host. ex:

root@ubuntu1604:/# btrfs subvolume list /var/lib/lxd/storage-pools/pool-btrfs
ID 257 gen 41 top level 5 path containers
ID 258 gen 42 top level 5 path snapshots
ID 259 gen 40 top level 5 path images
ID 260 gen 42 top level 5 path custom
ID 263 gen 13 top level 259 path images/7a7ff654cbd8f5f09bec03aa19d8d7d92649127d18659036a963b1ea63f90d25
ID 264 gen 346 top level 257 path containers/my-ubuntu2
ID 267 gen 57 top level 264 path containers/my-ubuntu2/rootfs/test
ID 268 gen 50 top level 267 path containers/my-ubuntu2/rootfs/test/snapshot
ID 269 gen 55 top level 264 path containers/my-ubuntu2/rootfs/snap

But I can not show subvolume in my guest container. I get errors

root@ubuntu1604:/# lxc exec my-ubuntu2 /bin/bash
root@my-ubuntu2:~# btrfs subvolume list /test
ERROR: can't perform the search - Operation not permitted

How to fix the error and let it work correct ?

That’s the normal behavior for unprivileged btrfs. Nothing LXD can do about this unfortunately.

You can either use a privileged container, or work around that issue in one way or another by using other btrfs commands which do work as unprivileged users.

thank q very much , I can show subvolume now ^^

root@ubuntu1604:/var/lib/lxd/devices/my-ubuntu2# lxc config set my-ubuntu2 security.privileged true
root@ubuntu1604:/var/lib/lxd/devices/my-ubuntu2#
root@ubuntu1604:/var/lib/lxd/devices/my-ubuntu2#
root@ubuntu1604:/var/lib/lxd/devices/my-ubuntu2# lxc stop my-ubuntu2
root@ubuntu1604:/var/lib/lxd/devices/my-ubuntu2# lxc start my-ubuntu2
root@ubuntu1604:/var/lib/lxd/devices/my-ubuntu2# lxc exec my-ubuntu2 /bin/bash
root@my-ubuntu2:~# btrfs subvolume list /test
ID 257 gen 41 top level 5 path containers
ID 258 gen 42 top level 5 path snapshots
ID 259 gen 40 top level 5 path images
ID 260 gen 42 top level 5 path custom
ID 263 gen 13 top level 259 path images/7a7ff654cbd8f5f09bec03aa19d8d7d92649127d18659036a963b1ea63f90d25
ID 264 gen 365 top level 257 path containers/my-ubuntu2
ID 267 gen 365 top level 264 path containers/my-ubuntu2/rootfs/test
ID 268 gen 365 top level 267 path snapshot
ID 269 gen 365 top level 264 path containers/my-ubuntu2/rootfs/snap