问题
When I am trying to add/remove shared folder to my VirtualBox I am getting this error:
~$ VBoxManage sharedfolder add dev --name srv --hostpath "/my/local/path"
VBoxManage: error: The machine 'dev' 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 1012 of file VBoxManageMisc.cpp
It works when I stop the machine, manipulate shares and then start the machine again. It also works from the VirtualBox UI but I would like to script these operations.
Running VirtualBox 5.0.12 on Mac OS Yosemite. The box was provisioned with docker-machine
.
回答1:
As noted by 'socratis' at Virtual Box Forum, the way to do this is by using the --transient
flag:
~$ VBoxManage sharedfolder add dev --name srv --hostpath "/my/local/path" --transient
When using --transient
, the mapping will not persist over the VM restart.
The VirtualBox documentation mentions this as well:
There are two types of shares:
VM shares which are only available to the VM for which they have been defined; transient VM shares, which can be added and removed at runtime and do not persist after a VM has stopped; for these, add the --transient option to the above command line.
回答2:
Yes, You can add shared folder with VboxManage command but this changes are not permanent
Note: To enable folder sharing with vBOX you will have to install install Vbox-guest driver on your guest machine, then only you can share hosts folder inside your guest vm
来源:https://stackoverflow.com/questions/34489942/can-virtualbox-vboxmanage-add-remove-shared-folders-on-the-fly