Craig Kochis
Craig Kochis

Reputation: 883

Vagrant synced_folder overwriting guest folder

I'm having an issue, where after starting the vagrant box, the synced_folder is erasing all the contents of the target folder on the guest machine (I'm guessing that it's overwriting it).

I have the following line in my Vagrantfile

config.vm.synced_folder "folder/", "/home/vagrant/src/folder/"

I verified that /home/vagrant/src/folder has content, then adding the synced_folder command to Vagrant file causes it to be empty after startup.

I don't know if it's because I'm missing some configuration options, a permissions issue, or what.

I'm on mac OS X 10.9.2 with VirtualBox 4.3.12

Any help with this would be greatly appreciated.

Thanks!

Upvotes: 1

Views: 1978

Answers (2)

Terry Wang
Terry Wang

Reputation: 13920

As BrianC mentioned, it is NOT overwriting, but expected behaviour.

Vagrant mounts the folder in your project folder to /home/vagrant/src/folder/ within the guest. As a result, the contents in the original folder will be hidden unless you manually unmount the vagrant share (by default vboxsf).

You can change the mount point (within guest) of the share to workaround the issue.

BTW: The default vboxsf has its limitations, there are new type of synced fodlers, e.g. rsync, NFS, smb. I personally would recommend using rsync type.

Upvotes: 1

BrianC
BrianC

Reputation: 10721

If the folder /home/vagrant/src/folder/ exists inside the guest OS (which is sounds like), any contents there won't be overwritten, but they will be hidden because Vagrant will use that same path as the mount point. If you disable the share, then do a vagrant reload and vagrant ssh, you'll probably see the old contents reappear.

The sharing is mainly helpful for getting files on the host OS to be visible in the guest OS, not so much the other way around.

One workaround might be to use the normal folder share (into /vagrant), then inside the guest OS create a symbolic link to the content you want visible back on the host OS. You could add that to your .profile to run it each time you ssh into the guest.

Upvotes: 1

Related Questions