How do I sync Vagrant sync folder with VirtualBox and CentOS/Windows?
I can't get the /vagrant folder to synchronize. It will synchronize from Windows host to CentOS guest, but only if I manually run vagrant rsync or vagrant up, and will delete any new files in the guest. It won't sync from guest to host.
$ vagrant ssh
Last login: Wed Mar 15 21:00:00 2017 from 10.0.2.2
[vagrant@localhost ~]$ cd /vagrant
[vagrant@localhost vagrant]$ ls
Vagrantfile vagrant.log
[vagrant@localhost vagrant]$ touch tmp.txt
[vagrant@localhost vagrant]$ ls
tmp.txt Vagrantfile vagrant.log
[vagrant@localhost vagrant]$ exit
logout
Connection to 127.0.0.1 closed.
Chloe@xps /cygdrive/c/Users/Chloe/Documents/server
$ ls
vagrant.log VagrantfileI tried to manually mount and it gave an error
[vagrant@localhost vagrant]$ sudo mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant
/sbin/mount.vboxsf: mounting failed with the error: Protocol errorI tried to manually set a shared folder in VirtualBox interface and restarted
It doesn't give any errors on vagrant up and there is nothing in the debug log.
Version 5.1.16 r113841 (Qt5.6.2)
CentOS Linux release 7.3.1611 (Core)
Windows 8.1
2 Answers
I fixed it by changing the name (1st column) of /vagrant in VirtualBox to vagrant and manually running this command inside the guest:
[vagrant@localhost ~]$ sudo mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant
[vagrant@localhost vagrant]$ touch /vagrant/tmp.txt
[vagrant@localhost vagrant]$ exit
Connection to 127.0.0.1 closed.
Chloe@xps /cygdrive/c/Users/Chloe/Documents/server
$ ls
tmp.txt vagrant.log VagrantfileNot even selecting 'Auto mount' checkbox will mount it automatically. By the way, 1000 is the uid and gid of vagrant user. id -u vagrant; id -g vagrant
You can add this to your Vagrantfile:
config.vm.provision "shell", run: "always", inline: <<-SHELL mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant SHELL 1 I suggest that you update to Virtualbox to version 5.1.18 which solves that problem!
2