Mount VirtualBox SharedFolder in Ubuntu VM on boot

52,903

Solution 1

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.

Solution 2

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.

Solution 3

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

Share:
52,903

Related videos on Youtube

wharding28
Author by

wharding28

A 7 year .Net developer looking to expand his horizons and move into the php world. Very excited about jQuery and learning CSS. Working as a freelancer for multiple .Net Development companies.

Updated on September 18, 2022

Comments

  • wharding28
    wharding28 over 1 year

    I have a Ubuntu VM running in VirtualBox.
    I have a Shared Folder set up as myshare I have a folder created in my home directory (~/jamesw) as host. using the line sudo mount -t vboxsf myshare host from my home directory in Terminal mounts the drive correctly, but if I reboot it is not mounted again.

    This is a VM I use for running a simple web server and I would like this Share mounted each time I boot. Is there any way to do this? Especially given that it requires sudo?

  • MestreLion
    MestreLion almost 13 years
    That will make the guest OS to automount a host share, and I believe the OP wants the opposite: to mount a guest share in his host OS. If i'm wrong, than I completely misunderstood the question, and my answer should be ignored
  • wharding28
    wharding28 almost 13 years
    @MestreLion: You are wrong, sorry! I think my problem is that I could never find the Shared drive on the Ubuntu VM because I had no idea it was mounting to /media. Had I realized that this question would not even have been necessary.
  • MestreLion
    MestreLion almost 13 years
    @James: Oh, I'm sorry then. Mounting a host share in a guest OS is easy, and you have several options. Besides the (excellent, btw) answer given here, are you aware that a guest OS can be made seen in the LAN just like a regular machine? Just change network from the default NAT to Bridged. You can now "exchange" shares from guest to host (and vice-versa) using Nautilus, Samba, etc...
  • Takkat
    Takkat almost 13 years
    @MestreLion: to be honest - I mostly share my host (and guest) files by using Samba over the network ;)
  • MestreLion
    MestreLion almost 13 years
    @Takkat: Me too! (and that makes both our answers obsolete! :P)
  • Takkat
    Takkat almost 13 years
    @MestreLion: why not edit your answer for a short howto sharing host windows folders by using samba?
  • Reinier Post
    Reinier Post over 8 years
    See forums.virtualbox.org/viewtopic.php?f=3&t=15868 for how to fix it. Basically, add the mount command in /etc/rc.local or equivalent.
  • Reinier Post
    Reinier Post over 8 years
    Using /etc/fstab doesn't work, see Kenneth Gulbrandsøy's answer.