Home > debian, vagrant > Vagrant was unable to communicate with the guest machine

Vagrant was unable to communicate with the guest machine

Problem:
I was setting up vagrant on an old laptop running debian 8. I also had virtualbox installed. I ran into the following error when trying to set up an ubuntu vm.

$ vagrant init ubuntu/trusty32
$ vagrant up
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: flaskbox_default_1477256195436_10223
==> 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: 22 (guest) => 2222 (host) (adapter 1)
==> 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
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.

The main reason for this was because the networking on ubuntu was not working.

Solution:
The fix was to restart the network interface on the ubuntu box.

To do this I had to log into the box via the gui interface using virtualbox or uncommenting “vb.gui=true” in the Vagrantfile.

After connecting I ran the following commands

$ sudo ifdown eth0
$ sudo ifup eth0

I then made sure that I could ping google.com and the host box. Now I needed to enable this when the machine booted. That meant adding the same command to /etc/rc.local

$ less /etc/rc.local
ifdown eth0
ifup eth0

exit 0

I now did a test run on ubuntu/precise32. This worked well and vagrant was now working as expected. Trying the same on ubuntu/trusty32 resulted in a timeout once again. This meant that I had to add the following to the Vagrantfile

  # For ubuntu/trusty32 the box takes a while to boot up.
  # Default timeout is 300 seconds.
  config.vm.boot_timeout = 600

Now both boxes are able to come up even after reboot.

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'ubuntu/trusty32' is up to date...
==> 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: 22 (guest) => 2222 (host) (adapter 1)
==> 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
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.3.36
    default: VirtualBox Version: 5.1
==> default: Mounting shared folders...
    default: /vagrant => /home/rodnee/boxes/testbox
$ vagrant ssh
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-100-generic i686)

 * Documentation:  https://help.ubuntu.com/

  System information as of Sun Oct 23 21:21:41 UTC 2016

  System load:  0.25              Processes:           81
  Usage of /:   3.3% of 39.34GB   Users logged in:     0
  Memory usage: 15%               IP address for eth0: 10.0.2.15
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.


Last login: Sun Oct 23 21:12:08 2016 from 10.0.2.2
vagrant@vagrant-ubuntu-trusty-32:~$ exit
logout
Connection to 127.0.0.1 closed.
$ vagrant halt
==> default: Attempting graceful shutdown of VM...

Note:
You would have to log into a new box the very first time to bring up the network interface. The new changes will persist after a reboot.

Sources:
This took me so long to fix and I went down so many different rabbit holes that I can’t quite say that there was a definitive source that helped me out.

Lessons learnt
1. Installing the latest version of virtualbox did not work on debian 8 (stretch). I needed to stick with what came with the distribution.
2. I did not need to install virtualbox-guest-additions as it already comes with virtualbox.
3. There is no need to change the Network settings on virtualbox. The default settings for NAT work just fine and were not part of the problem.

# Packages that I needed to install
$ sudo apt-get install virtualbox virtualbox-guest-dkms dkms
$ sudo apt-get install vagrant
Advertisements
  1. Fivos
    April 10, 2017 at 11:05 pm

    Solution worked for i686 with Ubuntu 16.04.2 Xenial, Vagrant 1.9.3, VirtualBox 5.1.18

    (Thanks so much!)

    • April 11, 2017 at 4:09 pm

      You’re welcome. Glad to see that it helped.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: