36

Server A exports directory /srv via NFS with option nohide. A subdirectory within /srv, /srv/foo, is a mount point for another location on the NFS server using --bind option, like

server# mount --bind /bar/foo/ /srv/foo/

Client B imports A:/srv and mounts it on /mnt/srv using NFS. Contents of /mnt/srv are the contents of A:/srv.

The problem is that /mnt/srv/foo is empty, while I'm expecting to see the contents of A:/bar/foo/ there.

How to properly export and import NFS shares that have subdirectories as mount points also?

2
  • Maybe easier to just use symlink on A from /srv/foo --> /bar/foo ?
    – ckhan
    Commented Jul 6, 2012 at 6:55
  • 2
    I tried this. This would try to get to the /bar/foo on client machine B, not on server A.
    – mbaitoff
    Commented Jul 6, 2012 at 10:59

5 Answers 5

49

crossmnt is your friend.

/srv        *(rw,fsid=0,no_subtree_check,crossmnt)
12

I had stumbled into this problem while following the Diskless Arch guide, and it really slowed me down. I am going to share my findings here, as I am curious if this will work for anyone else.

As per the Diskless guide I have the diskless client's root filesystem (the actual data I need to export) in a loopback image, which has been mounted on /srv/des1:

/srv/des1.img on /srv/des1 type btrfs (rw,relatime,compress=lzo,discard,space_cache)

I then created a mountpoint /nfs/des1 then run the mount, and confirm that I can see everything:

# mkdir -p /nfs/des1 
# mount --bind /srv/des1 /nfs/des1
# ls -l /nfs/des1
bin  boot  dev  usr  #[SNIP]

Referring to the Arch NFS guide, I then put the following in /etc/exports on the server:

/nfs/      *(rw,no_root_squash,no_subtree_check,fsid=root)
/nfs/des1/ *{rw,no_root_squash,no_subtree_check,nohide)

I then ran an exportfs -rav on the server to apply these changes.

However I then mounted the share on the test client with: mount server:/des1 /mnt/tmp only to find it's an empty directory, when I expected the diskless-root-filesystem to be there.

At this stage I tried just about everything until something lead me to this option in the exports man page:

crossmnt
    This option is similar to nohide but it makes it possible for clients
    to move from the filesystem marked with crossmnt to exported filesystems
    mounted on it. Thus when a child filesystem "B" is mounted on a parent "A",
    setting crossmnt on "A" has the same effect as setting "nohide" on B. 

So having tried everything else I swapped this around so my /etc/exports looked like this:

/nfs/      *(rw,no_root_squash,no_subtree_check,fsid=root,crossmnt)
/nfs/des1/ *{rw,no_root_squash,no_subtree_check)

Having read the man page entry you would think this would have the same effect as the previous code, but when I ran exportfs -rav again to register the changes, then tried to remount from the client and it worked!

2
  • the crossmnt on my root folder (where a potential mount bind would be) fixed my "empty" folder bit. So I appreciate this answer very much. wish this answer got more to the top or the final fix was more upfront. (not sure if needed)
    – CodeAsm
    Commented Jun 8, 2023 at 15:30
  • From the man page exports(1): "The nohide option is currently only effective on sigle host exports. It does not work reliably with netgroup, subnet, or wildcard exports."
    – Wildcard
    Commented Mar 8 at 20:03
12

Looks like every mount sub-point must be exported by the NFS server in order to be visible for clients. In the situation above the /etc/exports file should look like the following:

/srv        *(rw,fsid=0,nohide,no_subtree_check)
/srv/foo    *(rw,nohide,no_subtree_check)

Then, importing /srv on the client with option -t nfs will make both /srv and /srv/foo properly available.

edit by OP

this line

    /srv/foo    *(rw,fsid=0,nohide,no_subtree_check)

has worked in my case instead of

    /srv/foo    *(rw,nohide,no_subtree_check) 
1
  • 3
    crossmnt on the root? Commented Feb 18, 2017 at 7:45
4

I really wanted to do this too, but it seems there are problems with this idea because the NFS clients expect inode numbers of files to be unique within the client's view of a single mount.

The problems are detailed in this blog post (not by me): http://utcc.utoronto.ca/~cks/space/blog/unix/MultiFilesystemNFSIssue

I've decided to mount the filesystems separately and symlink them together, which should work for all NFS clients.

1
  • 3
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – slm
    Commented May 14, 2014 at 22:07
1

NOTE: only single user enabled

What it adds is a set of edits to server side and client side. On the server side, /etc/exports and /etc/fstab on client side.

Server side

  • Linux Mint 18.3 Sylvia 32-bit
  • Kernel Linux 4.4.0-138-generic i686
  • Asus eeepc

    $ cat /etc/exports 
    #insert shares (one for each mounted partition sub-folder):      
    /nfsshare/ /192.168.1.155(rw,no_root_squash,no_subtree_check,fsid=root,crossmnt)
    /nfsshare/media/ 192.168.1.155(rw,no_root_squash,no_subtree_check)
    /nfsshare/extra/ /192.168.1.155(rw,no_root_squash,no_subtree_check)   
    
    $ cat /etc/fstab  
    #shared media files on /media/ed/
    /media/ed/ /nfsshare/ nfs bind 0 0
    /media/ed/media/ /nfsshare/media/ nfs bind 0 0
    /media/ed//extra /nfsshare/extra/ nfs bind 0 0
    

Client side

  • Linux Mint 19 Tara 64-bit
  • Kernel Linux 4.15.0-38-generic x86_64

    $ cat /etc/fstab
    #NFS Shares line added
    192.168.1.158:/nfsshare /mnt/share nfs rw,soft,intr,noatime,x-gvfs-show
    
3
  • 1
    What is this? Is this one file? Many files? Please use the formatting tools to format your answer for clarity.Could you please edit and explain how your answer answers the question?
    – terdon
    Commented Nov 1, 2018 at 18:04
  • 1
    (1) Use your words.  (2) What does this offer that hasn’t already been presented? Commented Nov 1, 2018 at 18:29
  • apologies for that . Commented Nov 1, 2018 at 18:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .