vagrant - constantly syncing folder setup - windows

I am trying build a centos7 vm at my windows10 using virtualbox. I am using cento/7 box.
it by default using rsync for syncing folder and I don't really like it as I would have to open an extra cmd just to run vagrant rsync-auto for constant syncing.
I tried to use nfs but not successful.
Here is my vagrantfile.
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
config.vm.synced_folder ".", "/home/vagrant/sync", type: "nfs"
end
and when I tried to run it. It gave me this.
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:
mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` home_vagrant_sync /home/vagrant/sync
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` home_vagrant_sync /home/vagrant/sync
The error output from the last command was:
mount: unknown filesystem type 'vboxsf'
I noticed that changes made by host will be synced to guest but not the other way round. I want to make the folder like a shared folder both guest and host can apply changes to it. Any best approaches to do it?
Thanks.

The reply you got is telling you to install Virtual Box guest additions. This is a separate installation action you have to perform on top of installing Virtual Box. Did you install Virtual Box Guest Additions?

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 :)

Laravel vagrant unable to mount

Obviously after some updates, my whole dev environment broke. When running vagrant up I get the following error:
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attemped was:
set -e
mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant
The error output from the command was:
: No such file or directory
I have tried with several options on StackOverflow, as well as googling, but no help. I've installed the vagrant-vbguest plugin, I've updated, destroyed and provisioned the box, I did a vagrant reload --provision.
I've also tried logging in to guest with SSH, and running sudo ln -s /opt/VBoxGuestAdditions-4.3.10/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions
Does anyone have a solution?
EDIT:
I've tried downgrading Virtualbox to 5.1. and then I get the following:
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["modifyvm", "dc09e643-896d-4491-8a6a-659c13d2cf65", "--natpf1", "tcp8000,tcp,,8000,,80", "--natpf1", "tcp44300,tcp,,44300,,443", "--natpf1", "tcp33060,tcp,,33060,,3306", "--natpf1", "tcp54320,tcp,,54320,,5432", "--natpf1", "ssh,tcp,127.0.0.1,2222,,22"]
Stderr: VBoxManage.exe: error: A NAT rule of this name already exists
VBoxManage.exe: error: Details: code E_INVALIDARG (0x80070057), component NATEngineWrap, interface INATEngine, callee IUnknown
VBoxManage.exe: error: Context: "AddRedirect(Bstr(strName).raw(), proto, Bstr(strHostIp).raw(), RTStrToUInt16(strHostPort), Bstr(strGuestIp).raw(), RTStrToUInt16(strGuestPort))" at line 1820 of file VBoxManageModifyVM.cpp
i had the exact same problem as you and my virtual box version was 5.1.16 all i had to do was downgrade to 5.1.14 and problem fixed.
Hope it works for you

Vagrantfile ordering provisioner issue

I have the following vagrant file:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
vb.cpus = 4
#storage
end
config.vm.provision "shell",
path: "vagrant_files/setup_script.sh"
config.vm.provision :reload
config.vm.provision "shell",
path: "vagrant_files/setup_script_2.sh"
config.vm.provision :reload
config.vm.provision "shell",
path: "vagrant_files/setup_script_3.sh"
config.vm.synced_folder ".", "/vagrant"
end
In my setup setup_script I have vagrant install Virtual Box Guest Additions which is a requirement to get the synced folder feature to work for vagrant.
Unfortunately, even if I put the line to sync the folders at the very end of the Vagrantfile, it still attempts to do that task first resulting in an error:
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:
mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant
The error output from the last command was:
mount: unknown filesystem type 'vboxsf'
I understand I need to first install the Virtual Box Guest Additions. Anyone else run into this issue? how did you all solve this problem?
This is an interesting issue. I spun up a CentOS 7 VM with the same base box like so...
vagrant init centos/7
vagrant up
...and the Guest Additions installation failed. Here's the relevant output from Vagrant...
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
mount: /dev/loop0 is write-protected, mounting read-only
Installing Virtualbox Guest Additions 5.0.10 - guest version is
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.10 Guest Additions for Linux............
VirtualBox Guest Additions installer
Copying additional installer modules ...
./install.sh: line 345: bzip2: command not found
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
./install.sh: line 358: bzip2: command not found
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
So this base box does not have the bzip2 package installed and that causes the failure. Out of curiosity I created a new Ubuntu VM from the ubuntu/trusty64 base box and Guest Additions installed without any problem. As you might guess, the bzip2 package was already installed in Ubuntu.
I would classify this as an issue with the base box itself. The CentOS project should be baking bzip2 into all of their Vagrant base boxes that are used with VirtualBox.
Of course, this doesn't help you right now, but fortunately you have many more options for CentOS base boxes and I would expect that most of them are not affected by this issue.
To fix my issue, I just loaded the Centos box.
Then I proceeded to install Virtual Box Guest Additions
Then I proceeded to repackage the box
That solved my issue.
I used luvejo tip on https://github.com/mitchellh/vagrant/issues/6769 and it worked for me as well:
You can also install the vagrant-vbguest plugin so it adds the
VirtualBox Guest Additions for you.
vagrant plugin install vagrant-vbguest
vagrant destroy && vagrant up
And that works for me.

