kvz.io
Published on

Fix Vagrant Box Hanging at Boot

Authors
  • avatar
    Name
    Kevin van Zonneveld
    Twitter
    @kvz

Sometimes it happens that vagrant hangs during boot of your virtual image. Right after typing:

$ vagrant up

It hangs for a long time and then finally throws:

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

If you open VirtualBox you'll see that the virtual machine preview shows a black screen with kernels to choose from. This is GRUB requiring user input to boot further.

Here's how to fix that.

First, get the machine id

$ # Before v1.1
$ # MACHINE_ID=$(awk -F\" '{print $6}' .vagrant)
$ # After v1.1
$ MACHINE_ID=$(cat .vagrant/machines/default/virtualbox/id)

Power off the VM

$ VBoxManage controlvm ${MACHINE_ID} poweroff

Then boot the machine with a GUI console

$ VBoxManage startvm ${MACHINE_ID}

Wait for it to boot, login, run:

$ sudo update-grub

When successful, shut it down

$ VBoxManage controlvm ${MACHINE_ID} poweroff

And after this, vagrant up will just boot your VM normally :)

Legacy Comments (7)

These comments were imported from the previous blog system (Disqus).

Bruno Batista
Bruno Batista·

Awesome! Solve my problem, many many thanks!

Sergey Ryabenko
Sergey Ryabenko·

How to connect to guest OS, if it is not loaded?

Ghanshyam
Ghanshyam·

Hi Kvz,

I followed your instruction till VBoxManage startvm ${MACHINE_ID} this command.

My Virtualbox gets started as well, but still there is nothing in that apart from blank screen.

Chamila Wijayarathna
Chamila Wijayarathna··1 like

Hi,

When I run 'vagrant up' I get https://gist.github.com/cdw....

Any idea on whats going on here?

Kev van Zonneveld
Kev van Zonneveld·

Hi, a good way to debug is to open VirtualBox and take a look at the screen preview. You'll see where exactly the box is hanging

Chamila Wijayarathna
Chamila Wijayarathna·

Hi, thanks for reply, In the beginning it says "Press F12" which we get in normal computer startup. From few seconds it disappears and shows black screen with nothing on it.

mattmcgiv
mattmcgiv·

Genius! Thanks Kevin.