Vagrant Synced Folder Defaults: Transitioning Between Providers in Version 2
0 reputation · 17 Dec 2020, 06:51 UTC
0 reputation · 17 Dec 2020, 06:51 UTC
To understand how the default synced‑folder type in Vagrant 2.x changes when switching providers and what explicit configuration is required to maintain consistent behavior.
When a project moves from VirtualBox to, say, VMware or a non‑VirtualBox provider, the default synced‑folder type switches from VirtualBox shared folders to either rsync or NFS (depending on provider support). This shift can break expected file visibility and edit flow, especially on Windows hosts where NFS is unavailable.
34775 reputation · 17 Dec 2020, 15:58 UTC
Assume Vagrant 2.x and a single Vagrant.configure('2') block. To force one synced-folder implementation across providers, declare the default guest path with an explicit type: instead of relying on provider defaults:
Vagrant.configure('2') do |config|
config.vm.synced_folder '.', '/vagrant',
type: 'rsync',
rsync__auto: true,
rsync__exclude: ['.git/', 'node_modules/']
end
Use type: 'nfs' or type: 'smb' when the host and provider support them. Keep provider-specific blocks only when a provider truly needs a different type; a provider block can override the top-level entry.
Using the same guest path as the built-in default, /vagrant, is what makes this a replacement rather than an extra mount. If your version reports a duplicate mount, disable the default first with disabled: true, then declare the explicit entry.
The likely breakage when moving off VirtualBox is not that Vagrant forgot the folder; it is that the default implementation changed. VirtualBox normally uses native shared folders, while non-VirtualBox providers commonly fall back to rsync or a provider-native mechanism. That changes both performance and the direction of sync.
The portable control point is the explicit type option. Treat provider defaults as convenience, not as a contract.
| Type | Direction | Practical limitation |
|---|---|---|
virtualbox | Live two-way | VirtualBox provider and guest additions only |
rsync | Host-to-guest by default | Guest writes do not appear on the host automatically |
nfs | Two-way over an NFS mount | Not a normal Windows-host option; host NFS support and permissions required |
smb | Two-way over an SMB mount | Mainly Windows-host oriented; credentials and share permissions matter |
rsync__auto: true starts host watching on up; run vagrant rsync-auto for the watcher and vagrant rsync --all to force a host-to-guest pass.If the same Vagrantfile must work on Windows and Unix hosts, branch on the host platform and keep credentials in environment variables:
Vagrant.configure('2') do |config|
if Vagrant::Util::Platform.windows?
config.vm.synced_folder '.', '/vagrant',
type: 'smb',
smb_username: ENV['VAGRANT_SMB_USER'],
smb_password: ENV['VAGRANT_SMB_PASS']
else
config.vm.synced_folder '.', '/vagrant', type: 'nfs'
end
end
If identical behavior matters more than raw performance, prefer the rsync block above. Do not use type: 'virtualbox' on VMware, Hyper-V, or libvirt; use the provider-native type if available, otherwise use rsync, SMB, or NFS.
vagrant validate after editing the Vagrantfile.vagrant up --provider=vmware_desktop or vagrant up --provider=virtualbox.vagrant rsync --all or vagrant rsync-auto, then create a host file and confirm it appears in the guest.Which non-VirtualBox provider and host OS combination must the same Vagrantfile support? That determines whether SMB, NFS, or rsync is the safe default.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.