Have tested these instructions successfully under an Ubuntu 16.04LTS guest with a VirtualBox 5.1 and 5.2 host.
-
Create Ubuntu server instance under VirtualBox (obviously).
-
Start VM, goto Devices - Insert Guest Additions CD image to mount the ISO image.
-
From the terminal, run the following commands:
$ sudo su $ apt install gcc make $ mkdir --parents /media/cdrom $ mount /dev/cdrom /media/cdrom $ /media/cdrom/VBoxLinuxAdditions.run $ reboot
-
After reboot:
$ sudo usermod --append --groups vboxsf USERNAME
-
Host shares should now be mounted in Ubuntu guest under
/mediavia the installedVBoxServiceservice, set to start on system boot-up. -
All done.
By default with auto mounted shares, VirtualBox will set an interesting set of ownership and file/directory permissions for the guest which (for me) is sub-optimal. To correct this behavior and mirror permissions between host and guest we can do the following:
-
Shut down the guest (if not already) and ensure "Auto-mount" is disabled.
-
Restart the guest.
-
From the shell, determine the
umaskanduid/gidof your host user.$ umask 0022 $ id uid=1000(USERNAME) gid=1000(USERNAME) groups=1000(USERNAME),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),110(lxd),115(lpadmin),116(sambashare) -
Now mount the share as follows:
$ mkdir --parents /path/to/share $ sudo mount.vboxsf -o umask=UMASK,uid=UID,gid=GID SHARE_NAME /path/to/share
-
If all is good, we can now add an entry to our
/etc/fstab:SHARE_NAME /path/to/share vboxsf umask=UMASK,uid=UID,gid=GID 0 0 -
And remount all file systems
$ sudo mount -a
-
All done.