Mount zfs dataset in LXD

Is there an easy way to mount a ZFS dataset into a LXD container?

I’m looking for something similar to that which mounts host directories:

lxc config device add mycontainer mystorage disk source=/srv/mydata path=/srv/mydata/

But with a source dataset instead of a source path:

lxc config device add mycontainer mystorage disk source=zfs:mypool/storage path=/mnt/storage/

I’ve read about doing something like

lxc storage create mystorage zfs source=storage/mydata
lxc storage volume create mystorage myvolume
lxc storage volume attach mystorage myvolume mycontainer path=/srv/mydata

If I create a lxd storage volume for an existing zfs dataset:

lxc storage create mystorage zfs source=storage/mydata

It creates loads of unwanted child datasets (e.g. containers, custom, deleted, images, virtual-machines). I don’t want the dataset to be polluted with things I didn’t create myself.

What I’m looking for is a simple way to attach a ZFS dataset that is otherwise unmounted (i.e. it has ‘mountpoint=none’ and is not mounted on the host or any other container), directly without needing a lxd storage pool. Is this possible?

Hi,
You can create a dataset with “zfs create -o mountpoint=<exact_path> pool/dataset” and mount with the command as you mentioned before.
Regards.

What do you mean by <exact path>? If its a path on the host, e.g. /srv/mydata then that is what I am doing today:

zfs create -o mountpoint=/srv/mydata storage/mydata
lxc config device add mycontainer mystorage disk source=/srv/mydata path=/srv/mydata/

I was looking for a way to do it directly without having to mount on the host.

Hi,

The disk device is used to pass through a mounted directory into a container, so it does need to be mounted on the host. We don’t have a way currently to automatically mount and pass through.

Thank you @tomp for clarifying that. That is what I am doing and it does work fine if there’s no alternative (it would be nice if, in future, the host mount requirement could be avoided).