How can I access nfs shares executing 'cd /net/host' using the nfsv4 protocol?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • autofs/automount

Issue

  • Can I use automounter to access /net/hostname also with nfs4?
  • Can I use automounter host maps using nfs4?
  • Why can I not cd /net/hostname and have the nfs share automatically mounted using nfs4 while it works for nfs3?

Resolution

  • If no virtual root is used then RHEL5 clients can access the exports below /net after /net -hosts -fstype=nfs4 has been configured in file /etc/auto.master
  • If no virtual root is used then RHEL6 clients will use nfs4 to access the exports below /net without further configuration
  • If a virtual root is 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 nfs4 services then using the options fsid=0 or fsid=root configures the export with the virtual root. To disable the virtual root use a fsid bigger than 0, i.e. fsid=1.

  • If RHEL5 is used to offer nfs4 services then the virtual root is always enabled for exports.

Accessing NFS exports configured without 'virtual root'
  • RHEL6 clients: accessing shares using the /net structure will use nfs4 without any further configuration. If nfs4 is not offered nfs3 will be used.

  • RHEL5 clients: accessing shares using the /net structure will use nfs3 by default. Configuring /net -hosts -fstype=nfs4 in file /etc/auto.master will lead to nfs4 beeing used for the access.

Accessing NFS exports configured with 'virtual root'
  • RHEL6 clients: accessing export paths using the /net structure will attempt nfs4 mounts, but these will fail without the workaround below.

  • RHEL5 clients: accessing export paths using the /net structure will use nfs3 by default. Configuring /net -hosts -fstype=nfs4 in file /etc/auto.master does not succeed. This is due to autofs attempting to mounting the path /exportedpath whereas 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.nfs4 in /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.nfs4 to strip off the sharename
  • Accessing /net/$server/exportpath/ results in a nfs4 mount
  • 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 root beeing used for the export or not:
  • If nfs3 is used the NFS client uses the path to mount the export
  • If nfs4 without virtual root is used the NFS client uses the path to mount the export, similiar to nfs3
  • If nfs4 with virtual root (often also referred to as global root) is in use then the NFS client root of the export tree must be mounted, so "/" has to be used instead of the path presented by the server.
  • The NFS client has no means to find out if a virtual root is used or not, so if the exported path should be mounted using the path or using '/'. This also results in environments using the virtual root of not beeing able to offer mounts via nfs3 parallel to nfs4.
Components
Category

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.