Can VirtualBox VBoxManage add/remove shared folders on the fly?

docker-machine, virtualbox

Solution

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.

Problem

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`.

Original source