5

I have a shared folder set up between virtualbox and my windows 7 host machine. I have a test.txt file that I created in Windows and it shows up appropriately in my Ubuntu VM. Virtualbox mounts the shared folder in /media/sf_share (the name I gave to the shared folder in the virtualbox settings was share). I want to move the mount point from /media/sf_share to simply /srv so that on my windows host I can edit files and they show up under /srv. How can I accomplish this?

**

What I've tried:

**

I've edited /etc/fstab to look like this:

share /srv vboxsf defaults 0 0

After doing this I used the command mount -a, also I rebooted, and I rebooted again with the virtualbox shared folder settings to NOT auto-mount.

I read there is an issue with filesystems being mounted before virtualbox utilities are loaded, so I added vboxsf to my /etc/modules and then repeated the steps above.

None of them reproduce the correct content in /srv. When I issue mount -a AFTER I have edited the fstab I can sometimes get it to work. I don't know what I'm doing differently each time, but sometimes after I edit fstab, issue mount -a without rebooting I can see the files there. After a reboot though the files are gone again.

smilebomb
  • 153

3 Answers3

7

You have to change the "Guest properties" to modify the mount prefix and base directory used for the shared folders.

See https://www.virtualbox.org/manual/ch04.html#sf_mount_auto
and https://www.virtualbox.org/manual/ch04.html#guestadd-guestprops

An important note, though:
Both properties detailed in the first link have default values when not set or cleared:
/VirtualBox/GuestAdd/SharedFolders/MountPrefix defaults to sf_ if not set.
Set /VirtualBox/GuestAdd/SharedFolders/MountDir defaults to /media if not set

As a consequence, you have to set MountPrefix to / if you do not want the sf_ prefix, as trying to set it to "" will in fact clear the property and put it back to its default value.

Nawak
  • 71
  • I was going crazy trying to figure out how to set MountPrefix to an empty value, setting it to / did the trick, thanks! – Mahn Jul 11 '16 at 17:15
3

Check /etc/fstab? I'm not too sure how virtualbox shares, so if changing the mount point breaks the sharing, you could change it back & bind mount /media/sf_share to /srv

Info on bind mounting & fstab:

https://serverfault.com/questions/613179/how-do-i-do-mount-bind-in-etc-fstab

If I had a volume mounted at /media/3tb-vol1/Private/, and I wanted to bind it to /srv/Private I have a /etc/fstab like this.

<p><code>/media/3tb-vol1/Private/ /srv/Private        none    bind</code></p>

Of course, I don't know the details of VirtualBox's sharing. I'm not sure how & when /media/sf_share gets mounted, if it's not ready when fstab is, it might not be mounted in time to be bound...?

Xen2050
  • 8,705
1

Based on Nawak's answer, I finally managed to get it done. I had already tried so many solutions (based on /etc/fstab/ and setting some /etc/rc.local) but this one was the one that worked.

I just ran the following commands (from the host machine):

VBoxManage guestproperty set "Ubuntu 16" /VirtualBox/GuestAdd/SharedFolders/MountPrefix /
VBoxManage guestproperty set "Ubuntu 16" /VirtualBox/GuestAdd/SharedFolders/MountDir srv

Where Ubuntu 16 is the name of my VM. In order to check that these properyies where applied properly, you can run:

VBoxManage guestproperty enumerate "Ubuntu 16"
vabada
  • 291