Search code examples
windowsvagrant

How to sync folder with Vagrant in Windows?


Using Vagrant 1.9.2 on Windows 10.

Installed rsync by chololatey:

C:\> choco install rsync

The Vagrantfile:

Vagrant.configure("2") do |config|
  ...
  config.vm.synced_folder "data", "/vagrant"
  ...
end

Here want to sync data folder under the current path to /vagrant path in Vagrant. When login to Vagrant and make a test file under /vagrant path, check from Windows data folder, there exists nothing. So the file didn't synced. Why? How to sync?


Edit

Started vagrant today, got new issue:

There was an error when attempting to rsync a synced folder.
Please inspect the error message below for more info.

Host path: /c/Users/me/data/
Guest path: /vagrant
Command: "rsync" "--verbose" "--archive" "--delete" "-z" "--copy-links" "--chmod=ugo=rwX" "--no-perms" "--no-owner" "--no-group" "--rsync-path" "sudo rsync" "-e" "ssh -p 2222 -o LogLevel=FATAL   -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i 'C:/Users/me/.vagrant/machines/default/virtualbox/private_key'" "--exclude" ".vagrant/" "/c/Users/me/data/" "vagrant@127.0.0.1:/vagrant"
Error: rsync: change_dir "/c/Users/me/data" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) [sender=3.1.2]

Solution

  • I used nfs type to resolve the problem:

    config.vm.synced_folder "data", "/vagrant", type: "nfs"