Ubuntu – How to mount a zfs filesystem on another zfs filesystem in ubuntu 16.04

Ubuntuzfs

With ubuntu 14.04 I had two zfs mount points set to legacy so I could mount one filesystem on another via fstab. I.e:

zfs_1/base /home/xyz

zfs_2/photo /home/xyz/stuff/photo

With ubuntu 16.04 zfs is not loaded before fstab is processed so I tried to remove the legacy mount points and set the mount points on the file systems.

The problem is I don't see how to set a mount order. If zfs_2/photo is mounted first it will auto-create the tree and then zfs_1/base will fail to mount since the directory is not empty. Is there a simple fix for this issue with 16.04 ?

I had a related issue that I would bind photo to an exported nfs volume /export/photo; but I think I can solve that problem via using a symlink /export/photo -> /home/xyz/stuff/photo and then still export /export/photo via nfs (need to test it).

The easiest solution would be to revert to legacy and use /etc/fstab but from what I have read in ubuntu forum this does not seem to be an option.

Best Answer

You can force ZFS to be loaded early by including it into a file in /etc/modules-load.d/*.conf. Say, we create /etc/modules-load.d/zfs.conf with the following content:

zfs

The code itself also comes with a systemd service (actually a couple of them) and you can add system dependencies with the latest mount implementations. For example:

/zfs_1/base  /home/xyz               none  defaults,bind,x-systemd.requires=zfs-mount.service  0  0

/zfs_2/photo  /home/xyz/stuff/photo  none  defaults,bind,x-systemd.requires=zfs-mount.service  0  0

(Disclaimer: I am aware that x-systemd.requires works on the latest Arch and Debian Testing, may not be there yet in Ubuntu 16.04, although it is in the mount man page)

Related Question