Question

Every time a Vagrant box fails to install, it leaves some mess behind in VirtualBox. Forwarded ports that were set up in the Vagrantfile do not get cleaned up. vagrant halt does not work because the box is not up, and vagrant destroy sometimes work, depending on how far the installation of a box went before hanging.

So every time I test a new setup, vagrant says that the port to be forwarded is already in use. I need to change the port to forward, and then the install continues, only to hang at a later point and take the port hostage into oblivion. Now I don't have any ports that I can use (that are accessible remotely), so I just want to quit having those ports constipated.

I could probably fix this with a reboot, but the machine cannot be rebooted right now.

Issuing the "just delete the damn thing" command does not work:

$ VBoxManage list vms
"<inaccessible>" {aaaa-aa-aa-aa-aaaa}
"<inaccessible>" {bbbb-bb-bb-bb-bbbb}
"vagrant_default_cccc_cc" {cccc-cc-cc-cc-cccc}
$ VBoxManage unregistervm aaaa-aa-aa-aa-aaaa --delete
VBoxManage: error: The object is not ready
VBoxManage: error: Details: code E_ACCESSDENIED (0x80070005), component Machine, interface IMachine, callee nsISupports
VBoxManage: error: Context: "Delete(ComSafeArrayAsInParam(aMedia), pProgress.asOutParam())" at line 165 of file VBoxManageMisc.cpp
$ VBoxManage unregistervm bbbb-bb-bb-bb-bbbb --delete
VBoxManage: error: The object is not ready
VBoxManage: error: Details: code E_ACCESSDENIED (0x80070005), component Machine, interface IMachine, callee nsISupports
VBoxManage: error: Context: "Delete(ComSafeArrayAsInParam(aMedia), pProgress.asOutParam())" at line 165 of file VBoxManageMisc.cpp
$ VBoxManage unregistervm cccc-cc-cc-cc-cccc --delete
VBoxManage: error: Cannot unregister the machine 'vagrant_default_cccc_cc' while it is locked VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component Machine, interface IMachine, callee nsISupports
VBoxManage: error: Context: "Unregister(fDelete ? (CleanupMode_T)CleanupMode_DetachAllReturnHardDisksOnly : (CleanupMode_T)CleanupMode_DetachAllReturnNone, ComSafeArrayAsOutParam(aMedia))" at line 160 of file VBoxManageMisc.cpp
$

(Nope, sudo doesn't do the trick either.)

How can I totally eradicate and destroy the machines as easily as possible without having to reboot? Or, at least (or better) stop VirtualBox from keeping port forwards to broken boxes? I probably should not remove and -rf just everything because there are also some boxes that run fine.

The server running Vagrant and VirtualBox runs on Ubuntu 13.10. The guest, although probably irrelevant, tries to run Ubuntu 12.10.

Was it helpful?

Solution

$ ps axu|grep VBoxHeadless
jamie     4205  0.3  1.2 1592676 208592 ?      Sl   Apr10   7:08 /usr/lib/virtualbox/VBoxHeadless --comment apt-cacher_default_1396256757 --startvm a8c2157a-f86f-491d-a703-74e49b4348fb --vrde config
jamie    11390 48.7  1.4 2823080 231788 ?      Sl   Apr10 845:49 /usr/lib/virtualbox/VBoxHeadless --comment vandeliverytest_default_1397122355 --startvm a06a0a8c-a645-4270-89f4-992566e111f0 --vrde config
jamie    22226  0.0  0.0  13596   936 pts/3    S+   16:31   0:00 grep --color=auto VBoxHeadless

The "startvm" ones are the processes that hang around and can't be stopped with normal vagrant commands. issue a kill -TERM command to the processes and they should stop If that doesn't work escalate to a kill -KILL

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top