vagrant box copy not working well - vagrant

I cannot boot a vagrant box copy without problem.
I use "hashicorp/precise32" (I cannot install "ubuntu/trusty64" or 32 on my machine, I've tried everything. I guess it's because my pc is too old, 2009).
I can vagrant up using the default added box "hashicorp/precise32".
All works fine.
Then, I vagrant halt and do a copy of the vagrant box like that :
vagrant package --base myprojectvm_default_1437507203066_25705 --output mybox.box
vagrant box add mybox.box --name mybox
Then I vagrant destroy.
Then I change Vagrantfile : config.vm.box = "hashicorp/precise32"
to config.vm.box = "mybox"
THen I run vagrant up and I see this in my guest after minutes :
"Waiting for network configuration...
Waiting up to 60 more seconds for network configuration....
Booting system without full network configuration..."
Then some "Starting..." lines among other lines... and finally, machine booted.
Why "without full network configuration" ?

From the vagrant book
It is very common for Linux-based boxes to fail to boot initially.
This is often a very confusing experience because it is unclear why it
is happening. The most common case is because there are persistent
network device udev rules in place that need to be reset for the new
virtual machine. To avoid this issue, remove all the persistent-net
rules. On Ubuntu, these are the steps necessary to do this:
$ rm /etc/udev/rules.d/70-persistent-net.rules
$ mkdir /etc/udev/rules.d/70-persistent-net.rules
$ rm -rf /dev/.udev/
$ rm /lib/udev/rules.d/75-persistent-net-generator.rules>
on centos box, this is the command I am running
cd /etc/sysconfig/network-scripts/
sudo rm -f ifcfg-eth1
cd /etc/udev/rules.d/
sudo rm -f 70-persistent-net.rules
It then has always been working fine for me

Related

Vagrant : synchronised folder that is creating during provisionning error

I am trying to share a folder betwing my vagrant box and my host using this directive in Vagrantfile :
config.vm.synced_folder "./syncWithBox", "/var/www/html/"
The issue is that the /var/www/html/ folder is created during provisionning (installing apache2 server).
So when I vagrant up, there is an error because the /var/www folder does not exist before provisionning !
Is there a way to solve that ? How can I tell vagrant to perform folder sync after provionning ?
I saw a similar question here, but the answer is not exactly what I am looking for
This workaround works for me. I put the following command in an install.sh script and run it:
#!/bin/bash
vagrant plugin install vagrant-vbguest && vagrant up --no-provision
sed -i 's/#config.vm.synced_folder/config.vm.synced_folder/' Vagrantfile
vagrant halt && vagrant up --no-provision
vagrant provision
Install vbox addition with vagrant-vbguest plugin and Vagrant up the box without provisioning it
uncomment the synchronized folder directive using sed for example
stop the box and Vagrant it up without provisioning it : so the folders between host and guest are empty but synchronized
finally, provision the box

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

No synced vagrant folder to be found

I am trying to work through the "Getting Started" section at the vagrant site. I run through the two commands they show:
$ vagrant init hashicorp/precise32
$ vagrant up
All seems to go well. I then run these two commands:
$ vagrant ssh
$ lsb_release -a
The result shows I'm running on Ubuntu 12.04, precise. So far so good.
However, when I do an 'ls' the only thing in the directory is a postinstall.sh file. I thought I should have been in the same directory as the Vagrantfile.
Sorry for such a newbie question. I'm sure its something basic I messed up.
I'm doing this on an Ubuntu 14.10 box with Virtualbox 4.3.22 and Vagrant 1.7.2 installed.
Thanks
By default, Vagrant will share your project directory (the directory with the Vagrantfile) to /vagrant on the guest machine.

How to rebuild vagrantfile

I vagrant up a project, but accidentally delete the Vagrantfile folder, the VM is still in VirtualBox, how to rebuild the vagrantfile and assign it to the same VM.
You cannot rebuild Vagrantfile. But you can associate your folder with existing vm.
Short step-by-step (based on this link):
create file named .vagrant
run $ VBoxManage list vms in your terminal
get id hash for desired machine.
put into .vagrant this code: {"active":{"default":"YOUR-ID-HERE"}}
So you'll get something like this: {"active":{"default":"ec426377-dbe6-4be7-4751-766956e44958"}}
run $ vagrant init (this will create new Vagrantfile)
run $ vagrant up (this will associate your desired folder with running vm)
run $ ssh-keygen -t rsa -f .vagrant/machines/default/virtualbox/private_key
run $ ssh-copy-id -i .vagrant/machines/default/virtualbox/private_key.pub -p 2222 vagrant#127.0.0.1, password: vagrant
I don't think there is a way to do that (create a Vagrantfile from an existing VM). From the perspective of Vagrant virtual machines being temporary in nature (build, use, destroy), you're best bet may be to recreate the Vagrantfile again and start over.
If there is something on the VM that you want or need, you could access it directly via VirtualBox, then copy over to the new VM as needed.

Resources