42

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

0

18 Answers 18

10

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.

2
  • What is the workaround if I want to preserve myalias? Commented Sep 10, 2011 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
    Commented Apr 5, 2012 at 7:43
27

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
7
  • 3
    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
    Commented Jul 2, 2011 at 4:57
  • sudo /etc/init.d/networking restart is worked for me, thanks!
    – Anatoly
    Commented Sep 12, 2011 at 7:40
  • 2
    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
    Commented Oct 7, 2011 at 8:02
  • 2
    I get The following settings shouldn't exist: boot_mode
    – Calin
    Commented Mar 24, 2016 at 14:50
  • 2
    Got in the latest version you have to put v.gui = true for the provider config
    – Calin
    Commented Mar 24, 2016 at 14:52
6

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.

2
  • Deleting my unused host-only network in VirtualBox settings worked for me! Thank you!
    – Duke
    Commented Sep 21, 2013 at 16:32
  • 1
    It seems that this setting was depricated as of 1.3.X - github.com/berkshelf/berkshelf/pull/856 Commented Feb 19, 2014 at 21:58
5

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.

2

My network card type was originally set to 82540EM. I changed it to Am79C973 and now Vagrant up works every time. I've started multiple VMs, even rebooted the host and it still works.

The command is:

VBoxManage modifyvm yourmachinename --nictype1 Am79C973

Remember to repackage and readd your box to Vagrant.

I'm running Debian Squeeze 64-bit as host and guests, using VirtualBox 4.1.16 on a Core i7-2600 machine.

1

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.

1

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.

1

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

1

I uncommented the part in the Vagrantfile like this:

  config.vm.provider :virtualbox do |vb|
    # Don't boot with headless mode
    vb.gui = true

    # Use VBoxManage to customize the VM. For example to change memory:
    # vb.customize ["modifyvm", :id, "--memory", "1024"]
  end

I saved it and then I did

vagrant reload

and then things worked fine. I'm not sure why that fixed it though.

1

My guest box would not boot properly due to a disk issue.

I forced the VM to close via

VBoxManage controlvm <Name of VM> poweroff

Then I modified my Vagrantfile to include this line:

config.vm.boot_mode = :gui

Next, I re-ran

vagrant up

In the GUI that popped up, I had to run the 'disk fixer' utility.

After running the disk utility, my VM was successfully booted, and then I could run vagrant ssh.

0

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

0

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.

0

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 )

0

On windows 7 run

vagrant ssh

if you get something like this...

`vagrant ssh` isn't available on the Windows platform. You are still able
to SSH into the virtual machine if you get a Windows SSH client (such as
PuTTY). The authentication information is shown below:

Host: 127.0.0.1
Port: 2222
Username: vagrant
Private key: U:/.vagrant.d/insecure_private_key

Then you should use something like this...

ssh [email protected] -p 2222 -i /cygdrive/u/.vagrant.d/insecure_private_key

Notice I am using cygwin on my windows box rather than Putty.

3
  • OP is not using Windows 7.
    – rtf
    Commented Oct 29, 2012 at 20:25
  • Thank you r.tanner.f -- No OS was specified, this helped me, hopefully helps others.
    – Artistan
    Commented Oct 30, 2012 at 13:26
  • Don't know why you were downvoted, this seems like it could help other people
    – Mark
    Commented Jul 17, 2013 at 15:45
0

Here is another possible reason for the error:

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

A username can be specified in the config file like this:

config.ssh.username = "badusername"

If that username does not exist or cannot be logged into for some reason, neither you nor Vagrant will be able to SSH into the VM. Thus Vagrant will "fail to connect", even if the VM is in fact running and working properly.

0

My issue was that vagrant ssh wouldn't do anything at all.

I removed ~/.ssh/config and the problem was solved. Copy the file somewhere or rename it if you want to keep it.

1
  • on local or remote system? Commented Aug 19, 2018 at 2:39
0

As with others, I used the GUI (I always have this on to prevent problems like this)

config.vm.boot_mode = :gui

I then used the VirtualBox menu, as the commands here didn't work. Machine > Reset in the menu, then ssh was then possible.

0

I shut down the running vm and created a new basebox:

  1. Shut down VM I am trying to export
  2. vagrant package --base "salt-master basebox" --vagrantfile ./Vagrantfile

You must log in to answer this question.