NFS exports

There seems to be a misunderstanding. Throughout the entire instructions above, none of the server's local root file system is exported.

You’ve likely confused the NFSv4 tree root with the server’s root file system. Those are two entirely different things.

NFSv4 requires a tree root, which is defined in /etc/exports with the "V4:" line. When defined, it becomes the NFSv4 exported file system's root ( in this case V4: /home/GRUPPE becomes " / " for NFSv4 mounts.

Hense the "/" path in server:path : e.g. mount -o nfsv4 server:/ /mnt,

The NFSv4 mount path is relative to the NFSv4 tree root, whereas NFSv3 must be specified with a absolute path (see examples below).

nfsv4(4)
Code:
     The NFSv4 protocol does not use a separate mount protocol and assumes
     that the server provides a single file system tree structure, rooted at
     the point in the local file system tree specified by one or more

           V4: <rootdir> [-sec=secflavors] [host(s) or net]

     line(s) in the exports(5) file.  (See exports(5) for details.)

exports(5)
Rich (BB code):
     In the following example some directories are exported as NFSv3 and
     NFSv4:

           V4: /wingsdl/nfsv4
           /wingsdl/nfsv4/usr-ports -maproot=root -network 172.16.0.0 -mask 255.255.0.0
           /wingsdl/nfsv4/clasper   -maproot=root clasper

     Only one V4: line is needed or allowed to declare where NFSv4 is rooted.
     The other lines declare specific exported directories with their absolute
     paths given in /etc/exports.

     The exported directories' paths are used for both v3 and v4.  However,
     they are interpreted differently for v3 and v4.  A client mount command
     for usr-ports would use the server-absolute name when using nfsv3:

           mount server:/wingsdl/nfsv4/usr-ports /mnt/tmp

     A mount command using NFSv4 would use the path relative to the NFSv4
     root:

           mount server:/usr-ports /mnt/tmp
Here is what I have tried:-

NFS Server:-

/etc/rc.conf :-
Code:
nfs_server_enable="YES"
nfsv4_server_enable="YES"

/etc/exports :-
Code:
V4: /var/db/backup
/ -mapall="root"


mkdir /var/db/backup
zfs create -o mountpoint /var/db/backup zroot/backup
zfs sharenfs="network=192.168.1.0/24 -maproot=root" zroot/backup


NFS Client:-


mount -o nfsv4 192.168.1.250:/zroot/backup /mnt
mount_nfs: nmount: /mnt: Permission denied

mount -o nfsv4 192.168.1.250:/var/db/backup /mnt
mount_nfs: nmount: /mnt: Permission denied



Obviously something wrong.
 
Code:
zfs set sharenfs="-network 192.168.1.0/24 -maproot=root" zroot/backup
cat /etc/zfs/exports
vi   /etc/zfs/exports
---->  "V4: /"
mount -o nfsv4 192.168.1.250:/var/db/backup /mnt
 
/etc/exports :-
Code:
V4: /var/db/backup
/ -mapall="root"
You are defining the NFSv4 tree root as V4: /var/db/backup but the wrong export directory in the line below. It must be:
Code:
V4: /var/db/backup
/var/db/backup -mapall="root"

Mount on client: mount -o nfsv4 192.168.1.250:/ /mnt

Why " / " in " server:/" ? See https://forums.freebsd.org/threads/nfs-exports.102494/post-757542

mkdir /var/db/backup
zfs create -o mountpoint=/var/db/backup zroot/backup
In zfs-create(8) you don't need to mkdir(1) the mount point of the data set. The mount point is created automatically.

In your construct, the mkdir(1) directory is overlayed by the zfs-create(8) /var/db/backup mount point.
 
You are defining the NFSv4 tree root as V4: /var/db/backup but the wrong export directory in the line below. It must be:
Code:
V4: /var/db/backup
/var/db/backup -mapall="root"

Mount on client: mount -o nfsv4 192.168.1.250:/ /mnt

Why " / " in " server:/" ? See https://forums.freebsd.org/threads/nfs-exports.102494/post-757542


In zfs-create(8) you don't need to mkdir(1) the mount point of the data set. The mount point is created automatically.

In your construct, the mkdir(1) directory is overlayed by the zfs-create(8) /var/db/backup mount point.
I really struggling to understand all this.

I used
/etc/exports :-

Code:
V4: /var/db/backup
/ -mapall="root"

as a means of identifying a V4 and V3 export list/

the / -mapall="root" is for V3 and works just as I want. ie I can mount the root of my file server on any client and works perfectly for me. I know, I know, this is a massive security hole, but it's my homelab and I take full responsibilty for any loss.

What I can't figure out is how to incorporate V4 into my exports, and am not even sure if I need it in exports if i run zfs set sharenfs on this pool.
 
What I can't figure out is how to incorporate V4 into my exports, and am not even sure if I need it in exports if i run zfs set sharenfs on this pool.
Sorry, my mistake. I didn't consider "sharenfs" was used on the dataset when replying. If ZFS dataset property "sharenfs" is set, no mount point exports over /etc/exports for any NFS version is necessary. Set only the "V4:" line for NFSv4.

You're getting a "Permission denied" error because you're using the wrong path in "server:path" for your NFSv4 mount.


Correct settings and mount(8) commands for your case are as follows:

/etc/exports
Code:
V4:  /var/db/backup

Mounting /var/db/backup on client via NFSv3:
mount 192.168.1.250:/var/db/backup /mnt

Mounting /var/db/backup on client via NFSv4:
mount -o nfsv4 192.168.1.250:/ /mnt

As you notice, the mount point of the path in "server:path" is " / ". The " / " path represents the /var/db/backup NFSv4 tree root set in /etc/exports "V4:".

NFSv3 mount paths must be absolute paths: server:/var/db/backup
NFSv4 mount paths must be relative to the NFSv4 tree root: server:/


Another example:

Code:
zfs create -o mountpoint=/NFSshare zroot/NFSshare
zfs create zroot/NFSshare/Music

zfs sharenfs="ro,network 192.168.1.0/24" zroot/NFSshare/Music

Specify the NFSv4 tree root in /etc/exports:
Code:
V4:  /NFSshare

Mounting the "Music" dataset mount point on client via NFSv3 (the path must be absolute in "server:path"):
mount 192.168.1.250:/NFSshare/Music /media/nfsMusic

Mounting the "Music" dataset mount point on client via NFSv4 (the path must be relative to the NFSv4 tree root "/NFSshare" in "server:path"):
mount -o nfsv4 192.168.1.250:/Music /media/nfsMusic
 
Back
Top