Vagrantfile ordering provisioner issue - vagrant

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.

Related

vagrant guest additions and kernel

Getting a 'vboxsf' error whenever I try to up the centos7 box.
I run vagrant init in the directory.Then I go in directory and edit the file.And run the vagrant up.This is what I put in vagrant file:-
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define "Centos7" do |master|
master.vm.provider "virtualbox"
master.vm.box = "centos/7"
master.vm.hostname = "web.mylab.local"
master.vm.network :private_network, ip: "198.168.56.7"
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
master.vm.provision "shell", inline: <<-SHELL
sudo sed -1 "s/PasswordAuthentication.*/PasswordAuthentication
yes/g" /etc/ssh/sshd_config
sudo systemct1 restart sshd
SHELL
end
end
**This is the error message i get:-**
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 attempted was:
mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant
The error output from the command was:
mount: unknown filesystem type 'vboxsf'
You are defining a synced_folder (i.e. shared folder) for your VirtualBox vm.
This functionality requires the vm to have the VirtualBox Guest Additions installed
You are using a base box that does not have VirtualBox Guest Additions installed
From there you basically have 3 options
Modify your vagrant provisioning script to install Guest Additions when creating the vm (e.g. Insert the virtual CDROM into vm, mount it and lauch the install script). I still have a doubt this can break in case the shared folder mount happens before provisionning is finished...
Create a base box yourself that will have Guest Additions installed and use it. If you need to share this box with other devs, you will have to host it somewhere.
Use an other base box with Guest Additions already installed.
I did not dig into the latest point for quite a while since I tend to craft my own boxes for my own use. But if I remember well, the public generic/centos7 box comes with Guest Additions pre-installed for the VirtualBox provider.

Vagrant unable to mount shared folders - No such file or directory

I have this Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty32"
config.vm.hostname = "app.local"
config.vm.network :private_network, ip: "192.168.20.20"
config.vm.synced_folder ".", "/vagrant", :mount_options => ['dmode=774','fmode=775']
config.vm.provider :virtualbox do |vb|
vb.name = "MyBox"
vb.memory = 512
vb.cpus = 2
end
config.vm.provision :shell, path: "install.sh"
end
that I used so far without problems (on Ubuntu and Windows). On Windows 10, I have upgraded both Oracle VM Virtual Box (5.1.16) and Vagrant (1.9.2) and now I get this error when trying to install the box:
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 attempted was:
mount -t vboxsf -o dmode=774,fmode=775,uid=1000,gid=1000 vagrant /vagrant
The error output from the command was:
: No such file or directory
I also see this:
GuestAdditions versions on your host (5.1.16) and guest (4.3.36) do not match.
* Stopping VirtualBox Additions
and then it looks like the GuestAdditions is removed and the 5.1.16 version is installed, steps that ends with:
vboxadd.sh: Building Guest Additions kernel modules. vboxadd.sh:
Starting the VirtualBox Guest Additions.
Could not find the X.Org or XFree86 Window System, skipping.
After this, I still get:
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims: 4.3.36 VBoxService inside the vm
claims: 5.1.16 Going on, assuming VBoxService is correct... Got
different reports about installed GuestAdditions version: Virtualbox
on your host claims: 4.3.36 VBoxService inside the vm claims:
5.1.16 Going on, assuming VBoxService is correct...
Is this a bug or am I doing something wrong?
It looks like this was fixed in 5.1.18. Updating to the latest version fixed the problem for me.
Change Log (Version 5.1.18):
Shared Folders: fixed case insensitive filename access (5.1.16 regression; Windows guests only; bug #16549)
Shared Folders: fixed access to long pathes (5.1.16 regression; Windows guests only; bugs #14651, #16564)

vagrant - constantly syncing folder setup

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?

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

Chef Vagrant, Can't Find Folder

Chef is really confusing me. Can you help me understand why it's not working?
Cliff Notes
I'm using Chef-Solo (not Berkshelf or anything else)
Everything works when I set it up from scratch, I can vagrant provision
But if I reboot the HOST (My main operating system) it breaks!
It appears to be looking inside a .chef folder which I did not specify in my vagrant configuration.
I have to do a vmboxmanage box destroy ubuntu/trusty64 and redownload everything and redo vagrant up if I reboot.
Vagrant Version 1.7.2
Virtual Box Version 4.3.20r96996
Inside Vagrant SSH Error:
Note: The files are not pointing to the .chef folder, but they are here?
[2015-01-30T16:23:44+00:00] WARN: Did not find config file:
/etc/chef/solo.rb, using command line options.
[2015-01-30T16:23:50+00:00] FATAL: None of the cookbook paths set in
Chef::Config[:cookbook_path],
["/vagrant/.chef/cookbooks", "/vagrant/.chef/site-cookbooks"],
contain any cookbooks
$vagrant up and $ vagrant provision error:
==> default: Mounting shared folders...
default: /vagrant => /home/jesse/if/indieflix/vagrant
default: /home/vagrant/chef-recipes => /home/jesse/projects/if/vagrant/chef-recipes
default: /home/vagrant/chef-resources => /home/jesse/projects/if/vagrant/chef-resources
==> default: Running provisioner: chef_solo...
==> default: Detected Chef (latest) is already installed
Shared folders that Chef requires are missing on the virtual machine.
This is usually due to configuration changing after already booting the
machine. The fix is to run a `vagrant reload` so that the proper shared
folders will be prepared and mounted on the VM.
And, vagrant reload does nothing.
Vagrantfile
# ...
config.vm.synced_folder "chef-recipes", "/vagrant/chef-recipes"
config.vm.synced_folder "chef-resources", "/vagrant/chef-resources"
# ...
config.vm.provision "chef_solo" do |chef|
# Relevant to the Vagrantfile path
chef.cookbooks_path = ["chef-recipes"]
# This is just required by Chef, so it's minimal
chef.environments_path = "chef-resources/environments"
# This is the internal flag.
chef.environment = "development"
# This defines the cookbooks to run
chef.roles_path = "chef-resources/roles"
chef.add_role("development")
end
Folder Structure
chef-recipes/ (Git Submodule)
----python/
--------recipes/
------------default.rb
------------pip.rb
chef-resouces/ (Git Submodule)
----environments/
--------development.json
----roles/
--------development.json
Vagranfile
Anthony suggested in a comment I answer my question since it was answered in comments. Here it is!
Instead of using curl to install, I used omnibus which adds another step before provisioning:
$ vagrant plugin install vagrant-omnibus
Second, Chef-Solo/Vagrant has an issue with mounting files from the Host. The only workaround I have found is:
$ rm .vagrant/machines/default/virtualbox/synced_folders vagrant reload --provision
Optional: I created a bash script to make the above a little quicker:
reprovision.sh
#/bin/bash
rm .vagrant/machines/default/virtualbox/synced_folders
vagrant reload --provision
And of course chmod +x reprovision.sh and to run ./reprovision.sh

Resources