Thursday, June 2, 2011

Mount an Ubuntu virtual machine via NFS on a Mac

I do a lot of local development in various Ubuntu virtual machines running in vmware fusion. I do some work in them, mess them up and then delete them when I'm done. It tends to be a pain to xfer data between the VM and my local host machine, so I found a simple way to do it with NFS exports from the VM, mounted on my Mac.

For simplicity, first setup your VM with bridged networking. Then, execute this as root on your vm:

aptitude install nfs-common nfs-kernel-server portmap
echo "/var *(rw,no_subtree_check,all_squash,anonuid=0,anongid=0)" >> /etc/exports
echo "/etc *(rw,no_subtree_check,all_squash,anonuid=0,anongid=0)" >> /etc/exports
invoke-rc.d nfs-kernel-server restart || true


Obviously edit the echo statements above to export different directories.

Open up the DiskUtility application and select File->NFS Mounts...

Enter the IP address of your VM / mountpoint (nfs://10.0.0.1/etc) and the mount location on your local Mac. Given the example above that mounts /etc and /var, you'd probably want something like /Volumes/var and /Volumes/etc

You also need to pass -P for the Advanced Mount parameters.

That's it! Now you have root write access on your VM from your Mac.

No comments: