vagrant up fails when it gets to the ssh part:

myterminal$ vagrant up
[default] VM already created. Booting if its not already running...
[default] Running any VM customizations...
[default] Clearing any previously set forwarded ports...
[default] Forwarding ports...
[default] -- ssh: 22 => 2222 (adapter 1)
[default] -- db2: 30003 => 30003 (adapter 1)
[default] Cleaning previously set shared folders...
[default] Creating shared folders metadata...
[default] Booting VM...
[default] Waiting for VM to boot. This can take a few minutes.
[default] Failed to connect to VM!
Failed to connect to VM via SSH. Please verify the VM successfully booted
by looking at the VirtualBox GUI.

Then when I subsequently try and connect using vagrant ssh or vagrant reload or similar, I get this:

myterminal$ vagrant reload
[default] Attempting graceful shutdown of linux...
SSH connection was refused! This usually happens if the VM failed to
boot properly. Some steps to try to fix this: First, try reloading your
VM with `vagrant reload`, since a simple restart sometimes fixes things.
If that doesn't work, destroy your VM and recreate it with a `vagrant destroy`
followed by a `vagrant up`. If that doesn't work, contact a Vagrant
maintainer (support channels listed on the website) for more assistance.

Please help! I'm really stumped.

Kind regards,

Luke

link|improve this question
feedback

migrated from stackoverflow.com Oct 3 '11 at 12:10

This question came from our site for professional and enthusiast programmers.

10 Answers

up vote 2 down vote accepted

I saw this problem with my setup and eventually narrowed it down to the fact that I'd added a name onto the local hosts file. So I had:

127.0.0.1 localhost myname myalias

Removed the myalias which I'd added and it booted okay. Thanks to @saphirlazuli for the clue that it was networking related.

link|improve this answer
What is the workaround if I want to preserve myalias? – Mickey Cheong Sep 10 '11 at 12:10
If you want to use an alias, the Debian/Ubuntu way is to keep the first line as just 127.0.0.1 localhost, but add a second line with your aliases, like so: 127.0.1.1 foo bar baz – CodeGnome Apr 5 at 7:43
feedback

I have had the same problem with the box given in the "Getting started" of Vagrant site. My solution below is for this tutorial's box.

I find a solution here : https://github.com/mitchellh/vagrant/issues/391

  1. in the VagrantFile, add the gui mode : config.vm.boot_mode = :gui
  2. run vagrant up
  3. in the gui, log with the user "vagrant" (password = "vagrant")
  4. int the gui, run sudo /etc/init.d/networking restart, in /etc/network/interfaces file, you must now have a section with #VAGRANT-BEGIN [...]#VAGRANT-END
  5. run vagrant reload on the physical machine
link|improve this answer
2  
This worked for me, thanks. I had Vagrant running before, then it stopped working with a new box. Any idea what causes it? – Andrew Vit Jul 2 '11 at 4:57
sudo /etc/init.d/networking restart is worked for me, thanks! – mikhailov Sep 12 '11 at 7:40
This also worked for me. Thanks! – Eric H Sep 29 '11 at 14:37
I did restart, but in /etc/network/interfaces I don't have section with #VAGRANT-BEGIN [...]#VAGRANT-END, any clue why? Can I add it manually? – sparrovv Oct 7 '11 at 8:02
sudo dhclient works too – Ngo Minh Nam Nov 14 '11 at 16:30
feedback

This is an intermittent problem for me, and definitely seems to be related to networking. I found some more helpful information at Vagrant GitHub issues #391 and #455. I tried deleting my unused host-only network in VirtualBox settings (as recommended as a potential fix in one of the GitHub issues) which didn't seem to help.

Starting in gui mode (as described in a previous answer) is a great way to debug/fix problems. I found that it's because for whatever reason, the VM cannot obtain an IP address on startup. Starting in GUI mode then logging in (vagrant/vagrant) and running sudo dhclient in the guest OS would retrieve the IP address and the Vagrant setup process would complete successfully.

Still looking for a permanent fix though.

Hope this helps!

[EDITED TO ADD]: A helpful suggestion was added to GitHub Issue #455 which involves adding the following config to your Vagrantfile:

config.ssh.max_tries = 150

This is currently working for me, and seems to make sense since the problem seems to be related to timeout - increasing the number of tries should increase the probability of the SSH process succeeding in time. It's an intermittent issue in the first place so I'll reserve judgement for a while, but fingers crossed it'll work! Thanks to karel1980 for suggesting the fix.

link|improve this answer
feedback

If vagrant up fails, I recommend the following:

  1. Boot with gui mode: this helps to see if the image is broken (or e.g. what it does before the provisioning is started), set config.vm.boot_mode = :gui in your Vagrantfile
  2. Debug logging: run the provisioning with debug, chef.log_level = :debug
  3. Repackage the box: sometimes you need to install something before everything else runs - to bootstrap the bootstrapper. That's not really possible, so the easiest is to boot a vm without any provisioning, install whatever you need and re-package the box (vagrant box repackage foo, then vagrant import foo and then add foo in your Vagrantfile)

Note: gui mode can have other issues, e.g. for me no provisioning works with vagrant 0.7.5 when gui is enabled. It's still great to debug the actual box though.

link|improve this answer
feedback

If the kernel module is already installed, try starting the VM directly with VirtualBox. This will show you any startup errors encountered as the VM boots. Problems like filesystem errors will stop the SSH server daemon from operating correctly.

link|improve this answer
feedback

I had the same problem on osx (VirtualBox 4.1.0 and Vagrant 0.8.6), and for me the only help was to:

  1. login with :gui by login/pass: vagrant/vagrant
  2. modify the “/etc/rc.local” file to include the line “sh /etc/init.d/networking restart” just before “exit 0″.
  3. disable :gui
  4. vagrant reload

I've found this at: https://github.com/mitchellh/vagrant/issues/391 thx mikhailov.

link|improve this answer
feedback

Type sudo /etc/init.d/vboxdrv setup . It should now work.

link|improve this answer
feedback

My problem was that in

/etc/hosts

I had entry

127.0.1.1 lucid32

where as my box name was lucidtest, I changed the above line to

127.0.1.1 lucidtest

and it worked.

link|improve this answer
feedback

This message suggests ssh server is not running on the VM. make sure it is installed

sudo apt-get install openssh-server

and running

ssh localhost

should not give an error.

To exclude errors within vagrant, you should try ssh into the vm directly by:

ssh vagrant@localhost -p2222

(assuming default user and port forwarding )

link|improve this answer
feedback

I had this same problem. In my case 64-bit emulation wasn't enabled. Enabling this feature in my bios fixed the issue.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown