I've been tinkering with the automatic unlock of encrypted zfs datasets on login (at the console) which works great but when the user logs out they get the following errors:

login[65695]: zfs_unmount failed for zroot/home/$homedir with: -1
login[65695]: unmount_dataset failed with: -1

2 questions:
- Where do I configure the unmounting of datasets on logout?
- Where do I look to figure out why its not unmounting? The user has the mount zfs permission (and they can mount fine)

What am I getting wrong?

#FreeBSD #OpenZFS

@oxyhyxo at first glance it seems that the unmounting is attempted after the user logged out.
@beckermatic @oxyhyxo Or before. And some processes, say login shell, are still running and fs is busy.

@anparker

this feels more accurate to me, like something is still holding file-descriptors open on the mount-point. If the unmount-script is in that home-directory, it might be the culprit (so you might try moving the script to something outside the /home mount-point like /opt/bin and run it from there. It might also be that something still has that mounted-location as its $CWD, so your script might need to do something like `cd /` at the top to move out of the directory.

You might be able to use something like lsof(1) or fstat(1) right before you unmount, dumping the open file-descriptors to some user-writable location like /tmp and see if there are any obvious culprits holding things open in $HOME

@beckermatic @oxyhyxo