Linux – How to mount multiple folders with nfs4 on centos

centoslinuxnfsnfs4

I'm trying to get nfs4 working here.

Machine 1 (server) I have a folder and in it 2 other folders I'm trying to share independently. /shared/folder1 /shared/folder2

Problem is, I can't seem to figure out how to mount the folders independently on the client.

(Machine 1 – server)
/etc/exports:

/var/shared/folder1 192.168.200.101(rw,fsid=0,sync)
/var/shared/folder2 192.168.200.101(rw,fsid=0,sync)

exportfs -ra

exportfs

/var/shared/folder1
                   192.168.200.101
/var/shared/folder2
                   192.168.200.101

(Machine 2 – client)
/etc/fstab:

192.168.200.201:/folder1/ /home/nfsmnt/folder1 nfs4 rw 0 0

mount /home/nfsmnt/folder1
mount.nfs4: 192.168.200.201:/folder1/ failed, reason given by server: No such file or directory

The folder is there. I'm positive. I think there is something simple I'm missing, but I'm totally missing it.

It seems like there should be a way in fstab to tell nfs which folder on the server I want to mount. But I can only find references to what looks like a root mount point (e.g. 192.168.1.1:/) which I assume is handled by exports on the server. But even with the folders set up in exports, there doesn't seem to be an apparent way to pich and choose which gets mounted.

Is it not possible to mount separate folders from the same server to different mount points on the client?

Any help appreciated.


edit:

The error log on the server is showing the following:

/var/shared/folder1 and /var/shared/folder2 have same filehandle for 192.168.200.101, using first

Not sure what that means or how to change it. Googling only seems ti bring up info about nfs security.

Best Answer

In order to share the subdirectories, I had to share the parent folder first with fsid=0. So on the server /etc/exports looks like this:

/var/shared 192.168.200.101(rw,fsid=0,sync)
/var/shared/folder1 192.168.200.101(rw,sync)
/var/shared/folder2 192.168.200.101(rw,sync)

then on the client /etc/fstab looks like:

192.168.200.201:/folder1 /home/nfsmnt/folder1 nfs4 rw 0 0
192.168.200.201:/folder2 /home/nfsmnt/folder2 nfs4 rw 0 0

I can then mount the folders as expected:

mount /home/nfsmnt/folder1