Ubuntu – Creating two nfs shares from same server, but when mounted, both point to same directory

mountnfsUbuntu

I've got a group of server that need two nfs shares, a few servers need access to one of the shares and all of the servers need access to another. The NFS server is ubuntu 12.04 and the others are 13.04
Here's my exports on the nfs server

    /u0/logshare/ 172.1.1.0/24(rw,fsid=0,insecure,no_subtree_check,async)
    /vmail1/ 172.1.1.64/27(rw,fsid=0,no_subtree_check,async,anonuid=2000,anongid=2000) 172.1.1.36(rw,fsid=0,no_subtree_check,async,anonuid=2000,anongid=2000)

Both of those are on separate partitions, logshare is ext4 and vmail is xfs, dunno if that could be relevant.

Here's what's in the fstab on the client server

    172.1.1.15:/vmail1           /vmail1         nfs     hard,intr,auto 0 0 
    172.1.1.15:/u0/logshare      /logshare     nfs     hard,intr,auto 0 0 

but here's what I get after rebooting

172.1.1.15:/u0/logshare  4.1G  158M  3.8G   4% /logshare
172.1.1.15:/vmail1       4.1G  158M  3.8G   4% /vmail1

it's just mounted the logshare twice. If I reverse the order of the exports then it mounts the vmail twice. What's going on? I've been trhough the logs but don't see any errors relating to nfs

Showmount -e shows this
/vmail1 172.1.1.35,172.1.1.64/27
/u0/logshare 172.1.1.0/24

and the contents of both mounts are identical

Best Answer

You should have started saying that this is an NFSv4 server.

The problem is in your /etc/exports file. You are declaring both resources with the fsid=0 flag. That's wrong.

Read the exports(5) for the details, but basically:

For NFSv4, there is a distinguished filesystem which is the root of all exported filesystem. 
This is specified with fsid=root or fsid=0 both of which mean exactly the same thing. 

I.e. you can only declare one root.

Common practice (although others might have different ones) is to create dedicated LVs (formatted as you need, ext4, xfs, ...) for the resources you plan to export, and mount them under a controlled directory structure. For example:

/var/exports/foo
/var/exports/bar
/var/exports/baz

Then, mount bind those resources under /srv/nfsv4/, resulting something in the lines of:

# tree /srv/nfsv4/
/srv/nfsv4/
├── bar
├── baz
└── foo

This way, you declare /srv/nfsv4 your fsid=0 and export the rest of the resources as you see fit.

Note that access restrictions (by IP, or sec mode chosen) in the fsid=0 apply, so clients not satisfying the requirements in the fsid=0 will fail to mount the resources, even if the requirements for an specific resource are fulfilled.

Related Topic