Had a predicament recently, whereby on my Fedora 12 box i couldnt manage music on my IPhone.

Now i installed VirtualBox, install Windows XP within that, Itunes within that etc etc and mapped the USB Path of the phone through to the Virtual machine. Now, all my music is on my host drives, and not accessible by the virtual machine – unless i want to do it very elementarily and create samba shares (which i dont!).

So, I researched how to share host folders using “VBoxManage” – a tool bundled with VirtualBox. Now, say you have a virtual machine called “x” – and you want to share the folder “/home/Sam/share”, with the share name showing as “HostShare1” on the Windows side, you need to fire open the CLI (NOTE: Dont run as root if you made the VM as your user, UID’s problems) and run the following:

  • [Sam@SMNET ~]$ VBoxManage sharedfolder add x -name HostShare -hostpath /home/Sam/share

Now, lets deconstruct. “VBoxManage” is the program, and it IS case sensitive so bear it in mind.
“sharedfolder” is a parameter of the program which tells it you are about to create a shared folder.
“add x” tells it the ACTION (add) and what virtual machine name you want to action to (“x”).
“-name HostShare” is what the share will be called from the Windows clients perspective, again this is a parameter.
“-hostpath /home/Sam/share” tells the virtualbox program where to map the name “HostShare” to, i.e. /home/Sam/..

  • Once this command is ran, it should pass successfully:
  • [Sam@SMNET ~]$ VBoxManage sharedfolder add x -name HostShare -hostpath /home/Sam/share
  • VirtualBox Command Line Management Interface Version 3.1.0
  • (C) 2005-2009 Sun Microsystems, Inc.
  • All rights reserved.
  • [Sam@SMNET ~]$

However, if it does not you may need to re-read the notes. For example, if you get the message like below:

  • [Sam@SMNET ~]$ VBoxManage sharedfolder add x -name Media2 -hostpath /media/Other\ Media/
  • VirtualBox Command Line Management Interface Version 3.1.0
  • (C) 2005-2009 Sun Microsystems, Inc.
  • All rights reserved.
  • ERROR: A session for the machine ‘x’ is currently open (or being closed)
  • Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component Machine, interface IMachine, callee nsISupports
  • Context: “OpenSession(a->session, uuid)” at line 750 of file VBoxManageMisc.cpp

The above means the virtual machine is not powered off when you ran the command, which it needs to be. Also, if you get the message “command not found” you will need to ensure you have the case sensitive, i.e. Capital VB etc.

Now, we have configured the Linux side successfully, time for the easy bit. Turn on the VM, and go to “Start” and then “Run..”. In there, type “\\vboxsrv\HostShare” – and hit enter. And voila, you shared folder will appear. Now, to deconstruct again. “\\vboxsrv” is a preset parameter which tells the virtual machine the shared folder is stored on the host PC/Server (Your Linux install in this case). The “\HostShare” should look familiar as that is the name we set in our “…add x -name HostShare….” command.

Now, go forth and share!

Sam.