Bind mounts seem to be hard. I am looking for the right way to use a bind mount to mount a given directory to another one pretty much like a symlink (but I can't use a symlink because my application is linux containers). I want to be able to unmount that directory without disrupting other possible mounts.
Background: I want to share a ZFS pool from a host system to a Linux container (proxmox). As a ZFS pool, there are many nested datasets and hence I would like to recursively do the mount. Also, some of the datasets are encrypted and should be transparently available if encryption keys are loaded and not, if unmounted.
What I have tried
Starting point is the host system with the
mountpointproperty set so that all datasets are mounted to/zpseagate8tbon the host system. I can freely mount/umount datasets and load/unload encryption keys. I would like to clone this tree exactly into a containerI created another directory
/zpseagate8tb_bind, to which I bind mount the original pool. The intention is to mark it as slave to facilitate unmounting. I have the following line in my/etc/fstab:/zpseagate8tb /zpseagate8tb_bind none rbind,make-rslave,nofailThen I use LXC's builtin capabilities to bind mount that directory into the container. The config file includes:
lxc.mount.entry: /zpseagate8tb_bind zpseagate8tb none rbind,create=dir 0 0
This works flawlessly until I want to unmount and/or the pool disappears (due to mistakenly unplugging) in which case there is always something unexpected happening. For example, /zpseagate8tb_bind is empty while the data is still accessible/mounted inside the container. In nearly all cases I have to reboot everything to get a consistent state again.
What is the right approach to create this bind mount and which commands are needed to remove the mount from the container while not disturbing something else?