Note To Self: What to Do When a Vagrant Machine Stops Working (Destroy or Up Failing)

Sometimes "vagrant destroy" fails with an exception from the depths of the virtualbox Ruby gem or vagrant up freezes for a long time only to fail with SSH connection failure message. Here are some tips how to solve such problems.

See also my Vagrant Notes.

Vagrant Destroy Failing with "Error in API call" in ffi.rb

Sometimes "vagrant destroy" fails with an exception from the depths of the virtualbox Ruby gem. A solution might be to use the command-line VirtualBox tool VBoxManage to forcibly stop the machine.

Symptomps

1. "vagrant destroy" fails with an exception like this one:


$ vagrant destroy
[default] Destroying VM and associated drives...
/Library/Ruby/Gems/1.8/gems/virtualbox-0.9.2/lib/virtualbox/com/implementer/ffi.rb:106:in `call_and_check': Error in API call to unregister: 2159738887 (VirtualBox::Exceptions::InvalidObjectStateException)
	from /Library/Ruby/Gems/1.8/gems/virtualbox-0.9.2/lib/virtualbox/com/implementer/ffi.rb:80:in `call_vtbl_function'
	from /Library/Ruby/Gems/1.8/gems/virtualbox-0.9.2/lib/virtualbox/com/implementer/ffi.rb:61:in `call_function'
	from /Library/Ruby/Gems/1.8/gems/virtualbox-0.9.2/lib/virtualbox/com/abstract_interface.rb:145:in `call_function'
	from /Library/Ruby/Gems/1.8/gems/virtualbox-0.9.2/lib/virtualbox/com/abstract_interface.rb:62:in `unregister'
	from /Library/Ruby/Gems/1.8/gems/virtualbox-0.9.2/lib/virtualbox/vm.rb:578:in `destroy'
	from ...


2. VirtualBox GUI lists the vagrant_<number> machine as running

3. You can actually see the VirtualBox process started by Vagrant:


$ ps aux | grep -i vagr
me ... /Applications/VirtualBox.app/Contents/MacOS/VBoxHeadless --comment vagrant_1326716120 --startvm 026abe1a-b9

Solution

List all the VirtualBox VMs:

$ VBoxManage list vms


(This will also list internal hex IDs of the machines; you can find the id of the current machine in the .vagrant file in the directory where your ran vagrant from.)

Power off the Vagrant VM:


$ VBoxManage controlvm vagrant_1326716120 poweroff
# Or: 'cat .vagrant' => {"active":{"default":"a683f28a-4bdc-4739-b7ae-8ae21013dbd5"}}
# VBoxManage controlvm a683f28a-4bdc-4739-b7ae-8ae21013dbd5 poweroff


Run vagrant destroy again:


$ vagrant destroy
[default] Destroying VM and associated drives...


(If it doesn't help, try to remove the VM manually via VBoxManage unregistervm as described in the references.)

References

Vagrant up/halt/ssh Timeouts with "Failed to connect to VM via SSH"

The error might look like this:


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


This likely indicate some problem during booting the machine, often a network setup issue. It might be either a random thing or it might be caused by a mismatch between your VirtualBox version and the installed guest additions. The mismatch would be indicated by this being printed during vagrant up:


[default] Importing base box 'lucid32'...
[default] The guest additions on this VM do not match the install version of
VirtualBox! This may cause things such as forwarded ports, shared
folders, and more to not work properly. If any of those things fail on
this machine, please update the guest additions and repackage the
box.

Guest Additions Version: 4.1.0 VirtualBox Version: 4.1.6


If the wrong version of guest addition is your case then the best solution is either to use vagrant-vbguest to automatically upgrade guest additions or to install the correct version and repackage the box, storing it at some location accessible to all who need it. Alternatively use another base box compatible with your VB version, for example from Vagrantbox.es (though it still might be a good idea to copy it to a place you've control over).

If you believe that the problem is just temporary, you can try to resolve it by following this:
  1. Power off the machine via VBoxManage, as shown above
  2. Tell Vagrant to start the machine in the GUI instead of the headless mode by adding "config.vm.boot_mode = :gui" to your Vagrant file
  3. Run vagrant up and use the VirtualBox UI that should automatically open to log into the virtual machine (user vagrant, psw vagrant) and check its network, SSH status, system logs

Installing Virtual Box Guess Additions

Update: You may try the Vagrant plugin vagrant-vbguest that can install/update VB Guest Additions automatically for you.

The installation is described in the Virtual Box documentation and also, little differently, in Vagrant documentation - Install VirtualBox Guest Additions (no dkms, installs headers).
  1. sudo apt-get update; sudo apt-get install linux-headers-$(uname -r) build-essential (Virtual Box docs use dkms but I believe that it is only useful if you plan upgrading the guest additions regularly)
  2. Mount the VBoxGuestAdditions.iso as a CDrom (OS X: /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso; in Finder right-click on VirtualBox.app and select View package contents; than drag&drop it to the open file dialog of the virtual drive)
  3. Mount it: sudo mount /dev/cdrom /cdrom
  4. Install the additions: cd /cdrom; sudo sh ./VBoxLinuxAdditions.run (This will likely end with "Installing the Windows System drivers …fail! (Could not find the X.Org or Xfree86 Window Sytem.)" but that's OK since we're running a headless system.)
  5. Run sudo apt-get clean  to remove unnecessary files, you may also want to remove some of the packages installed above.

References


Tags: troubleshooting DevOps tool


Copyright © 2024 Jakub Holý
Powered by Cryogen
Theme by KingMob