10

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?

Jan Richter
  • 1,976
  • 4
  • 29
  • 49
  • This solved my problem, very similar to yours: https://stackoverflow.com/questions/46230783/vagrant-synced-folder-without-reload I hope this is as helpful for you as it was for me! – Cleber Alcântara Oct 02 '18 at 21:19

4 Answers4

14

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
Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
  • 1
    I tried without rsync but the folder didn't work either. NFS is not an option since it needs to be crossplatform. – Jan Richter Dec 05 '16 at 13:29
  • did you remove the existing Vagrantfile from the box folder and your current Vagrantfile ? it works for me – Frederic Henri Dec 05 '16 at 13:32
  • You were right! Removing from Vagrantfile in ~/.vagrant.d/.. solved the problem! But when I init centos/7 it adds rsync by default, is there a way to prevent box from creating this line with rsync? – Jan Richter Dec 05 '16 at 14:18
  • what you mean ? when you run a new `vagrant init centos/7` ? it does not even mention about the default synced folder in the default Vagrantfile – Frederic Henri Dec 05 '16 at 15:08
  • I have the `Vagrantfile` as mentioned above in git repository which I clone and then do `vagrant up` and it automatically generates the file with line `config.vm.synced_folder ".", "/vagrant", type: "rsync"`, what could be doing this? – Jan Richter Dec 05 '16 at 17:24
  • this file comes from the box itself, its not a file you owned, its part of the box you download as Vagrantfile can be delivered as part of the box itself (https://www.vagrantup.com/docs/vagrantfile/) you just need to remove this file when you download the box. unfortunately you cannot remove a specific type and get back to default, you could change to nfs for example but not revert to default or you could just create another shared folder without rsync `config.vm.synced_folder ".", "/myvagrant"` and the `/myvagrant` folder on the VM will be shared in sync mode – Frederic Henri Dec 05 '16 at 18:31
5

You can use rsync-auto command:

vagrant rsync-auto

Actually, when I had a problem with sync, adding type: nfs helped me:

config.vm.synced_folder ".", "/home/ubuntu/qb-online", type: "nfs"

You can read more information from the documentation: https://www.vagrantup.com/docs/synced-folders/rsync.html

Ibrohim Ermatov
  • 2,169
  • 19
  • 13
0
Vagrant.configure("2") do |config|
  config.vm.synced_folder ".", "/vagrant", type: "nfs",
  rsync__exclude: ".git/"
end

just use the 2nd and 3rd line inside Vagrant.configure("2") do |config| #place here end

Shubham Prakash
  • 363
  • 1
  • 4
  • 3
-1

If Anyone is Facing this issue vbox "Syncing/Mount" just enter the Vagrant ssh where the vagrant file is without vagrant up and run the command "sudo yum upgrade" dat'll Take time once it'll get finished exit the vagrant and hit vagrant up again.Issue will resolved. .. :)

and make sure If You are using Centos use "Bento/Centos" in Your VagrantFile List item

  1. vagrant ssh
  2. sudo yum upgrade
  3. vagrant reload