Ubuntu – Sharing between Host and Guest in Virtualbox


Since Ubuntu 11.10 use a new kernel, it's very difficult to have a decent support for virtualization.

VirtualBox doesn't support guest additions for ubuntu 11.10, so I can't copy to and from my ubuntu desktop and windows, which I absolutely require, plus FreeBSD seems not to be able to use DHCP without guest additions.

Virt-manager instead gives an error on launch:

Unable to open a connection to the libvirt management daemon.

Libvirt URI is: qemu:///system

Verify that:
 - The 'libvirt-bin' package is installed
 - The 'libvirtd' daemon has been started
 - You are member of the 'libvirtd' group

unable to connect to '/var/run/libvirt/libvirt-sock', libvirtd may need to be started: Permission denied

Traceback (most recent call last):
  File "/usr/share/virt-manager/virtManager/connection.py", line 1146, in _open_thread
    self.vmm = self._try_open()
  File "/usr/share/virt-manager/virtManager/connection.py", line 1130, in _try_open
  File "/usr/lib/python2.7/dist-packages/libvirt.py", line 102, in openAuth
    if ret is None:raise libvirtError('virConnectOpenAuth() failed')
libvirtError: unable to connect to '/var/run/libvirt/libvirt-sock', libvirtd may need to be started: Permission denied

The problem is solved by running virt-manager as root, but I don't like that. How do I change permissions to run Virt-Manager as user?

Is there a way to install guest additions on Ubuntu 11.10?

Best Answer

The solution although a little bit confusing is this:

Ubuntu Guest with Ubuntu Host

After installing the Guest Ubuntu:

  1. Load the Guest Addition ISO from the Virtualbox Menu

    enter image description here

  2. In the guest Ubuntu open a terminal and install some essential files for the Guest Addition to install correctly:

    sudo apt-get install dkms build-essential linux-headers-generic in my case of 32Bit

  3. Run the Linux Guest Addition installer in the Guest Ubuntu. Open the terminal, cd yourself to the mounted image (In my case is cd /media/cyrex/VBOXADDITIONS_4.1.6_74713). In your case you need to input cd /media/USER/VBOXADDITIONS_VIRTUALBOX_VERSION where USER is your username and VIRTUALBOX_VERSION is the current version you are installing. After that run the Guest Addition:

    sudo ./VBoxLinuxAdditions.run (It is in the root directory of the ISO image)

    enter image description here

  4. Since you installed the needed packages in step 2, you should be fine after installing the Linux Addition since it will configure with no problems. Say yes to a question or two it might ask but this will not do you harm since it will be checking to see if you have the guest addition installed already. Reboot after finishing the install.

  5. Now when the guest starts again you should see that you have several new options available like input devices, views, etc.. but the one you are needing is SHARE FOLDERS!!. To share a folder you already know that is done from the Virtualbox Menu.

    enter image description here

  6. But what we need is to connect to this Shared folder from the Host. To do this first create a folder in the guest which will link to the shared folder from the host. For example lets create in the guest home folder the directory virtual. Now assuming the shared host folder is also called virtual we would set this up in the guest like this:

    sudo mount -t vboxsf virtual ~/virtual

    Now you can access the shared folder.


  • The name of the shared host folder must be the same as the guest folder. In the example mentioned above you have both named virtual, but it could be both named bck, shared, virtualbox, etc... This will solve several "protocol" errors.

  • Since mounted shares have by default root as owner, to mount them as YOU, you can do for example:

    sudo mount -t vboxsf -o uid=1000, gid=1000 virtual ~/virtual when mounting them

  • To automount a share folder add it to /etc/fstab. This way when you load the guest it will have the shared folder already mounted.

  • If (JUST IF!!) you by change have a editing/saving problem directly in the shared folder. Just copy over the file to another place. Edit the file, save it, copy over back to the shared folder, replacing the one in there.

  • If the 3D Acceleration support was not enabled when you did the virtualbox setup. Do not worry just run the guest addition again after activating it as seen here:

enter image description here

  • You can also do the Guest Addition setup from the Proprietary Driver Manager. That is, jockey-gtk As seen in this picture (This is the same as Step 2)

enter image description here

After all of this you should have a Virtualbox that shares folders with the host and back and has 3D acceleration. Here is an image of the outcome:

enter image description here

Windows Guest with Ubuntu Host

If you are using Windows Vista and up, by simply installing the Guest Addition, Sharing the folder (The same procedure as in the Ubuntu example) and rebooting the Windows Guest session you will automatically see the Shared folder between both systems.

If you are using Windows XP, 2000 or 2003 you can use the answer shown in: How do I set up shared folders in a Windows XP virtualbox guest?

To do the sharing via a command line, Takkat has a nice tutorial in How to access a shared folder in VirtualBox? and in How do I set up shared folders in a Windows XP virtualbox guest?

To understand how the network works inside a virtual environment (in this particular case) see Wireless Network in Virtualbox