mounting linux NFS exports from macOS
I have a slackware machine (hostname: cyberdyne) that has a directory I want to export via NFS
so it can be mounted by my macOS machine (hostname: lightfoot).
The directory I want to export is /home/me/shared. I want to mount this directory
on my macOS machine at /Users/me/cyberdyne.
This is /etc/exports:
# Export the directory as the root directory of the virtual file tree:
/home/aaron/shared lightfoot(ro,fsid=root)
lightfoot mounts the export with this command:
sudo mount_nfs -o vers=4,resvport cyberdyne:/ ~/cyberdyne
A stroll through the export flags:
rosets read-only permissions. Note that when macOS mounts an NFS share exported by a linux server it will always have read-only privileges regardless of the flags I set in/etc/exports, but in the future I may mount this export with a linux client, in which case I will have to change this flag if I want read-write privileges for that machine. Setting theroflag now ensures that I will have to make that decision consciously.fsid=rootsets the exported directory as the root of the virtual filesystem. The purpose of this flag is better explained when examining themount_nfscommand below.
A romp through the mount_nfs command:
vers=4enforces the use of NFSv4. Thefsid=rootflag is only available on NFSv4. And, NFSv4 simplifies ipv6 addressing. Using ipv6 with NFSv3 requires specialrpcsettings that took me down an ai rabbit-hole for several days before I realized I could bypass all of that by usingvers=4, with the added benefit of enablingfsid=root.resvportis necessary when a macOS machine mounts a linux export. It has to do with arcane rules governing which ports are available. I learned that the same result can be accomplished by addinginsecureto the flags in/etc/exportsbut that creates a server-wide exception to the default linux behavior, whilst usingresvportas a mount option alters the default behavior only for clients who need it.cyberdyne:/defines thehostname:/directorybeing mounted. This is where the benefits offsid=rootreally shine. Withoutfsid=rootthehostname:/directorywould require an absolute path, e.g.cyberdyne:/home/aaron/shared; and that would require that the client-user know the parent directory structure of the export.fsid=rootallows the client-user to mount the export without knowing its locaion on the server.~/cyberdyneis the mountpoint on the client. Using the~/makes the command portable. I have another macOS machine that will mount the same shared directory at the same mountpoint location. I can use the same command without change.