34

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?

mbaitoff
  • 4,911
  • 8
  • 28
  • 32

5 Answers5

45

crossmnt is your friend.

/srv        *(rw,fsid=0,no_subtree_check,crossmnt)
anatoly techtonik
  • 2,514
  • 4
  • 24
  • 37
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!

v25
  • 273
  • 3
  • 7
  • 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 Jun 08 '23 at 15:30
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) 
mbaitoff
  • 4,911
  • 8
  • 28
  • 32
3

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.

Bluby
  • 131
  • 1
  • 2
    Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – slm May 14 '14 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