How do I sync Vagrant sync folder with VirtualBox and CentOS/Windows?

7,240

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  Vagrantfile

Not 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
Share:
7,240

Related videos on Youtube

Chloe
Author by

Chloe

Updated on September 18, 2022

Comments

  • Chloe
    Chloe over 1 year

    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  Vagrantfile
    

    I 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 error
    

    I tried to manually set a shared folder in VirtualBox interface and restarted

    virtual box shared folder settings dialog

    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

  • Chloe
    Chloe about 7 years
    Oh wow they just released it today. Just got the notice popup. Doesn't Oracle have regression tests so they stop breaking things?
  • Chloe
    Chloe about 7 years
    That still doesn't work. I upgraded to 'Version 5.1.18 r114002 (Qt5.6.2)', removed the manual mount provision lines in my answer, started the box, touched /vagrant/tmp.txt, and the file still did not appear in my host folder.
  • Zimmi
    Zimmi over 6 years
    Successfully used your solution, thanks for sharing it ! (tried many other proposal, none worked for me). After installing 3 ubuntu and 2 debian boxes, I noticed that ubuntu boxes are ok : hashicorp/precise64, ubuntu/trusty64 and ubuntu/xenial64 didn't show the problem, but debian aren't ok : debian/(jessie64|stretch64) demonstrated the same problem and needed your fix. In case someone wants to try to reproduce, host OS is Windows 10, with VirtualBox 5.2.2, guest additions + vagrant-vbguest plugin installed. Did you find info about the cause of this problem ?