export ZFS filesystem over NFS


devros

Recommended Posts

I currently have a zpool of a few SSDs with a few ZFS volumes on there.  I need to export one of the volumes over NFS.  The problem is that, unlike the SMB settings where you can add extra config, there is no such option for NFS.  Unassigned devices won't recognize ZFS volumes, so I can't use that.  If I use the zfs set sharenfs=on command, it will work then, but will not stay shared after a reboot or if any changes are made to any share setting.

 

My solution was to write a script that runs when the array is 1st started that echos the lines of config I need into /etc/exports and then restarts nfsd.  The problem is that whenever some config changes are made, it results in /etc/exports getting blown away, regenerated and a restart of nfsd.  

 

Any thoughts on how I could get the two extra lines I need added every time /etc/exports get regenerated?

 

TIA,

-dev

Link to comment
  • 3 years later...
  • 4 months later...

i created 3 scripts for this problem

one to regenerate shares from zfs

#!/bin/bash -e

zfs get sharenfs -H -o name,value,source -t filesystem | grep -v off |  grep -v "inherited from" | while IFS=$'\n' read LINE;
do
        LINE=($LINE)
        NAME=${LINE[0]}
        SHARENFS=${LINE[1]}
        echo regenerating share $NAME with $SHARENFS
        zfs set sharenfs=off $NAME
        zfs set sharenfs=$SHARENFS $NAME
done

 

second one to run on every shutdown of array to backup zfs nfs shares to $BACKUPLOCATION

#!/bin/bash -e

BACKUPLOCATION=/mnt/tank/storage/unraid/zfs-nfs/backup/

rsync --verbose --archive --human-readable --progress --partial --checksum --delete-after /etc/exports.d/ $BACKUPLOCATION

 

and last one to restore backup on every start of array

#!/bin/bash -e

BACKUPLOCATION=/mnt/tank/storage/unraid/zfs-nfs/backup/

rsync --verbose --archive --human-readable --progress --partial --checksum  $BACKUPLOCATION /etc/exports.d

exportfs -ra

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.