How to mount a VirtualBox shared folder when the Guest OS boots
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.
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.
These steps were adapted from http://jhshi.me/2016/07/12/mounting-virtualbox-shared-folder-on-boot/index.html.
First, find out your numerical
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.
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
(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
If you have more than one shared folder, add one line for each shared folder you want to mount.
Now save the edited
/etc/module to add
vboxsf so that it is present at boot-time.
$ sudo nano /etc/modules
Append the following line and save.
Restart and the shared folder/s should now be mounted at the specified path/s.