[SOLVED] Am I missing something? Mounting VirtualBox shares
Linux - Virtualization and CloudThis forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Am I missing something? Mounting VirtualBox shares
It seems that the only reliable way for me to mount a share in VirtualBox is to specify this in the external user-interface. But, if I do that, the share is always mounted as root/vboxsf.
I need to specify that I want the share to be mounted as someone else and to have a "755" security mask.
Attempting to do this in, say, /etc/rc.local are unsuccessful apparently due to timing problems.
I've put an entry in /etc/fstab although it is not "auto."
How does the mechanism in the VirtualBox user-interface actually work? It seems to be the only way to reliably mount the share at startup, but it seems to give me no control.
I set up two shares at the top level when setting up the vm
1. /home/my_luser/Electronics
2. /mnt
On Slackware, the second one was sly, because usb sticks and my sdcard reader are mounted under /mnt in /etc/fstab. Both appear in Vista as separate drives.Only new automounts in X go under /run/media.
Irrespective of where the shares mount, the problem seems to be ensuring that they are mounted at the time that a particular service -- Apache2 -- needs to use them. [i](This is an eleven-year old application that is finally getting a makeover. Think, "two gigabytes of RewriteMaps." And yet, it completes thousands of dollars' worth of business every day and hosts more than 150 sites.)
If I let VBox do it ... and I don't know how it does it, yet ... the shares appear to be there (or maybe they aren't yet). If I mount them in /etc/rc.local, they don't actually mount atboot, although the same script, if issued afterwards, works. (So, the commands are correct but the timing is wrong.)
I think(!) that "I would be a very happy boy, if ..." I could actually specify how VBox mounts those shares (itself), and it stands to reason that I should, if only I better understood how their mechanism works!
I've read many posts, some tantalizingly marked as [SOLVED], but I need to proceed with great caution here so that I don't accidentally "brick" the VM. Some folks have suggested, for instance, "put the vboxsf module into /etc/modules so that it loads very early." Well, that could very easily be a "brick" if it doesn't work. I'd be scro-o-o-ood for a good, long time that I don't have.
Since system-start is "a very asynchronous time," I'm not sure that trying to put the Apache process into the vboxsf group would even work, assuming I could figure out how to do it, if it actually is a timing issue.
Tf you want to have it mount automatically upon each boot, put the mount command in /etc/rc.local (Debian based distro's), or whatever script is run at the end of the boot process. The Shared Folders service should mount them automatically, but that doesn't always happen.
Using /etc/fstab has little effect, because that file is processed before the SF module is loaded and will fail to mount the share. Sometimes, the share does get mounted because the GA ["what's GA ??"] check for it when they are loaded upon boot, but it's very flaky, meaning it doesn't work most of the time. You're better of with the first option.
Words like "very flaky" or "doesn't always happen" do not make me feel comfy.
I could arrange things to circumvent startup timing problems if I could control the permissions and/or the ownership of the shares! There must be some Linux-side code in play here ... but, where did Oracle Corporation put it?
This topic seems very detailed and complete, but it was written in 2007 or so, and has the caveat that others said it didn't work anymore. And, again, I really don't want to stray too far into hacker-land on this.
Last edited by sundialsvcs; 02-18-2016 at 06:28 AM.
Okay, I'm gonna mark this thread as [SOLVED] with the following simple recommendation:
If you want shares mounted, specify the shares in the VirtualBox user interface. They will (somehow ...) be mounted (by VirtualBox 5.0.14 for OS/X) in time for startup services such as Apache to access them.
To make it possible for Apache to do this, first observe what user-id Apache runs its daemons in (as defined in the Apache configuration file, or by a simple peek at ps -A outuput ...), and add this user-id to the vboxsf group.
For instance: groups www_user ... (to see what the group-list now is) usermod www_user -a -G vboxsf ... (to add the group-id to this user) groups www_user ... (to see if it worked!)
Do not forget the -a parameter, since you want to add to, rather than replace, the user's groups-list.)
(Or use your favorite GUI tool if you're a "weenie ..." )
Seriously... "it works, and it seems to work quite reliably."
Note(!) that you do not have to worry about the Group directive in the Apache configuration file! It doesn't matter "which gid = group_id the Apache daemons run under while they are executing." What matters is the "listof groups that this user (the User directive ...) belongs to."
Obviously, this uid should not be nobody, but Apache (for obvious reasons related to "real" file-access) doesn't use that user-id anyway. Add the daemon-userid to the group, and everything else seems to come out in the wash.
In light of this, it now seems someone's very-deliberate choice that the permissions-mask for the share is rwxrwx--- root vboxsf ... which seems to be pointing very-directly to "group membership" as being the only way, by design, to specify who is to have access to the share and who is not.
Yeah, sure, probably "a very well thought-out solution." Gee ... they could have "written a few paragraphs to that effect ... mmm?"
Last edited by sundialsvcs; 02-18-2016 at 06:41 PM.
I've been trying to solve this problem for two days now and just found this post, but I don't fully understand your solution (which I'm grateful for, btw).
questions:
1) what do you mean by 'specify the shares in the VirtualBox user interface?' I'm guessing you mean the Add Share dialog that you can access from the Settings->shared folders dialog? I.e., the place where you browse the host system to select a folder to be shared? Unless I'm mistaken, this has nothing to do with mounting but just identifies/defines shared folders apache migh want to read on the host system?
2) Not sure either what you mean by "observe what user-id Apache runs its daemons in (as defined in the Apache configuration file, or by a simple peek at ps -A outuput ...)" ? What do you mean by its daemons? Apache appears to run as www-data on the Ubuntu machines I'm working with. Do you mean the userid for user www-data? Or a group id for group www-data? Something else? When I execute ps -A, I see a handful of apache2 instances, but no instances of www-data. On the other hand, /etc/passwd and /etc/group do not contain the word 'apache' in them anywhere. I had already added user www-data to the vboxsf group when concocting my mount command.
I've tried adding a mount command to /etc/fstab to mount the shared folder at startup with no joy. This is the current directive. It doesn't block the boot process like others have, but neither does it actually result in the drive getting mounted:
Code:
# added by jta 2017-02-22 to mount oddballs shared folder from host
#my-share /var/www/my-dir vboxsf rw,noauto 0 1
I've no idea where to look for any errors caused by this directive. Once the machine boots, I try listing /var/www/my-dir and rather than the contents of the share, it's just the empty folder.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.