4

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.

  • possible duplicate of How to mount a VirtualBox shared folder at startup? – Takkat Dec 19 '14 at 7:31
  • @Takkat I can mount the shared folder just fine. That is not the issue. I want to change the mount point (or any other solution that allows me to develop on my host machine and have the changes appear in /srv in my vm). – smilebomb Dec 19 '14 at 14:45
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.

  • 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
2

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.

/media/3tb-vol1/Private/ /srv/Private none bind

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...?

  • And what would I be looking for in fstab? – smilebomb Dec 18 '14 at 21:13
  • /media/sf_share, that's what you want to change right? – Xen2050 Dec 18 '14 at 21:38
  • 1
    That does not appear is fstab. I tried mount --bind /media/sf_share /srv and that appears to be working. – smilebomb Dec 18 '14 at 21:43
  • Well, after a reboot all the contents were lost from /srv – smilebomb Dec 18 '14 at 21:55
  • a terminal mount would only be in effect until a reboot. Maybe add it to /etc/fstab if it exists at bootup, or to a login script or a one-liner script file (to run when needed) if it's not there until later – Xen2050 Dec 18 '14 at 22:01
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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.