How to access shared folders in Ubuntu VM(Oracle Virtualbox) and link them to the home folder

I have configured a shared folder between the Windows host and Ubuntu guest. The folder mounts at start up but its empty(It also has a padlock sign.). I have to run the command below to access its content(the padlock sign disappears).

  sudo mount.vboxsf media ~/media

How can i configure it to be run automatically at start up. I've tried adding to the start up programs but nothing happens. Am new to Linux so try to put your answer in a layman's language. Thanks.


Solution 1:

The mounted share folder belongs to the vboxsf user. You, as a user, were not added to the vboxsf group. To allow access to the shared folders permanently, copy and paste this command in a Terminal window:

sudo usermod -G vboxsf -a $USER

$USER will be replaced with your username. This command appends the user <username> to the vboxsf group, which is the owner of the shared folders (found in /media/... on the Ubuntu box).

You won't need to run a script at startup once you own the mounted shared folder.

But you will most likely need to logout and on again (or restart).

Solution 2:

So here is how to access your shared folders on Ubuntu VM(Oracle Virtualbox). Am assuming you have already enabled auto-mount while you were adding the folder. Open the terminal and type.

sudo usermod -G vboxsf -a $USER

This command appends the current user to the vboxsf group, which is the owner of the shared folders (found in /media/ on the Ubuntu box). Confirm from your media folder if the shared folders are present. They're usually named "sf_name-of-shared-folder". For quick access, you may want to create a link to the shared folders in the home folder. In Terminal (assuming that you are in the directory where you want the link to appear and that you've enabled the Nautilus plugin that gives you the context menu option ) do:

ln -s /media/sf_shared/ name_of_link.

Replace sf_shared with the actual name of the shared directory and name_of_link with whatever you want. However the name-of-link shouldn't exist in the directory where you want to create the link(That is there should be no folder or file with that name). Alternatively, you can just drag the folder in Nautilus to the right navigation area and it will create an easy to access link.