Tuesday 25 September 2012

Automatically share on boot ZFS filesystems via NFS in Fedora Linux using systemd

My media server project had a minor stumble when I found that after rebooting my server the ZFS shares were not showing on NFS clients, even though nfs-server.service was active.

I realised that the zfs shares were not being exported to NFS - I had assumed that ZFS on linux did this automatically on boot.

I wrote a simple systemd unit file to get this working on startup. This is what the file looks like:

/etc/systemd/system/zfs-share.service

[Unit]
Description=Start ZFS share-nfs sharing

[Service]
Type=oneshot
ExecStartPre=/bin/sleep 30
ExecStart=/usr/sbin/zfs share -a
ExecStop=/usr/sbin/zfs unshare -a
RemainAfterExit=yes

[Install]
WantedBy=default.target
After=nfs-server.service, zfs.service
Requires=nfs-server.service, zfs.service
 

This oneshot service simply runs the command
zfs share -a
after the NFS server and its dependencies have started.

systemctl stop zfs-share.service
should unshare the ZFS exports. In a another post I'll jot down how I got native ZFS working under Fedora 17, but it really was a case of following the simple instructions at http://zfsonlinux.org/

Edited 29/9/2012: Added 30-second sleep as ExecStartPre line to give time for ZFS to mount filesystems properly as I was getting errors due to a race condition.

No comments:

Post a Comment