Mount VirtualBox SharedFolder in Ubuntu VM on boot

Auto-mount shared folders using Virtual Box Manager

From Virtual Box > 4.0 we are able to auto mount shared folders in a virtual machine. To do so for Ubuntu we

  • need to install Guest Additions in the guest OS
  • make sure users are in group vboxsf
  • define shared folders from the Virtual Box Manager

Right click on your virtual machine and choose Settings->Shared Folders. This will list existing shares or lets you define a new shared folde by clicking on the blue folder icon with the green +-sign on the top right side:

enter image description here

Choose your folder from the dropdown menu Folder path or choose Define other for a file selector that lists the host filesystem. Choose a name for the share (e.g. myshares). By ticking Auto-mount this folder will always be mounted in the Ubuntu guest directory /media/sf_myshares (the prefix sf_ will automatically be added).


Alternatively, to define shared folders in a running guest OS we may select Devices -> Shared Folders from the window menu of Virtual Box Manager:

enter image description here

By ticking Make Permanent these shared folders will also be available on the next boot and will be mounted when Auto-mount is ticked in addition.


I don't think use of /etc/fstab will work (it didn't work for me) because that file is processed before the SF module is loaded and will fail to mount the share, see HOWTO: Use Shared Folders 1.


This is not a complete answer yet, but more like guidelines on 2 approaches you have:

1 - You could edit /etc/fstab and add this mount there. You would need to translate your mount parameter to fstab syntax. A wild guess would be something like /home/jamesw/host vboxsf myshare,umask=002,uid=<youruser>,gid=plugdev 0 0. You would need sudoto edit your fstab, but, once done, it will be auto-mounted on boot. Since this is done before you even log in, you need an absolute path to the mount point (hence /home/jamesw/host), you can not use $HOME or ~. Hint: "host" folder don't need to exist. If it is in fstab, mount will create it for you.

2 - You could use fusermount instead of mount. The syntax is similar (but not identical, so you still need to translate the mount parameters). Fusermount requires your mount point to be somewhere inside your $HOME, but the biggest advantage is that you would not need sudo. And the mount will be avaliable in Nautilus (as if it was a CD or USB key). After you get the right parameters and test it, you can add it to your ~/.profile, which runs every time you log in.

EDIT: Im assuming that either Virtualbox dont need the machine to be actually runing for it to share folders, OR that it is up and running before you log in