Oh, Virtualbox.....

So, Virtualbox, a (somewhat) crucial piece of software for us developers that allows us to spin up virtual machines to develop on locally. Virtualbox has a feature known as "Shared Folders" which basically in laymens terms is a "Symlink" to a mounted folder on the VM, which works great, when it works of course...


So, how do we get it to work? Well then..

sudo mount -t vboxsf FOLDER-ON-VM -o rw,dmode=777,gid=GROUP-ID,uid=USER-ID /path/to/folder/to/share

Lets start by breaking down the command:

sudo mount -t vboxsf FOLDER-ON-VM

This is telling the mount command what types you want, in our case we want the vboxsf user and our folder to "link" to, so Virtualbox can see that folder.

The next part of the command is our options:

-o rw,dmode=777,gid=GROUP-ID,uid=USER-ID

These Specify how we want to mount our folder, here, we are mounting with "rw" so it has full read/write access, "dmode=777" sets the directory permissions to 777 (as its a local VM with likely a Host only adapter, 777 will be fine), and the last two, "gid=GROUP-ID,uid=USER-ID" allows us to specify a group and user who has ownership of the folder, i set these to www-data's Group ID for the gid and my user's ID for the uid.

This part is self explanatory, this is the folder you want to have as the shared folder:

/path/to/folder/to/share

this folder then becomes the folder all your Shared folder's contents are uploaded to, and then as it is also symlinked to the main folder all its contents end up there too, yes, samba shares are a (probably) easier way of doing this on windows but hey Oracle give us a native way to do this (via the Guest Additions ISO which adds the shared folder capability so this can work) so might as well use that eh?


Things to note:

  • You do need Guest Additions Installed on your guest OS for this to work properly

  • You will need to manually make the directory for the mount location

  • You also need to add your user to the vboxsf group so there are no weird permission problems