Can an NFS export be configured so that NFS clients see only the final directory name?

Fellow FreeBSD Fans,

I'm using 10.3-RELEASE-p6 amd64.

I'd like to NFS export a jailed directory. This jail's not using VNET, so I've configured the export on the base operating system; I'm not attempting a jailed NFS server.

The base operating system's name's joymax and the jail's name's smurf.

My /etc/exports (on joymax) looks like:

Code:
/x/jail/smurf/goodies -ro -network 192.168.32.0/24

NFS clients see this export like this:

Code:
client$ showmount -e joymax
Exports list on joymax:
/x/jail/smurf/goodies                192.168.32.0

Yet what I'd really like, would be for NFS clients to see the export like this:

Code:
client$ showmount -e joymax
Exports list on joymax:
/goodies                             192.168.32.0

I guess I could just ln -s /x/jail/smurf/goodies /goodies (though I haven't tried that), or use nullfs(5), yet I thought somebody might know of a more elegant way.

'seems like it'd be groovy if the NFS server allowed me to make an export like this, without having to break out the "bailing wire."

Thanks very much!
 
You need to specify which NFS version you are using. The answer for NFSv3 which you should use is "yes". man exports
 
You need to specify which NFS version you are using.

Ah, it looks like I'm using NFSv3.

The answer for NFSv3 which you should use is "yes". man exports

Thanks for this.

In a new search for NFSv4 stuff after reading your comment, and I found this 2011 post by phoenix.

The major difference between NFSv3 and NFSv4 is how the mounting of shares works.

With NFSv3, the client needs to know the full path to the shared directory on the server. And the exports line includes the full path to the shared folder. So, if you have /home/coolstuff listed in the exports file, the client mounts it like so:
$ mount -t nfs myserver:/home/coolstuff

With NFSv4, the client mounts are relative to the shared directory. Thus, whatever is listed in the exports file is considered / (root) when the client mounts it. So, if you have /home/coolstuff in the exports file, then the client mounts it like so:
$ mount -t nfs myserver:/

It seems like it's not possible to do what I want with NFSv3. And some of the computers accessing my export will be quite old, and probably won't support NFSv4.

Thank you Oko!
 
I guess I could just ln -s /x/jail/smurf/goodies /goodies (though I haven't tried that), or use nullfs(5), yet I thought somebody might know of a more elegant way.
This won't work because the NFS daemon will refuse to share a symlinked directory. You could do it the other way around though, set the filesystem up as /goodies, share that through NFS and symlink (or nullfs(5)) it to /x/jail/smurf/goodies.
 
Oko and SirDice, thanks again for your replies.

Here's my tentative solution, thanks to you two. I figured others might find it helpful (my future self, most likely).

  1. Placed in the host's /etc/fstab:
    Code:
    # This is mounted by /usr/local/etc/rc.d/nullfs_smurf.
    /x/jail/smurf/goodies  /goodies    nullfs  rw,noatime,noauto
  2. Placed in the host's /etc/rc.conf:
    Code:
    # See /usr/local/etc/rc.d/nullfs_smurf and /etc/fstab.
    nullfs_smurf_enable="YES"
  3. Placed in the host's /etc/exports:
    Code:
    # See /usr/local/etc/rc.d/nullfs_smurf and /etc/fstab.
    /goodies -ro -network 192.168.32.0/24
  4. A script named nullfs_smurf, placed in the host's /usr/local/etc/rc.d:
    Code:
    #!/bin/sh
    #
    # This nullfs(5) mounts a directory within the "smurf" jail on to the host, to
    # give the host's NFSv3 server a short directory path name to export.
    #
    # Though the host's NFSv3 server could directly export the jailed directory,
    # doing so would result in NFS clients having to mount an export like
    # /x/jail/smurf/goodies, instead of simply /goodies.
    #
    # In a more basic sense, this exists because A) it's not possible to jail NFS
    # service on 10.3-RELEASE, B) NFSv3 was desired for broad NFS client
    # compatibility, and C) a configuration may be desired which allows both a
    # jailed Samba instance and the host's NFS server to export a single, jailed
    # directory.
    #
    # This relies on an /etc/fstab line with the "noauto" option set.  If "noauto"
    # isn't set, the nullfs(5) mount will be attempted before the jail's ZFS
    # dataset has been mounted, which will cause the boot process to fail.  The
    # /etc/fstab line should look about like this:
    #
    #     /x/jail/smurf/goodies  /goodies    nullfs  rw,noatime,noauto
    #
    # $Id: nullfs_smurf,v 1.1 2016/08/16 18:28:53 rgregg Exp $
    #-----------------------------------------------------------------------------
    
    # PROVIDE:  nullfs_smurf
    # REQUIRE:  zfs
    # BEFORE:   nfsd
    
    . /etc/rc.subr
    
    name="nullfs_smurf"
    rcvar="nullfs_smurf_enable"
    
    start_cmd="${name}_start"
    stop_cmd="${name}_stop"
    
    nullfs_smurf_start() {
        echo -n "Starting $name"
        /sbin/mount /goodies
        echo .
    }
    
    nullfs_smurf_stop() {
        echo -n "Stopping $name"
        /sbin/umount /goodies
        echo .
    }
    
    load_rc_config $name
    run_rc_command "$1"
 
There's really no need for all this. Just add the filesystem to /etc/fstab.smurf and set up /etc/jail.conf for the jail. Something like this should do the trick:
Code:
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.clean;

mount.devfs;

smurf {
        host.hostname = "smurf.example.com";
        ip4.addr = X.X.X.X;
        ip6.addr = Y:Y:Y::Y;
        interface = em0;

        path = /jails/smurf/;
        mount.fstab = /etc/fstab.$name;
}

The filesystem will be automatically mounted and unmounted when the jail starts/stops.
 
SirDice, thanks so much for replying.

The approach you've suggested's sure simpler; I like it.

Yet I've actually chosen to keep all of the data inside of the smurf jail, and nullfs(5) mount it back to the host. So even if the /etc/fstab.smurf approach could make the nullfs(5) mount back to the host when smurf started, that'd happen too late in the boot process (since NFS starts before jails do).

I've chosen to keep the data inside of smurf to simplify replications--I'll be able to replicate a single dataset for smurf, instead of having to replicate two--one for smurf, and one for the NFS exported directory outside of smurf. On the other hand, the approach I've chosen's complex in its own way, so I'm not sure which way's simpler over all.

I sure appreciate your advice; if I've misunderstood your suggestion, I'll be curious to hear your thoughts. Thank you SirDice.
 
Back
Top