Sasha O
Sasha O

Reputation: 3749

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

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.

Upvotes: 2

Views: 7633

Answers (2)

Nilesh Attarde
Nilesh Attarde

Reputation: 64

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

Upvotes: 1

Sasha O
Sasha O

Reputation: 3749

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.

Upvotes: 6

Related Questions