NFS vs VirtualBox Shared Folders: Performance vs Compatibility
0 reputation · 09 Feb 2020, 02:22 UTC
0 reputation · 09 Feb 2020, 02:22 UTC
Ensure a stable synced folder for a Vagrant VM running on a Windows host, using NFS for performance while avoiding silent mount failures.
vagrant up or vagrant reload?Vagrant does **not** automatically fall back to VirtualBox Shared Folders when an NFS synced folder fails on a Windows host; it aborts with an error. To get the performance of NFS while avoiding silent mount failures, you must ensure the Windows NFS Server service is ready before Vagrant attempts the mount and verify the mount succeeded.
type: "nfs") will raise a Vagrant error if the mount command returns a non‑zero exit status; there is no built‑in fallback mechanism.# PowerShell (run as Administrator)
Enable-WindowsOptionalFeature -Online -FeatureName NFS-Server -All
Start-Service nfs-server
Set-Service nfs-server -StartupType Automatic
netsh advfirewall firewall add rule name="NFS Server" dir=in action=allow protocol=TCP localport=2049,111
netsh advfirewall firewall add rule name="NFS Server" dir=in action=allow protocol=UDP localport=2049,111
C:\vagrant-data to the VM)
# PowerShell
New-NfsShare -Name "vagrant-data" -Path "C:\vagrant-data" -Clients "/24" -Permission ReadWrite
showmount -e
# Should list the share
sudo mount -t nfs :/vagrant-data /mnt/test
# Verify mount works, then umount
sudo umount /mnt/test
config.vm.provision "shell", inline: <<-SHELL
if ! mountpoint -q /vagrant; then
echo "NFS mount not ready, exiting"
exit 1
fi
SHELL
config.vm.synced_folder ".", "/vagrant", type: "nfs"
VAGRANT_LOG=info vagrant up
Look for lines like "NFS: Mounting shared folders…" followed by either "success" or a non‑zero exit code.vagrant up, check whether the mount is present:
mount | grep vboxsf # should be empty for NFS
mount | grep nfs # should show your export
==> default: Mounting NFS shared folders...
==> default: Failed to mount folders in Linux guest. This is usually because
==> default: the "vboxsf" file system is not available. Please verify that
==> default: the guest additions are properly installed and the host can
==> default: resolve the NFS server.
Treat any non‑zero exit status as a failure; there is no silent success.Are you seeing a specific error message in the Vagrant log (e.g., "access denied", "timeout", or "port 2049 not reachable")? Knowing the exact failure reason would let us tailor firewall or export‑permission fixes rather than applying a generic pre‑check.
Use comments to ask for clarification. Post a solution as an answer.
31,775 reputation · 09 Feb 2020, 05:05 UTC
One practical gap in the steps above: even when vagrant up completes without error, it's worth verifying which filesystem actually backed the synced folder, because a misconfigured export can leave you on a stale or empty mount point rather than a loud failure. From the host:
vagrant ssh -c "findmnt -t nfs4,nfs /vagrant || mount | grep /vagrant"
If the output shows vboxsf or nothing at all, the NFS mount didn't take effect — df -h /vagrant works too, but findmnt -t nfs is unambiguous about the filesystem type. Two additional notes: (1) if you want a manual fallback rather than an abort, define two synced_folder entries keyed off an environment variable (e.g. ENV['USE_NFS']) so switching is a deliberate choice, not silent; (2) nfs_udp: false is worth setting explicitly on Windows, since UDP mounts are a common source of intermittent timeouts behind host firewalls.