If you find yourself needing to run Linux-only-software for development of some kind but would prefer to work in the host OSX operating system for whatever reason instead of the VM then this guide is for you.

An updated version of this post can be found here: Use Ubuntu on Mac OS with Multipass

At the time of writing I am using OSX 10.7.5 and Ubuntu 12.04 [Update: Also works with OSX 10.7.5 and Ubuntu 13.04, OSX 10.10.5 and Ubuntu 14.04] inside of a Parallels 8.0 VM. But as long as the host and VM have IP’s assigned then you shouldn’t have any huge issues. To verify this, open up a terminal window in the host and VM and enter:

ifconfig

One of the network interfaces should have an address similar to 192.168.1.100 - If each machine has a different IP assigned then continue on. If not then you will first have to set your network up to assign those IP’s.

Ubuntu VM Setup

Install the NFS server.

apt-get install nfs-kernel-server

Then we are going to create a pseudo filesystem where we will share our users home directory from.

mkdir -p /export/your-user-name

We need to add these directories to the access control list for export to NFS. Open up /etc/exports in your favorite text editor and add the following:

/export    192.168.1.0/24(rw,fsid=0,insecure,no_subtree_check,all_squash,async,anonuid=1000,anongid=1000)

/export/your-user-name    192.168.1.0/24(rw,nohide,insecure,no_subtree_check,all_squash,async,anonuid=1000,anongid=1000)

To avoid having to set up authentication because we are only sharing locally you will need to set these directories to have 777 permissions.

sudo chmod -R 777 /export

Now lets link our home directory to the export directory.

mount --bind /home/your-user-name /export/your-user-name

To avoid from having to re-mount that directory every time we restart the VM open up /etc/fstab and add the following:

/home/your-user-name    /export/your-user-name    none    bind  0  0

And finally, you’ll need to export the shares and restart your nfs server

sudo exportfs -a
sudo service nfs-kernel-server restart

OSX Setup

On the OSX side things are very simple. First lets create the directory we are going to mount our remote home directory into.

sudo mkdir ~/linux-vm

And now we mount the NFS to the directory. Be sure to substitute the following IP for the one of your Ubuntu VM.

sudo mount -t nfs 192.168.1.100:/export /Users/your-user-name/linux-vm

If you get an error that reads ‘Operation not permitted’ then you can try the following.

sudo mount -t nfs -o resvport 192.168.1.100:/export /Users/your-user-name/linux-vm

And now when you enter that directory you should see the home directory of your user on your VM. I hope that these steps help get you up and running in no time.

Problems - Solutions

Stale File Handle - Try un-mounting and re-mounting the NFS.

sudo umount -f /Users/your-user-name/linux-vm
sudo mount -t nfs 192.168.1.100:/export /Users/your-user-name/linux-vm

Could not open a connection to your authentication agent - When trying to run ssh-add after sshing into your VM. You are probably missing the required environment variables to run ssh-add.

exec ssh-agent bash

If you are having any issues feel free to comment below or mention me on twitter @fromanegg Thanks for reading!