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

crossmnt is your friend.

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

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!


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) 

Tags:

Mount

Nfs