ZFS mounting script

1 minute read

This post is targeted at Ubuntu 20.04, systemd services may be different / non-existant in your distribution.

Security considerations

For security reasons, and given that I am becoming more and more paranoiac, I did not want that ZFS shares are mounted at boot.

I wanted to manually enter the passphrase.

Disabling the mount

The first step is to diable the systemd unit responsible for mounting the shares at boot:

1sudo systemctl disable zfs-mount

If zpool or datasets do not show after reboot, it’s possible you need to start the following:

1sudo systemctl start zfs.target

Mounting script

To facilitate the keys (passphrase) loading and mounting, I have created a script that presents it easily for me:

 1#!/usr/bin/env bash
 2for dataset in `zfs list | grep data/ | awk '{ print $1; }'`; do
 3        echo "=================================================="
 4	echo "Loading key for dataset: $dataset"
 5	sudo zfs load-key "$dataset"
 6	echo "Mounting dataset: $dataset"
 7	sudo zfs mount "$dataset"
 8	echo "=================================================="
 9done
10
11echo "Starting the NFS server"
12sudo systemctl restart nfs-server
13echo "=================================================="

This script is also restarting the NFS server given that the NFS server shares data on those ZFS datasets.