Web development with vagrant can be a joy, but sharing files between a Virtual Box VM and the host machine has it’s quirks. Some Googling would tell you that simply using NFS will solve all your speed issues, but on my Ubuntu host/Ubuntu guest setup I’m still seeing extremely slow file accesses. What’s going on here?
Firstly, let’s start with a simple Vagrant file, exporting an NFS share from the host and mounting in the guest:
vagrant ssh and write ~800MB of zeroes to the shared folder:
This doesn’t seem too speedy. Let’s invert the NFS configuration here. Instead of exporting from the host and mounting in the guest, we’ll export from the guest and mount in the host. First install the vagrant-nfs_guest plugin that serves just this purpose:
vagrant plugin install vagrant-nfs_guest
and then modify the NFS config to change the
vagrant reload, and run the same test again:
Much better. This shows roughly a 25-fold improvement.
For sake of comparison, here’s the results of the same test running directly on the host machine:
And here when using a plain old VirtualBox shared folder, with the following config in the
And just because I love a good chart, here’s a visual representation of these numbers:
A major wrinkle here is that since we are storing our files within the VM now, they will not be available on the host while the VM is powered off. This may be a deal-breaker, but for a quick-and-dirty fix for your vagrant NFS woes, this is something to consider.