I will discuss very few steps involved in getting a NFS directory shared from OSX and mounting it on an Ubuntu VM.
The gist of it is OSX knows how to handle(export) NFS shares as long as you write the instructions correctly in /etc/exports file. So assume you need to export the directory in /Volumes/Disk 2/Projects
edit the /etc/exports file in your favourite editor as root (ex: sudo vim /etc/exports), paste the below command and change it to fit your requirement. Some parameters are explained below.
/Volumes/Disk\ 2/Projects -network 10.11.1.0 -mask 255.255.255.0 -mapall=purinda
/Volumes/Disk\ 2/Projects is the directory we export as a NFS share. -network 10.11.1.0 is the network subnet that will be allowed to access the share. -mask 255.255.255.0 is subnet mask, which indicates all IPs from 10.11.1.1 to 10.11.1.255 will be allowed. -mapall=purinda indicate that when reading/writing operations will be done under this user.
Run the following command in your OS X terminal, which will restart nfsd daemon and trigger above export (may not require).
sudo nfsd restart
SSH into your Ubuntu server and install autofs for mounting the above export. Remember that the IP address defined in the export above should allow the Ubuntu server IP for it to access it.
Once ssh’ed in run the following command to validate the export.
showmount -e <ip of the OSX>
Above command should show the exported directory, if not try running the same on the OSX for validating that NFS has started to share the directory.
sudo apt-get install autofs
If all of the above steps has worked for you now it is the time to setup a config file for autofs to mount the above NFS share on demand.
In order to do this, we need a autofs mount file in /etc/ folder, you can call this folder with a easy to recognisable name. In my case I called it auto.projects because I shared projects that I worked on to the Ubuntu VM.
I ran the below command (using Vim) to create the autofs config file
sudo vim /etc/auto.projects
Then paste the following line and change according to your setup and save the file.
/home/purinda/Projects -fstype=nfs,rw,nosuid,proto=tcp,resvport 10.11.1.2:/Volumes/Disk\ 2/Projects/
/home/purinda/Projects This is the directory that NFS export will be mounted on. -fstype=nfs,rw,nosuid,proto=tcp,resvport Indicates options passed in for the NFS mount command. 10.11.1.2:/Volumes/Disk\ 2/Projects/ This is the OSX host IP and the absolute path to the NFS share on the OSX.
You need to let autofs know that you have added your NFS share configuration. In order to do that edit the master autofs config.
sudo vim /etc/auto.master
Paste the following filename that we created in the end of Step 4 at the end of the /etc/auto.master file
Then restart autofs on Ubuntu VM using the command below
sudo service autofs restart
And… thats it. You should have the NFS share mounted in your Ubuntu VM under specified path.