Virtual box 中的 VM 已经锁定了一个会话(或正在解锁)

我的虚拟机在虚拟机不能启动由于这个错误,我不想破坏它和重新安装它,无论如何恢复呢?

执行 VBoxManage(Vagrant 使用的 CLI)时出错 命令和 stderr 如下所示。

Command: ["modifyvm", "319fcce3-e8ff-4b6f-a641-3aee1df6543f", "--natpf1", "delete", "ssh"]


Stderr: VBoxManage: error: The machine 'centos64_c6402_1454036461345_59755' is already locked for a session (or being unlocked)
VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports
VBoxManage: error: Context: "LockMachine(a->session, LockType_Write)" at line 493 of file VBoxManageModifyVM.cpp
101380 次浏览

Having the same issue I found that there was a process running actually locking the vm:

501 79419 79323   0  2:18PM ??         0:39.75 /Applications/VirtualBox.app/Contents/MacOS/VBoxHeadless --comment default --startvm 1d438a2e-68d7-4ba2-bef9-4ea162913c1b --vrde config

Make sure you don't have a process stuck trying to start the vm:

ps -ef | grep -i "vbox"

I've encounter the same error message today:

>me@myhost:~$ ps -ef | grep -i "vbox"


me  3064     1  0 08:51 ?        00:00:00 /usr/lib/virtualbox/VBoxXPCOMIPCD


me  3089     1  0 08:51 ?        00:00:00 /usr/lib/virtualbox/VBoxSVC --auto-shutdown


me  3126  3089 27 08:51 ?        00:00:39 /usr/lib/virtualbox/VBoxHeadless --comment RHEL5 64-bit desktop --startvm e5c598d8-1234-4003-a7c1-b9d8af15dfe7 --vrde config


me  3861  3415  0 08:53 pts/1    00:00:00 grep --color=auto -i vbox*

Gergely's answer solves it perfectly. It turned out that I've a crontab set at reboot to boot the virtual machine, which initiated the three VBox process shown above

me@myhost:~$ crontab -l


@reboot me /usr/bin/vboxmanage startvm "RHEL5 64-bit desktop" --type headless

Running this on the command line unlocked the VM:

vboxmanage startvm <vm-uuid> --type emergencystop

Where <vm-uuid> is the number in the error message: Command: ["modifyvm", "<vm-uuid>" [...]. After that I was able to control the VM (start, halt, etc). Using Virtualbox 4.1 on Ubuntu.

In Windows Task Manager, I ended any tasks related to Virtual Box (you can see they start with a V in Task Manager like Vbox Headless.exe, etc). Once I did that, I was able to get this error to go away (the above 'vboxmanage startvm ...etc...' solutions here did not work for me).

The only option that worked for me was to kill all the processes matching ps axl|grep -i vbox.

If you have a settings window open for that box in the VirtualBox GUI, you may run into this error. Just close the settings window and try again.

For me I had to kill the VboxHeadless.exe process in task manager. I also had to ensure CMD prompt was opened in Administrative mode.

I found this answer from @Gonzalez very interesting.

vboxmanage startvm <vm-uuid> --type emergencystop

The only problem with that it shut down the current instance of my VM, so instead of using modifyvm you can use controlvm if the current vm is running.

For example:

 VBoxManage modifyvm <vm_name> --natpf1 "guestssh,tcp,,22,,2222"
VBoxManage modifyvm <vm_name> --natpf1 delete "guestssh"

Become:

VBoxManage controlvm <vm_name> natpf1 "guestssh,tcp,,22,,2222"
VBoxManage controlvm <vm_name> natpf1 delete "guestssh"

Full documentation Here https://www.virtualbox.org/manual/ch08.html#vboxmanage-controlvm

sudo pkill -9 VBox kills everything running related to vbox

In my case, the apparent cause was a USB ethernet adapter that had been removed after suspending the machine. In my case,

vboxmanage startvm <vm-uuid> --type emergencystop

did not help. Instead, I received the confusing message that

VBoxManage: error: The machine 'xyzzy' is not locked by a session

The true error was revealed by running

vboxmanage startvm <vm-uuid> --type gui

which returned

VBoxManage: error: Nonexistent host networking interface, name 'en9: USBPlug' (VERR_INTERNAL_ERROR)

Changing the network configuration to a different network adapter solved the issue.

This is because You reallocated the memory set for Virtual Box
What you have to do to fix is: Restart The PC