当我尝试销毁一个 Kitchen 实例时,Virtualbox 被锁定了。

8
我运行了一个test-kitchen实例,一切都很好,但最后当我尝试使用"destroy"命令销毁它时,出现了问题:
roberto@pc:~$ kitchen destroy

虚拟机出现了这个错误。
-----> Starting Kitchen (v1.1.1)
-----> Destroying <default-ubuntu-1204>...
       [default] Destroying VM and associated drives...
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: Failed to complete #destroy action: [Expected process to exit with [0], but received '1'
---- Begin output of vagrant destroy -f ----
STDOUT: [default] Destroying VM and associated drives...
STDERR: There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["unregistervm", "2507bc77-3734-429b-a573-d92fadb80e95", "--delete"]

Stderr: VBoxManage: error: Cannot unregister the machine 'default-ubuntu-1204_default_1391521776' while it is locked
VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component Machine, interface IMachine, callee nsISupports
VBoxManage: error: Context: "Unregister(CleanupMode_DetachAllReturnHardDisksOnly, ComSafeArrayAsOutParam(aMedia))" at line 158 of file VBoxManageMisc.cpp
---- End output of vagrant destroy -f ----
Ran vagrant destroy -f returned 1]
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details

我运行了Virtualbox,但无法删除该实例,因为它也被锁定,关闭选项也被禁用。

还有其他人遇到这个问题吗?


2个回答

5

因为虚拟机是被占用的,所以您需要先关闭它,例如:

VBoxManage controlvm VMNAME poweroff

将代码中的 VMNAME 替换为您的机器名称,例如 default-ubuntu-1204_default_1391521776
然后,您可以通过以下方式注销:
VBoxManage unregistervm VMNAME --delete

指定--delete将删除您的虚拟机。如果您不想删除它,可以从~/"VirtualBox VMs/VMNAME进行备份。


如果您将此放入shell脚本中,则需要在“poweroff”和“unregistervm”命令之间添加轻微的延迟...如果不这样做,则注销仍将失败并显示“已锁定”错误。我在两个命令之间添加了“sleep 2”,它可以正常工作。 - JD Allen

1

这个问题可能有两个原因,请确保:

  1. 在安装/更新VirtualBox后重新启动计算机
  2. 在使用驱动程序之前,请确保手动至少打开一次VirtualBox

如果该机器出现在VBox GUI的虚拟机列表中,请再次尝试命令。如果它们未在VirtualBox GUI中列出,请删除 .kitchen 目录并重试。


7
以下是对我有用的命令:
  1. VBoxManage startvm VMNAME/id --type emergencystop
  2. VBoxManage unregistervm VMNAME --delete
- chinmay

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接