Using LXD I’m trying to make an existing ZFS dataset (with data) (created with
zfs create POOL/foobar) available to an lxd container.
The ZFS dataset is meant for a single container and holds data for a single application in the container, and is meant to stay even if I decide to get rid of the container at some point.
So far I found several ways to do it, but none that makes me entirely happy:
creating a zvol, moving the data to the zvol and adding it to the container with
lxc config device add myContainer myStorage disk source=/dev/zdxy path=/mnt/smthing
The issue (at least for me) with this approach is, that I have to give the disk size of the zvol instead of just letting it take the space it needs, although the size can be changed manually.
creating an lxd zfs-storage and copying the data to it (as creating from/importing a non-empty dataset isn’t working)
This could certainly work, but the data is somewhat trapped in lxd, as removing the storage form lxd, also removes the backing zfs dataset(s).
There’s also this note: “Note that LXD will assume it has full control over the ZFS pool or dataset. It is recommended to not maintain any non-LXD owned filesystem entities in a LXD zfs pool or dataset since LXD might delete them.”
Setting the mountpoint somewhere on the host, map some UID/GID between host and container and run
lxc config device add myContainer myStorage disk source=/mnt/foo path=/mnt/bar
So far this is the most promising way of doing it, but requires me to create a group on the host system. On the plus site: The folder is easily available on the host system.
Are these all the ways to do it or did I miss something that’s more suitable? I just want to mount a zfs dataset to some path in the container, but not giving control over the zfs dataset itself to lxd.
Thanks for you help,