Vagrant NFS Synced Folders: Fast, Practical, and Full of Gotchas
Use Vagrant’s NFS synced folder to boost file‑system performance on macOS/Linux hosts. Follow this guide for a working Vagrantfile, platform prerequisites, common pitfalls, and verification steps.
17 Aug 2025, 16:05 UTC

Why NFS Matters for Vagrant Workflows
When a project contains thousands of files—think a large Ruby on Rails app or a multi‑module Node.js monorepo—the default VirtualBox shared folder can become a bottleneck. Network File System (NFS) offers near‑native file‑system performance, reducing I/O latency and keeping file changes in sync between host and guest. The trade‑off is a slightly more complex setup and a few platform limitations. Below is a quick recipe to get NFS working, a checklist of common pitfalls, and a pragmatic way to verify the mount is healthy.
Getting Started: A Minimal Vagrantfile
Place the following in your project’s root. It tells Vagrant to share the ./src directory into the guest at /vagrant_src using NFS, with ownership mapped to the vagrant user.
# Vagrantfile – NFS synced folder example
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
# Share ./src → /vagrant_src via NFS
config.vm.synced_folder "./src", "/vagrant_src",
type: "nfs",
owner: "vagrant",
group: "vagrant",
nfs_options: "rw,sync,actimeo=1"
end
Run vagrant up (you’ll need sudo on macOS or Linux hosts because NFS requires root privileges). After the box boots, SSH in and check the mount:
vagrant ssh
$ mount | grep /vagrant_src
/var/lib/nfs/rpc_pipefs /vagrant_src type nfs (rw,vers=4.2,addr=192.168.56.101,clientaddr=192.168.56.101)
What Makes NFS Faster?
VirtualBox shared folders emulate a local filesystem inside the guest, which incurs context‑switch overhead for every file operation. NFS, by contrast, runs a lightweight kernel‑level mount that forwards syscalls to the host over the network stack. For read‑heavy workloads, the difference can be an order of magnitude.
Platform Prerequisites
- macOS hosts – Install Xcode Command Line Tools (
xcode-select --install) to providenfsdbinaries. - Linux hosts – NFS client utilities are usually preinstalled; if not, install
nfs-commonor equivalent. - Windows hosts – NFS is not supported natively. Vagrant will fall back to VirtualBox shared folders if you specify
type: "nfs". Use the default or switch to a Linux‑based host for NFS.
Common Mistakes & How to Avoid Them
- Forgetting
sudoon macOS – The mount will fail with permission errors. Runvagrant upfrom a terminal where you havesudorights. - Misspelling
type: "nfs"– Vagrant silently falls back to VirtualBox, so you’ll see the same performance problems you started with. - Incorrect
owner/groupsettings - Firewall blocking NFS traffic – Ensure
2049(NFS) is open on the host’s firewall. On macOS, the defaultpfconfiguration allows it, but corporate firewalls may block it. - Mounting sensitive directories – NFS exposes the host’s filesystem to the guest. Never mount directories that contain secrets or system files unless you trust the guest environment.
- Large numbers of tiny files – Even with NFS, 10k+ small files can strain the kernel. Consider using
actimeo=1to reduce cache staleness or a dedicated NFS server.
Without matching ownership, the guest may see files as root and refuse to write. Align them with the vagrant user (or your preferred UID/GID).
Fine‑Tuning nfs_options
The nfs_options string is passed directly to the mount command. Common tweaks:
| Option | Effect |
|---|---|
| rw | Read‑write access (default is read‑only if omitted) |
| sync | Ensure writes are flushed to disk before returning; safer but slightly slower |
| actimeo=1 | Force a 1‑second attribute cache timeout for better consistency |
| nolock | Disable NFS locking; useful if the guest needs to run services that lock files |
Verification Checklist
- Run
vagrant upand confirm no errors about NFS. - SSH into the guest and
mount | grep /vagrant_src– the type should benfs. - Create a file on the host (e.g.,
touch src/test.txt) and verify it appears instantly inside the VM (ls /vagrant_src). - Modify a file from the guest and confirm the change reflects on the host.
- Check permissions:
ls -l /vagrant_srcshould list files owned byvagrant:vagrant.
When to Stick with VirtualBox Shared Folders
If you’re on Windows, or you only need a handful of files, the default shared folder is simpler and avoids the NFS setup overhead. For large codebases or production‑grade development environments on macOS/Linux, NFS is usually the better choice.
Conclusion
Enabling NFS in Vagrant gives you near‑native file‑system performance, but it comes with platform constraints and a few configuration nuances. By following the example Vagrantfile, ensuring sudo rights on macOS, and checking the mount type inside the guest, you can quickly confirm that the shared folder is working as intended. Once in place, the speed gains for large projects are tangible and the workflow feels almost local.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.