Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant up takes a long time after "Waiting for machine to boot. This may take a few minutes..." to finish booting

I have an ubuntu virtualbox. Everything works fine, except that on boot, it takes about 5 or more minutes after the message

Waiting for machine to boot. This may take a few minutes...

before it finishes booting:

➜  my_box  vagrant reload
/Users/pinouchon/.vagrant.d/boxes/my_box/virtualbox/include/_Vagrantfile:5: warning: already initialized constant VAGRANTFILE_API_VERSION
[default] Attempting graceful shutdown of VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
# More port forwards 
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
# waits about 5 minutes at this point, then:

[default] Machine booted and ready!
[default] The guest additions on this VM do not match the installed version of
VirtualBox! In most cases this is fine, but in rare cases it can
cause things such as shared folders to not work properly. If you see
shared folder errors, please update the guest additions within the
virtual machine and reload your VM.

Guest Additions Version: 4.3.0
VirtualBox Version: 4.2
[default] Configuring and enabling network interfaces...
[default] Mounting shared folders...
[default] -- /vagrant

This box used to be much quicker (about 30s to boot). So I think it is a network config that causes a timeout or something like that.

It tried the fixes proposed here: https://github.com/mitchellh/vagrant/wiki/%60vagrant-up%60-hangs-at-%22Waiting-for-VM-to-boot.-This-can-take-a-few-minutes%22

but without success. (I tried the fix Resolve it and the workaround 2.).

I also tried removing any 127.0.0.1 entries in my /etc/hosts files. Without success.

Any hint ?

OS / Versions:

Host: OSX 10.8.5
Guest: Ubuntu 12.05
Virtualbox: 4.2
like image 535
Benjamin Crouzier Avatar asked Jan 08 '14 18:01

Benjamin Crouzier


2 Answers

@spuder's suggestion of vagrant up --debug fixed this problem for me. It seemed that the VirtualBox GUI ran more smoothly and popped up a window sooner in the process. I had turned that on the way others suggested:

config.vm.provider :virtualbox do |vb|
  vb.gui = true
end

and had set config.vm.boot_timeout = 600.

This was in relation to the setup for the Udacity course Full Stack Foundations.

like image 87
Noumenon Avatar answered Sep 18 '22 12:09

Noumenon


This can also occur if vagrant isn't able to make an SSH connection.

It seems to not report any error for why it hangs in this case.

Se the GUI to show:

 # Show GUI or not.
config.vm.provider "virtualbox" do |v|
  v.gui = true
end

You may see the "dev login:" or other prompt like everything is just fine.

Then you may remember you changed the SSH keyset on the guest last night...

Solution: Tell vagrant where the private key is on the host.

 # Use a new keyset
config.ssh.private_key_path = "~/.ssh/id_rsa"

Public Key Needs to be on guest too.

This will only work if you have already put the matching public key in the authorized_keys file on the guest.

This varies by OS, but on the common Precise64 box, it looks something like this from a terminal:

Linux Host with openssh-client

ssh-copy-id -i .ssh/id_rsa.pub [email protected]

Mac Host

cat ~/.ssh/id_rsa.pub | ssh [email protected] "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"

There is also a port of ssh-copy-id for mac. https://github.com/beautifulcode/ssh-copy-id-for-OSX

This SO post has a simple inline shell provisioner to swap out the authorized_keys when provisioning a machine to make it automatic. Vagrant insecure by default?

like image 22
shanemgrey Avatar answered Sep 19 '22 12:09

shanemgrey