vagrant synced folders not working real-time on virtualbox

Jan Richter picture Jan Richter · Dec 5, 2016 · Viewed 10.9k times · Source

my synced folders are not working properly, they are synced one-time at start but when I make changes on the host machine, vagrant is not syncing it real-time.

First some details on my system:

  • OS: Linux Mint 18 Sarah
  • Virtualbox version: 5.0.24-dfsg-0ubuntu1.16.04.1
  • Vagrant version: 1.9.0
  • vagrant-hostmanager (1.8.5)
  • vagrant-share (1.1.6)
  • vagrant-vbguest (0.13.0)

Before we start discussing, I am not using newest version of Virtualbox since it is not in the repository and a simple vagrant up fails.

My Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.network "private_network", ip: "192.168.88.88"
  config.vm.hostname = "my.centos.dev"
end

vagrant up gives me this.

Now when I create a file on the host machine:

falnyr@mint:~/centos-vagrant $ ls
ansible  Vagrantfile
falnyr@mint:~/centos-vagrant $ touch file.txt
falnyr@mint:~/centos-vagrant $ ls
ansible  file.txt  Vagrantfile

And ssh to guest machine:

falnyr@mint:~/centos-vagrant $ vagrant ssh
[vagrant@my ~]$ ls /vagrant/
ansible  Vagrantfile

As you can see, the file is not created. When I perform vagrant reload the sync is executed again during machine boot.

Note: I cannot use NFS sync, since I need cross-platform ready environment.

Any ideas on how to enable real-time sync?

Answer

Frederic Henri picture Frederic Henri · Dec 5, 2016

The owner of the box has enabled rsync by default on the sync type. If you look at Vagrantfile of your box (in my case its ~/.vagrant.d/boxes/centos-VAGRANTSLASH-7/0/vmware_fusion but yours might probably under the virtualbox provider) you'll see a Vagrantfile with content

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

Just remove this file from the box directory and it will work.

note if you plan to use nfs you can change the sync type in your Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.network "private_network", ip: "192.168.88.88"
  config.vm.hostname = "my.centos.dev"
  config.vm.synced_folder ".", "/vagrant", type: "nfs"
end