Automatically mount nested datasets into LXC

Mrt12

Well-Known Member
May 19, 2019
134
9
58
44
Hi all,
I have the following situation. I want a LXC container to store files into different ZFS datasets.
I made one ZFS dataset:

zfs create tank/mydataset

and then mounted this dataset into the LXC container, by editing the /etc/pve/lxc/<container ID>.conf file:

mp0: /tank/mydataset,mp=/srv

Then, I created a couple child datasets:

zfs create tank/mydataset/data1
zfs create tank/mydataset/data2

Basically, the idea is that I can set different properties to data1 and data2 (such as quota, special_small_blocks etc) and then have them mounted in the LXC.
However, inside the LXC, I can see the folders corresponding to these datasets

ls /srv
data1 data2

but, of course, due to ID remapping (as it is an unprivileged container), the datasets are inacessible as they belong to nobody/nogroup. How can I fix this?
I know I can just add additional mountpoints for the data1 and data2, as follows

mp1: /tank/mydataset/data1,mp=/srv/data1
mp2: /tank/mydataset/data2,mp=/srv/data2

but this feels to me a bit redundant and is not very convenient, as I later may want to create many further datasets and not want to edit the config file manually each time. So is it somehow possible to have child datasets automatically mounted to a LXC?

and, maybe as a small feature request, would it someday even be possible to add such bind mount points from the web GUI?

Further, I tried the following. I created a privileged LXC and mounted the tank/mydataset under /srv, as previously:


mp0: /tank/mydataset,mp=/srv

and the datasets (I set a quota for test purposes)

zfs create tank/mydataset/data1 -o quota=50M
zfs create tank/mydataset/data2 -o quota=100M

now, from within the LXC, I can indeed access data1 and data2, but it seems like the quota is not honoured:

/srv/data1# df -h .
Filesystem Size Used Avail Use% Mounted on
tank 1.8G 128K 1.8G 1% /srv

obviously, the "data1" inside the LXC is not the dataset "data1" on the host. I believe I am here not accessing the dataset itself, but instead the "naked" directory where the dataset is mounted. Also, if I put files into /srv/data1, I cannot see them on the host, the dataset seems to be empty there.

I experimented a bit with zoned datasets, see here

https://gist.github.com/copecog/08996b55827329e31c6d21ccbec45081#gistcomment-5175321

but this also seems to me a bit of a workaround as the created datasets do not get their mount points automatically assigned, as it would be the case on the host.

So is it somehow possible to have nested datasets automatically bind mounted into LXC containers? and if so, how?
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!