Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mount VirtualBox shared folder on boot using fstab

How to mount a VirtualBox shared folder when the Guest OS boots

Problem

While using VirtualBox's Guest Additions to mount shared folders provides a seamless way to mount shared folders, there are also disadvantages.

  • Shared folders will always mount in /media/sf_(share name) unless specified using through vbox drivers in the guest OS
  • Mounting does not happen at boot-time. Applications that require paths at boot will not be able to access the shared folder even after it is mounted - such as Docker.

Solution

Instead of relying on Guest Additions, if you have sudo permissions, shared folders can be mounted at boot-time using fstab. Using this approach allows

  • Mounting shared folders to specific paths other than /media/sf_(share name)
  • Shared folders are guaranteed to be mounted at boot time.

However, it is important that the shared folder must exist on the Host OS or else the Guest OS will fail to boot.

Instructions

These steps were adapted from http://jhshi.me/2016/07/12/mounting-virtualbox-shared-folder-on-boot/index.html.

First, find out your numerical uid and gid by performing the following shell commands.

$ echo $UID
1000
$ echo $GID
1000

Here, my UID is 1000 and GID is 1000. This is necessary in order to give you read and write permissions when you mount the shared folder.

Let's assume you want to mount a shared folder with a share name you specified in VirtualBox as vb_shared to /home/kent/shared. Make sure that that path exists and create the directories if it isn't.

Now, open fstab and edit. Here I use nano.

$ sudo nano /etc/fstab

Edit text marked by () by removing the () and using your own values and append the following at the end of fstab.

(vb_shared)    (/home/kent/shared)    vboxsf    defaults,uid=(1000),gid=(1000),umask=0022    0    0

This line will mount your shared folder named vb_shared to mount to the path (that exists) /home/kent/shared. Once mounted, user with uid 1000 belong to group with gid 1000 will have read and write access through umask=0022.

If you have more than one shared folder, add one line for each shared folder you want to mount.

Now save the edited fstab.

Lastly, edit /etc/module to add vboxsf so that it is present at boot-time.

$ sudo nano /etc/modules

Append the following line and save.

vboxsf

Restart and the shared folder/s should now be mounted at the specified path/s.

@thinkjrs

This comment has been minimized.

Copy link

thinkjrs commented Dec 5, 2017

Thanks for the Gist, this was super helpful/quick/concise!

@AlexanderFadeev

This comment has been minimized.

Copy link

AlexanderFadeev commented Dec 22, 2017

echo $GID was returning empty line, so it's better to use id -g

@wyattbiker

This comment has been minimized.

Copy link

wyattbiker commented Mar 8, 2019

defaults,uid=(1000),gid=(1000) fails on my Linuxmint 19.1

Here is example that works for me:
/shared /home/standing/Documents/SharedOSX vboxsf defaults,uid=1000,gid=1000,rw 0 0

And yes $GID is empty. Just type id to get both uid and gid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.