2

I have primarily used Ubuntu boxes in Vagrant and in those any files created within the box have been successfully synced to Windows also. Usually things like git pull.

However, I now have centos/7 and cannot get any files to sync to Windows. If you create a file in /vagrant it never appears anywhere in Windows - not under C:\cygwin64\ nor C:\vm\machine. When I vagrant reload the box, all the files created inside the box are gone, except configuration files eg. /etc/httpd/conf/httpd.conf. Any changes in them are still present upon vagrant reload and also vagrant halt; vagrant up.

enter image description here

Here's the Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.network "forwarded_port", guest: 80, host: 8086, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 3306, host: 3386, host_ip: "127.0.0.1"
  config.vm.synced_folder "./", "/vagrant"
  # I have also tried the following:
  # config.vm.synced_folder "C:/vm/machine", "/vagrant"
  # config.vm.synced_folder "./", "/vagrant", type: "rsync", disabled: false
end

When doing vagrant up, both methods for synced_folder display this:
==> default: Rsyncing folder: /cygdrive/c/vm/machine/ => /vagrant

I have tried doing vagrant up from both cmd.exe and also from the Cygwin64 Terminal (under /c/vm/machine). Neither of them create files to the Windows directory, which is in C:\vm\machine.

What do I need to do to make files created in the box also sync to Windows?

When I try the same in an Ubuntu box, the file appears in Windows and does not disappear: enter image description here

This is the Vagrantfile of the Ubuntu box:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "v0rtex/xenial64"

  config.vm.network "forwarded_port", guest: 80, host: 8083, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 443, host: 8443, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 3306, host: 3303, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 5000, host: 5003, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 8000, host: 8003, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 9090, host: 9093, host_ip: "127.0.0.1"
  config.vm.network "forwarded_port", guest: 9091, host: 9193, host_ip: "127.0.0.1"

end

Upon vagrant up for the Ubuntu box, I see this:
==> default: Mounting shared folders...
default: /vagrant => C:/vm/ubu1604-64

Juha Untinen
  • 1,806
  • 1
  • 24
  • 40
  • Wow, what are the odds that a similar question with a similar answer appeared just a few days apart :) Yes, the question added by @Frédèric Henri is the same as this, including the answer. – Juha Untinen Sep 20 '17 at 09:44
  • yep there's been a few questions recently about this box, seems there's a trend to use this box – Frederic Henri Sep 20 '17 at 09:48

1 Answers1

3

The solution is as follows:

  1. Change the Vagrantfile synced_folder part to this:
    config.vm.synced_folder "./", "/vagrant", type: "virtualbox", disabled: false
  2. And then run this command in the directory where the Vagrantfile is:
    vagrant plugin install vagrant-vbguest
  3. Then do either vagrant reload if it was already running, or vagrant up otherwise.
  4. It will run for quite a while - for me it took about 7 minutes altogether. However, it is a one-time install, so all future vagrant up's will take a normal amount of time.

After that, the files created in the /vagrant directory will also appear in Windows C:\vm\machine (for example) and will persist between Vagrant sessions, ie. vagrant halt + vagrant up

Juha Untinen
  • 1,806
  • 1
  • 24
  • 40