ZFS Jails: Recursively mounting ZFS dataset children?

Running 11.0-RELEASE, ZFS on root.

I created a jail, into which I put a few services/scripts to backup my filesystem to another local server, as well as the cloud.

I initially planned on using nullfs to mount my important datasets into this jail (read only), and have it read/backup the data from there. It seems however that each ZFS dataset needs to be individually mounted in the jail's fstab. I haven't been able to just mount /, and have all child datasets below it also be mounted.

E.g. if I have datasets for:
/
/jails
/jails/jail1
/jails/jail2
/home
/home/user1
/home/user2
...

I have to add each of those individually into my backup jail's fstab, I can't just add "/" and have "/jails/jail1", "/jails/jail2", "/home/user1" ... also mount.

I don't mind adding them all by hand once, but this seems like a nightmare for maintenance as each time I create a new dataset I also have to add it to the backup jail's mounts or else it won't get archived.

Is there a way to recursively mount all child datasets when mounting the parent?
 
host: 15.0-RELEASE

NSLee0 - thanks for posting. Here, 10 years later, and I'm doing the same thing you did.

my zfs mounts

Code:
# zfs mount | grep opt
zroot/SAFE/dev                  /opt/dev
zroot/SAFE/stage                /opt/stage
zroot/SAFE/prod                 /opt/prod
zroot/SAFE/dev/stuff1            /opt/dev/stuff1
zroot/SAFE/stage/stuff1          /opt/stage/stuff1
zroot/SAFE/prod/stuff1           /opt/prod/stuff1
zroot/SAFE/stage/stuff2       /opt/stage/stuff2
zroot/SAFE/dev/stuff2         /opt/dev/stuff2
zroot/SAFE/prod/stuff2        /opt/prod/stuff2

my jail's fstab entry

Code:
# /jails/fstab/foo.fstab
/opt/dev/stuff1    /jails/containers/foo/opt/dev/stuff1          nullfs ro 0 0
/opt/dev/stuff2    /jails/containers/foo/opt/dev/stuff2          nullfs ro 0 0

/opt/stage/stuff1    /jails/containers/foo/opt/stage/stuff1          nullfs ro 0 0
/opt/stage/stuff2    /jails/containers/foo/opt/stage/stuff2          nullfs ro 0 0

/opt/prod/stuff1    /jails/containers/foo/opt/prod/stuff1          nullfs ro 0 0
/opt/prod/stuff2    /jails/containers/foo/opt/prod/stuff2          nullfs ro 0 0

on the host, I touch the fakedata.txt and then view it in the jail

Code:
# jexec -l foo find /opt/
/opt/
/opt/stage
/opt/stage/stuff1
/opt/stage/stuff1/fakedata.txt
/opt/stage/stuff2
/opt/prod
/opt/prod/stuff1
/opt/prod/stuff2
/opt/dev
/opt/dev/stuff1
/opt/dev/stuff2

If there's a more elegant way to mount all of this, feel free to chime in. For me, my setup is fairly static... but since I use Ansible to push changes to my fleet, changes aren't a big deal.
 
nullfs mounts are per-dataset and don't recurse (if they did, you could create an infinite loop in the filesystem tree by crossmounting nullfs mountpoints on each other); there's not a more elegant way to do this, unfortunately.
 
atax1a Thank you. Since you know about this stuff, can you look at a the bottom of this thread where I'm asking about how to mount stuff into a jail so regular (non root) users can see them?

 
Back
Top