7

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.

Diogo Gomes
  • 109
  • 6
stormdrain
  • 1,377
  • 7
  • 28
  • 51

3 Answers3

8

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
stormdrain
  • 1,377
  • 7
  • 28
  • 51
  • You are giving rw access to your parent directory /var/shared. Is that what you want? I tried exporting it ro but then, bizarrely, the 2nd of the two subfolders becomes mounted ro despite the explicit rw flag – DrSAR Jul 05 '12 at 22:45
  • Yeah I created `/var/shared` specifically for the samba shares so rw is fine on that folder. Not sure what's going on with your sub-folder...is fstab rw? – stormdrain Jul 06 '12 at 13:38
  • @stormdrain do you even need to add both folders to the fstab? Couldn't you just do a `192.168.200.201:/ /home/nfsmnt/shared nfs4 rw 0 0` ? – Rooster Dec 05 '13 at 18:04
  • @Rooster to be honest, I'm not sure. I haven't played with it since I got it working (still works all these years later; me <3 linux). If I remember correctly, I think I did it this way because of samba and the way it uses share definitions. – stormdrain Dec 05 '13 at 18:13
  • 1
    @stormdrain ah I answered my own question. you can do it either way, but to do it on the machine I'm using I had to include nohide in the options. Ie. `/var/shared/folder2 192.168.200.101(rw,sync,nohide)` – Rooster Dec 05 '13 at 18:27
  • @Rooster nice, glad you got it working. And thanks for letting us know what worked for you. – stormdrain Dec 05 '13 at 18:30
4

The problem is that you have fsid=0 for two exported filesystems. That is the error message you're getting. fsid=0 is used to set the top of the exported filesystem tree in nfsv4. Set that only once. Typically you'd have something like this i /etc/exports on the server:

/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) 

See http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-nfs-server-config-exports.html

Cheeso
  • 572
  • 3
  • 17
1

in /etc/fstab, either of the 2 syntaxes should do

192.168.200.201:/var/shared/folder1 /home/nfsmnt/folder1 nfs4 rw,defaults 0 0 192.168.200.201:/var/shared/folder1 /home/nfsmnt/folder1 nfs rw,nfsvers=4,defaults 0 0

Jmarki
  • 226
  • 2
  • 3
  • I still get a folder not found error.`mount.nfs4: 192.168.200.201:/var/shared/folder1 failed, reason given by server: No such file or directory` Also get: `'vers=4' is not supported. Use '-t nfs4' instead.` Thanks! – stormdrain Jun 07 '10 at 17:27
  • apologies, mixed up with the Solaris command. `vers=4` should be nfsvers=4. – Jmarki Jun 08 '10 at 00:23
  • I think you should not have `fsid=0` in your `/etc/exports` lines. Both folders are forced to be the same export handler, causing the `same filehandler` error log. See `man exports` for details on `fsid` – Jmarki Jun 08 '10 at 00:29
  • Nope. I tried both changing each line of exports to fsid=1, fsid=2 respectively and fsid=0, fsid=1 respectively and I get Operation not permitted errors. – stormdrain Jun 09 '10 at 19:25