Ubuntu – How to access a shared folder in VirtualBox

shared-foldersvirtualbox

I followed the steps for sharing folders between Windows 7 and Ubuntu in VirtualBox.

Despite that the folder appears with a X sign and gives me the following message when a try to open it:

The folder content could not be displayed

When I choose Shared Folder from the VirtualBox Device menu, the following warning is displayed:

On the system page, you have assigned more than 50% of your computer's memory (2.93 GB) to the virtual machine…

How can I successfully share folders between Windows and Ubuntu using VirtualBox?

Best Answer

Access to shared folders in Virtual Box

Command line

By default, VirtualBox shared folders are created with read/write permission for the guest. This can be done from the command line on the host with:

VBoxManage sharedfolder add "VM name" --name sharename --hostpath "C:\test"

By adding the option --readonly we can restrict these for read-only access. Use the --transient option if you only want the shares to appear in the present session but not persistent for following sessions. There are some limitations for shared folders (see this question for details). If prerequisites are met we may mount these shared folders manually by running the following commands in the guest:

mkdir /home/<user>/vboxshare
sudo mount -t vboxsf -o uid=1000,gid=1000 sharename /home/<user>/vboxshare  

Of course, we can also use different mount options to mount as read/only or mount with read access only to root.

Auto-Mount through Virtual Box Manager

In case we enabled auto-mounting on creating a shared folder from the Virtual Box Manager those shared folders will automatically be mounted in the guest with mount point /media/sf_<name_of_folder>. To have access to these folders users in the guest need to be a member of the group vboxsf.

sudo usermod -aG vboxsf userName

The guest will need to restart to have the new group added.

Source and further reading: Virtual Box User Manual

Related Question