Vagrant synced_folder overwriting guest folder - vagrant

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!

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.

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.

Related

how to get files from host machine to vagrant VM (MAC OS)

I haven't used vagrant for a while so I am racking my brains out on this one.
I know for a fact that one way to "exchange files" between the host machine and the vagrant VM is to copy any file you need into the host machine's vagrant folder that holds the Vagrantfile - the SAME folder where you run 'vagrant up' and 'vagrant ssh' to get connected to the /home/vagrant folder (indicating that you have entered the vagrant vm). However, when I get into the vagrant vm folder /home/vagrant I do not the files that I added in the host machine's vagrant folder.
I tried another approach by going in the vagrant vm's default folder /home/vagrant and run 'touch hello.txt'. Then I checked the host machine's vagrant folder using Finder and nope, I don't see hello.txt file either.
Appreciate any helpful inputs.
I finally found it...
Inside the Vagrantfile file, look for the following config setting:
config.vm.synced_folder
And mine's actually set as:
config.vm.synced_folder ".", "/vagrant"
When I gone back to check the /vagrant (NOT /home/vagrant) folder in my vagrant vm, there i found the files that I placed in my host machine's vagrant folder.
Although I wonder what the "." means - but in the meantime, I'm happy I found what I needed :)

Issues mounting a shared folder in virtualbox

I'm trying to create a shared folder between MacOS (Host) and Debian (Guest) in virtualbox. I've completed the steps of installing guest additions, creating a shared folder called "share" and a folder in debian called "sf", but when I try to run
sudo mount -t vboxsf share ~/sf
I get the error
mount: realpath /Users/USERNAME/sf: No such file or directory
I'm under the impression the second path is meant to be the directory in Debian. This also happens when I remove the ~/.
Looks like you are trying to run this command from your OSX shell. Is that possibly the case?
If yes, switch to your shell on the Debian guest. Also make sure the directory ~/sf actually does exist before you run the mount command.
Hope this helps.

HHVM with Homestead - HHVM refusing NFS

I'm trying to set up Homestead with VirtualBox and the HHVM option.
My host is Mac OS, and I'm not enabling the nfs option in Homestead.yaml.
However, as soon as I add a Hack file and run hh_client, hh_server dies because it refuses to run on NFS
I understand the rational of not supporting NFS but I'm wondering why is NFS actually involved here, and what could be done to workaround this?
VirtualBox shared folders are effectively a network folder, causing the same problems as NFS. This answer, and my comments on it, explain why hh_server (and thus Hack code) doesn't work on NFS -- the kernel doesn't provide the right inotify events to update its internal state.

Where is Vagrant saving changes to the VM?

I am just starting with Vagrant and I am having a little trouble understanding a few details. I have read through the docs but still am missing a basic concept. When I want to start a Vagrant box I run:
vagrant up
This will "build the VM based on the box" I understand that the boxes are stored at ~/.vagrant.d and in fact I have packaged up my own box from a base Ubuntu box. However, when I run vagrant up and start to add files to the vm, where is the virtual hard drive for the vm stored? For example, when I run apt-get install apache2 and the root system is modified, where is this modified?
When I do a du on my current directory I do not see any changes. I also do not see any changes in the ~/.vagrant.d directory. However, I can do vagrant halt, restart my local machine and then run vagrant up again and the changes are persisted somewhere.
vagrant up also reports
[default] VM already created. Booting if its not already running...
Can someone tell me where the VM is created and where the changes are made?
Vagrant imports the base box which is located at ~/.vagrant.d/boxes/, like you said.
This is where the base boxes are kept. It uses it to start a VM from the clean state. When importing a VM, the responsibility of where to store data files and VM state is up to VirtualBox itself. This is a configurable location but typically defaults to ~/VirtualBox\ VMS for Mac OS X and Linux. In Windows the boxes are kept in %userprofile%\.vagrant.d\boxes
It is easy to find the place where they are getting created, regardless of what platform you happen to be using.
1. Start VirtualBox.
2. Go to the VM that shows as running instance.
3. Check out the Settings ->Storage.
4. You can find the path to location where VMs are created and stored in your file system.
I always change the directory that Virtualbox uses by default for VMs. Normally it is in your profile folder in Windows.
I change it to something like "D:\VHDs\VBox\" and there I found my vagrant test vm: "test01_1347456065". It was called test01, so I guess vagrant adds the numbers to keep things unique.

Developing on Windows -> Deploying on a Virtual Machine?

Is there an easy way to integrate with VirtualBox such that I could develop under the host, Windows, and deploy and run scripts via a mounted folder in a guest linux system?
I'm looking to develop for Linux under Windows, kind of.
You can use VirtualBox's Shared Folders feature to enable your Ubuntu virtual machine to mount a directory of your Windows host. However, you're likey to be deal with some impedance mismatches like different line endings. I hope that is the least of your worries.
You might want to check out vagrant http://vagrantup.com/
It provides a nice and easy system to create a VM from a template in Virtual Box, and will automatically mount the project folder in the guest VM. The config can also easily be included in your project so others can use it.
I develop in PHP. And I use Debian as guest OS, and Win7 as host OS.
You can done automaticly mount share folder by:
new a file in /etc/init.d/ named mnt_win_sf, than you edit it:
It must has the same info head with /etc/init.d/apache2. And you need just one line of command:
mount -t vboxsf share_folder_name mount_point
We also need to excute this script before apache2, so we edit /etc/init.d/apache2. In the Require Start line, add mnt_win_sf
update them by:
sudo update-rc.d mnt_win_sf defaults
sudo update-rc.d apache2 defaults

Resources