How can I access nfs shares executing 'cd /net/host' using the nfsv4 protocol?
Environment
- Red Hat Enterprise Linux 5
- Red Hat Enterprise Linux 6
- autofs/automount
Issue
- Can I use automounter to access
/net/hostnamealso withnfs4? - Can I use automounter
host mapsusingnfs4? - Why can I not
cd /net/hostnameand have the nfs share automatically mounted usingnfs4while it works fornfs3?
Resolution
- If no
virtual rootis used then RHEL5 clients can access the exports below /net after/net -hosts -fstype=nfs4has been configured in file /etc/auto.master - If no
virtual rootis used then RHEL6 clients will usenfs4to access the exports below /net without further configuration - If a
virtual rootis used then RHEL5 as well as RHEL6 need the workaround documented below to access the exports below /net
Further informations
Activating/deactivating the 'virtual root' on RHEL nfs4 servers
-
If RHEL6 is offering the
nfs4services then using the optionsfsid=0orfsid=rootconfigures the export with thevirtual root. To disable thevirtual rootuse a fsid bigger than 0, i.e.fsid=1. -
If RHEL5 is used to offer
nfs4services then thevirtual rootis always enabled for exports.
Accessing NFS exports configured without 'virtual root'
-
RHEL6 clients: accessing shares using the /net structure will use
nfs4without any further configuration. Ifnfs4is not offerednfs3will be used. -
RHEL5 clients: accessing shares using the /net structure will use
nfs3by default. Configuring/net -hosts -fstype=nfs4in file/etc/auto.masterwill lead tonfs4beeing used for the access.
Accessing NFS exports configured with 'virtual root'
-
RHEL6 clients: accessing export paths using the /net structure will attempt
nfs4mounts, but these will fail without the workaround below. -
RHEL5 clients: accessing export paths using the /net structure will use
nfs3by default. Configuring/net -hosts -fstype=nfs4in file /etc/auto.master does not succeed. This is due to autofs attempting to mounting the path/exportedpathwhereas it has to use the virtual root/.
The following workaround creates a customized version of the auto.net script which strips off the sharename handed over to autofs to mount the share. This applies to rhel6 as well as to rhel5 clients.
- Create a copy of the script /etc/auto.net to /etc/auto.net.nfs4, configure
/net /etc/auto.net.nfs4in /etc/auto.master - Using
opts="-fstype=nfs4,hard,intr,nodev,nosuid,nosymlink"in the script/etc/auto.net.nfs4 - Append
| sed -e 's,:/.[^ ]*,:/ ,'to the last line of/etc/auto.net.nfs4to strip off the sharename - Accessing
/net/$server/exportpath/results in anfs4mount - This workaround will not work if any of these circumstances apply:
- A tree of mounts is exported from the server, this limitation exists because the sed substitution will not work for exports deeper in the tree
- The server has more than one export. There can only be one virtual root without any exported paths under it since the modified script will map all subordinate export paths to
<server>:/instead of<server>:/<trailing path>. - The server exports a mix of exports of differing versions, this would already fail due to the modification that attempts to mount all exports as nfsv4.
- The export pathes contain space characters.
Root Cause
- Accessing the path /net/hostname on a system results in automount(8) asking the server for a list of exports in the same way showmount(8) does. The NFS server replies with a list of the exported paths. The NFS client has to use the 'path' information now differently, depending on a
virtual rootbeeing used for the export or not:
- If
nfs3is used the NFS client uses thepathto mount the export - If
nfs4withoutvirtual rootis used the NFS client uses thepathto mount the export, similiar tonfs3 - If
nfs4withvirtual root(often also referred to asglobal root) is in use then the NFS client root of the export tree must be mounted, so "/" has to be used instead of thepathpresented by the server.
- The NFS client has no means to find out if a
virtual rootis used or not, so if the exported path should be mounted using the path or using '/'. This also results in environments using thevirtual rootof not beeing able to offer mounts vianfs3parallel tonfs4.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.