VM in virtualbox is already locked for a session (or being unlocked)

Solution 1:

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.

Solution 2:

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"

Solution 3:

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