vagrant ash: sudo: not found

When starting my vagrant box with a small 15MB Busybox image, the first time I get an error during the phase
Mounting shared folders...
It seems vagrant is trying something with sudo, which isn't istalled. I get this error:
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mkdir -p /vagrant
Stdout from the command:
Stderr from the command:
ash: sudo: not found
It works so far, I can login as root with the password vagrant, but I guess this is not perfect?
This is my setup: https://github.com/rubo77/ffnord-example/blob/pyddhcpd/Vagrantfile
config.ssh.username = 'root'
config.ssh.password = 'vagrant'
config.ssh.insert_key = 'true'
config.ssh.shell = 'ash'
(0..9).each do |i|
config.vm.define "gc-node0#{i}" do |node|
end
end
By default vagrant share/sync the directory /vagrant (guest) with the current project directory, the one containing the Vagrantfile (host), more directories can be shared using config.vm.synced_folder, I don't know if the default /vagrant can be disabled.
If you aren't using the shared directories feature then the missing sudo isn't a problem.
If your filesystem is writeable you can create the /vagrant directory once, so on next up vagrant shouldn't try to sudo mkdir again;
but assuming you're using VirtualBox (I don't know about others emulator behavior/architecture) you'll face another problem, shared directories require the kernel modules vboxsf and vboxguest (from VirtualBox Guest Additions) to be built (against the running kernel sources) and loaded (insmod), and the command mount.vboxsf to be built and installed in /sbin, plus your busybox require the option mount helpers enabled because vagrant use mount -t vboxsf and not mount.vboxsf directly, when vagrant try to mount the shared directories and those requirements aren't matched there is a long timeout before failing with error (a minute/two or more).
Notice that busybox (current stable) support sudo, is just disabled by default.
If you're building the buildroot yourself from sources I can tell that the shared feature works (I managed to get an image with busybox to work as vagrant expect), if you're using some pre-built kernel/busybox... may be a problem, you have to find matching binaries for vboxsf, vboxguest, mount.vboxsf and if the mount helpers option is disabled in your busybox you need to find a workaround (perhaps modifying vagrant to use mount.vboxsf).

Mounting a symlinked folder in vagrant & virtualbox

Okay, so here is my problem:
I use vagrant with VirtualBox. The host is Windows 8.1, the guest is Ubuntu (64bit). I am trying to use a symlinked windows folder created by
mklink /j somefolder someotherfolder
as synced folder in Vagrant. In my Vagrantfile I have
# disable the default synced folder
config.vm.synced_folder ".", "/vagrant", disabled: true
# sync my desired folder
config.vm.synced_folder "./somefolder", "/vagrant"
Unfortunately this does not work, but gives the following error:
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:
mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3`
vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant
The error output from the last command was:
stdin: is not a tty
/sbin/mount.vboxsf: mounting failed with the error: Invalid argument
Before you ask: Guest additions are installed, and mounting regular folders works flawlessly.
Is there a way to use symlinked directories as synced folders in vagrant with vbox?
Thanks for your help!
I was having a similar issue. I couldn't get Symlinks working with vagrant but a Hardlink Clone did. I was trying to have my Dev folder in sync with Google Drive but did not want to relocate the folder.
My Solution: Hardlink Clone
Download and install Linkshell for windows (and the listed prerequisite package) [ direct Link to actual file I downloaded | direct link to prerequisite package I downloaded ] Direct link good for Windows XP64,
Windows Vista64,
Windows Server ,
2003/2008/20012 64bit,
Windows 7/8/10 64bit
Right click on source folder (in my case the one I copied to Google drive) and select pick link source
In location where you want your "symlink", right click and select Drop as -> Hardlink Clone
Thats what it took for me to get it working with vagrant. I originally tried as symbolic link without success.
Cut the folder to where you need it from the VM, after that create the junction (or symlink) at the original location.

Resources