Please clarify vagrant behavior - vagrant

I have just started working with Vagrant. After starting guest machine and making some changes (e.g. installed some updates and python virtualenvs). And after few (vagrant halt and vagrant reload) when I ssh-ed into guest machine I noticed that all my changes disappeared. When I opened the Virtualbox I saw that there were two boxes with the name of my folder with guest os and on every vagrant up it seems like it is starting the second machine. When I started the first guest os through virtual box interface I saw that my data was present. How can I start with vagrant the first machine? Should I delete the second? When was it created?
Start with vagrant up
Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = "trusty_14"
config.vm.network "forwarded_port", guest: 8000, host: 8000
end`

So I tried to vagrant destroy. The second machine was deleted indeed, but after vagrant up the new one was created.
Then I checked the id's following #Frédéric Henri advice, and in id file was id of second machine, so I have replaced it with the id of first machine from VBoxManage list vms, and everything works!
But still did not get how and when the second machine was created...

Related

Vagrant Waiting For Domain To Get An IP Address

First, apologies: I'm a newbie.
I've created a very basic Vagrantfile by running Vagrant init. I only made a few changes:
config.vm.box = "generic/fedora28"
config.vm.box_version = "1.8.32"
config.vm.provider "libvirt" do |lv|
lv.memory = "4096"
end
(There are also a few items in my config.vm.provision section).
After running vagrant up , the process gets stuck at
==> default: Waiting for domain to get an IP address...
I'm running this off a Fedora 27 box, which uses version 2.0.2 of the Vagrant package (even though current is 2.1.5).
I've tried adding this line:
config.vm.network "private_network", ip: "192.168.100.101"
but it had no effect.
Can anyone help?
I have a Vagrant File that spins up 4 VMs, of image generic/ubuntu2004 on libvirt kvm, to make a k3s cluster that's accessible on the LAN. (multipass + k3s is only accessible via localhost b/c it doesn't allow easy bridging.)
I ran both of these commands > 50 times
sudo vagrant destroy --force --parallel
sudo vagrant up
On the ~51'st time, I noticed vagrant up got stuck on "Waiting for domain to get an IP address..."
What fixed it for me was sudo reboot. You know the classic have you tried unplugging it and plugging it back in?
Something else to try (I rebooted before trying it)
https://bugzilla.redhat.com/show_bug.cgi?id=1283989

Networking/Filesystem Issues in Creating a Vagrant/Virtualbox Environment Setup on New Host Machine

Recently, my work laptop died, and I'm trying to get my project setup on a different laptop that was in my garage. My project lives inside of a trusty64 Ubuntu vagrant box using Oracle's Virtualbox software. However, I'm running into a bunch of issues trying to get the vagrant setup to work on this laptop. I also have the project running on my home desktop, and it all works there just fine.
This laptop is a Gateway NE56R12u from 2012 with 8 GB of RAM. It has a 64-bit dual-core processor running Windows 10 Professional (I installed Ubuntu 16.04 on this laptop as well doing a dual-boot, it is having the same exact errors using the Ubuntu operating system as it is having using Windows 10) My home desktop (that everything works on just fine) is also Windows 10 Professional. I'm using Vagrant 2.0.0 and VirtualBox 5.1.28 on both Windows 10 machines. They are booting the same project on the same branch.
When looking at the Virtualbox GUI on the laptop, it is only showing 32-bit options for boxes, which seems to be due to a lack of available hardware acceleration (I did not find any acceleration options in the BIOS). The Virtualbox GUI throws an error that says due to missing acceleration properties, the box will not be able to detect that I have a 64-bit processor. The acceleration tab is inaccessible. So I've switched to trying to use a 32-bit 'trusty' box.
However, I am still having problems and am unable to use a virtual machine. The problems appear to be with network connections and connecting to my filesystem.
When I type in vagrant up it starts normally:
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/trusty32'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty32' is up to date...
==> default: Setting the name of the VM: directoryName_default_1509067920271_59622
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 3000 (guest) => 3000 (host) (adapter 1)
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
but then hangs there until time-out.
going into the Virtualbox GUI and watching the device boot, I watch it hang here:
waiting 10 seconds for network device
waiting 120 seconds for network device
then it says it gave up waiting for network device and continues. Eventually, it gets and hangs here:
Waiting for network configuration...
Waiting up to 60 more seconds for network configuration...
Booting system without full network configuration
then it quickly finishes booting and switches to a Vagrant login screen where I can successfully log in. When logged in, there are no files from my filesystem present. The command line where I started the boot process still has not changed at this point. It waits for the full time-out from the Vagrantfile and then throws the error that it timed out. I am not able to ssh in.
What I've done so far:
I have checked that the network adapter for the virtual machine is enabled. I have PAE set to on in my Vagrantfile because otherwise it is automatically set to off and throws a fatal error during boot (I tried turning pae, hwvirtex, vtxvpid, and vtxux all to off in my Vagrantfile). I made sure it only has one processor set. I have tried every network adapter setting available within the Virtualbox settings and there is no change. I have run bcdedit /set hypervisorlaunchtype off as an administrator on the command line. I've destroyed the .vagrant.d file folder, the .VirtualBox folder, and the VirtualBoxVMs folders from ~/user. I've tried different networking options such as public network and a private network with the local ip address.
Note: after running bcdedit /set hypervisorlaunchtype off my virtual machines no longer show in the Virtualbox GUI. However, the first time I deleted the .folder's after running that command, my machine successfully booted the box for the first time and everything was working correctly with it. However, the next day when I used vagrant up from the halted machine, it no longer worked again. Sometimes, instead of timing out, Vagrant gives the error that the machine went into the invalid state of 'unknown' state or 'paused' state. This behavior, however, is not consistent.
I've also re-installed Virtualbox and Vagrant, tried Virtualbox version 5.1.30 and version 5.2 (which I immediately learned is not compatible with Vagrant, which is interesting). At one point, upon a fresh install of Virtualbox it worked once and then it was immediately broken again after halting. Reinstalling again does not make it work. I tried using the hashicorp/precise32 box, and while that is created, boots, and is ssh accessible with access to my filesystem it does not seem to support node or versions of npm after version 1.1.14 and npm install fails. The ubuntu/xenial32 box always has a stderr while trying to boot on the command line. I can not get the logs because the VMs themselves do not show up in the Virtualbox GUI. I ran bcdedit /set hypervisorlaunchtype auto as having it set to off did not help solve my problem, but the Virtualbox GUI still does not show my VMs. Having vb.gui set to true in the Vagrantfile does not change this and the GUI does not show.
This is an error message I've gotten from the Virtualbox GUI many, many times:
The VM session was aborted.
Result Code: E_FAIL (0x80004005)
Component: SessionMachine
Interface: ISession {7844aa05-b02e-4cdd-a04f-ade4a762e6b7}
My Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty32"
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.boot_timeout = 500
config.vm.provider "virtualbox" do |vb|
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
vb.customize ["modifyvm", :id, "--pae", "on"]
end
config.vm.provision :shell, :path => "scripts/init_environment.sh"
end
I don't know what's wrong. It's technically worked twice, so I feel there must be a software and not a hardware problem? I can get a different box to work fine on this computer, but that box doesn't work for my project. This project has been setup on 3 other computers successfully with 0 issues (2 of them Windows 10, one Mac OSX), though none of those machines required a 32-bit box. Any ideas are greatly appreciated, I just need this to work so I can work on the go! Many of my errors are not consistent. The next thing I'm thinking about trying is taking out the Ubuntu dual-boot...
Edit:
I will also note that I put vb.memory = "1024" into my Vagrantfile and the Virtualbox still uses 512 MB of base memory according to Virtualbox. Also, I got the VM's to show in the Virtualbox software again, and grabbed a logfile .
The issue for me seemed to be that the virtual machine had shut down previously with some orphaned child nodes (I have no idea what that means). But, I did find this article explaining how to save a broken system and reboot from disc (which the article explains where you can download this).
https://superuser.com/questions/947942/unprocessed-orphan-inode-list-in-virtualbox-vm

Is "vagrant up" possible from different local directories with custom URLs?

I have two directories under /var/www/html, named vlp1 and vlp2 with Vagrant setup. If I run vagrant up separately in these folders the default local URL is vagrant.local for both. But vagrant.local/ always loads site from vlp1 folder.
As it should be, vagrant global-status shows that I have two virtual machines running under these directories. I require to run both sites side by side and to do this the only option I see is to have separate URLs. I believe there is a way to assign different URLs to different sites but don't have any idea how!
What I need to do to accomplish the above so that my sites run like local.vlp1.com and local.vlp2.com or may be like vagrant.vlp1 and vagrant.vlp2?
According to project instructions I have to keep two sites completely separated in two folders and have to use separate Vagrantfiles.
OS: Ubuntu 14.04 64 bit
Installed VitualBox version: 5.1
Installed Vagrant version: 1:1.9.4
Thank you!
UPDATE
Went through the following steps as advised by Henri:
Step 1:
$ vagrant global-status
Output:
id name provider state directory
------------------------------------------------------------------------
eb9b569 default virtualbox running /var/www/html/vlp1
190608c default virtualbox running /var/www/html/vlp2
Step 2: Did a graceful shutdown on vlp2
$ vagrant halt 190608c
Step 3: Output of vagrant global-status now is
id name provider state directory
-------------------------------------------------------------------------
eb9b569 default virtualbox running /var/www/html/vlp1
190608c default virtualbox poweroff /var/www/html/vlp2
Step 4:
$ sudo gedit /var/www/html/vlp2/Vagrantfile
if CONF['ip'] == "dhcp"
config.vm.network :private_network, type: "dhcp", hostsupdater: "skip"
else
config.vm.network :private_network, ip: "192.168.2.5"
end
Step 5: Re up'd vlp2 machine
$ vagrant up 190608c
Step 6:
$ vagrant global-status now shows both machine are back to running state again.
id name provider state directory
------------------------------------------------------------------------
eb9b569 default virtualbox running /var/www/html/vlp1
190608c default virtualbox running /var/www/html/vlp2
Step 7:
In /etc/hosts added following entry
192.168.2.5 vagrant.vlp2
Finally I tried vagrant.vlp2/ in browser but ended up with the following message:
This site can’t be reached
http://vagrant.vlp2/ is unreachable.
As I understand you're using multiple VM so the easiest in this case is to assign each of the VM a static IP (that must be different) so you do so in Vagrantfile
Vagrant.configure("2") do |config|
...
config.vm.network "private_network", ip: "192.168.10.x"
...
end
and you use another IP for the second VM
Vagrant.configure("2") do |config|
...
config.vm.network "private_network", ip: "192.168.20.y"
...
end
and then you update your /etc/hosts file with the information
192.168.10.x vagrant.vlp1
192.168.20.y vagrant.vlp2

Vagrant cannot vagrant up the box packaged from ubuntu xenial64 16.04

I have a custom vagrant box based on the offcial box ubuntu 16.04.
I simplly run like this to get the packaged box.
vagrant init ubuntu/xenial64; vagrant up --provider virtualbox
vagrant up
vagrant ssh # enter the virtual machine and do some custom change on it
vagrant halt
vagrant package --vagrantfile Vagrantfile --output custom_ubuntu1604.box
and then i copy the file custom_ubuntu1604.box to another directory, i use the box like this:
vagrant box add ubuntu1604base custom_ubuntu1604.box
vagrant init ubuntu1604base
vagrant up # at this point the machine will be stopped at "Started Journal Servie"
my new virtualbox machine base on the new packaged box will stop at:
the screenshot
And finally it timed out:
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within the
configured ("config.vm.boot_timeout" value) time period.
If you look above, you should be able to see the error(s) that Vagrant
had when attempting to connect to the machine. These errors are
usually good hints as to what may be wrong.
If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes. Verify
that authentication configurations are also setup properly, as well.
If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
Try to set config.vm.boot_timeout in Vagrantfile more than default e.x.600. From my experience I found out it take a long time at the first time to connecting guest machine.
For example
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.provider "virtualbox"
config.vm.boot_timeout = 600
end

Vagrant access guest machine from host (windows)

I installed a vagrant virtual machine in Windows, it's working fine, I am trying to connect to the guest machine from windows, but as soon as I uncomment some thing in Vagrantfile like :
config.vm.network "private_network", ip: "192.168.33.10"
OR
config.vm.network "public_network"
when reloading vagrant, I got this error :
The guest machine entered an invalid state while waiting for it
to boot. Valid states are 'starting, running'. The machine is in the
'poweroff' state. Please verify everything is configured
properly and try again.
If the provider you're using has a GUI that comes with it,
it is often helpful to open that and watch the machine, since the
GUI often has more helpful error messages than Vagrant can retrieve.
For example, if you're using VirtualBox, run `vagrant up` while the
VirtualBox GUI is open.
The primary issue for this error is that the provider you're using
is not properly configured. This is very rarely a Vagrant issue.
I know this does not make sense but I just open VirtualBox and with right-click goes to Settings of created vagrant machine image and diable Audio and it is working after save and run vagrant up
I never encountered that error personally, having never used vagrant on windows. This issue has been discussed here.

Resources