Why isn't shared folder automounting with fstab?

I have a shared folder “shared” which lives on the host machine and is shared via virtualbox to the guest as “shared”. In fstab, I put:


shared /var/www/testsite vboxsf defaults 0 0

But when I go to /var/www/testsite nothing is there. If I then execute the command:


sudo mount -t vboxsf shared /var/www/testsite

then it mounts it! Why isn’t fstab auto-mounting the folder?

This also doesn’t work!

shared /var/www/testsite vboxsf defaults,uid=0,gid=0 0 0

On Wed, 19 Dec 2012 02:06:02 +0000, 6tr6tr wrote:

> then it mounts it! Why isn’t fstab auto-mounting the folder?

At a guess, at startup, the VirtualBox daemon hasn’t started before the
filesystems try to mount the way you’re doing it.

Check out:

http://www.virtualbox.org/manual/ch04.html#sf_mount_auto

See if that gets you pointed in the right direction. :slight_smile:

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

Thanks. Unfortunately, that link doesn’t help. But your comment about VB daemon not being started yet is probably the issue. Can I schedule a script to run as root 1 minute after startup that does the mounting?

On Wed, 19 Dec 2012 06:26:02 +0000, 6tr6tr wrote:

> hendersj;2511864 Wrote:
>> On Wed, 19 Dec 2012 02:06:02 +0000, 6tr6tr wrote:
>>
>> > then it mounts it! Why isn’t fstab auto-mounting the folder?
>>
>> At a guess, at startup, the VirtualBox daemon hasn’t started before the
>> filesystems try to mount the way you’re doing it.
>>
>> Check out:
>>
>> ‘Chapter’ (http://www.virtualbox.org/manual/ch04.html#sf_mount_auto)
>>
>> See if that gets you pointed in the right direction. :slight_smile:
>>
>> Jim
>>
>>
> Thanks. Unfortunately, that link doesn’t help. But your comment about VB
> daemon not being started yet is probably the issue. Can I schedule a
> script to run as root 1 minute after startup that does the mounting?

You could try using a cron job scheduled for @reboot - or the after.local
script would seem to be a good place to set it up.

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

On 2012-12-19 07:59, Jim Henderson wrote:

>> Can I schedule a
>> script to run as root 1 minute after startup that does the mounting?
>
> You could try using a cron job scheduled for @reboot

And there you can schedule an “at” job to run a minute later. Result:
job runs a minute after reboot, as requested :slight_smile:


Cheers / Saludos,

Carlos E. R.
(from 11.4, with Evergreen, x86_64 “Celadon” (Minas Tirith))

On 12/19/2012 12:59 AM, Jim Henderson wrote:
> On Wed, 19 Dec 2012 06:26:02 +0000, 6tr6tr wrote:
>
>> hendersj;2511864 Wrote:
>>> On Wed, 19 Dec 2012 02:06:02 +0000, 6tr6tr wrote:
>>>
>>>> then it mounts it! Why isn’t fstab auto-mounting the folder?
>>>
>>> At a guess, at startup, the VirtualBox daemon hasn’t started before the
>>> filesystems try to mount the way you’re doing it.
>>>
>>> Check out:
>>>
>>> ‘Chapter’ (http://www.virtualbox.org/manual/ch04.html#sf_mount_auto)
>>>
>>> See if that gets you pointed in the right direction. :slight_smile:
>>>
>>> Jim
>>>
>>>
>> Thanks. Unfortunately, that link doesn’t help. But your comment about VB
>> daemon not being started yet is probably the issue. Can I schedule a
>> script to run as root 1 minute after startup that does the mounting?
>
> You could try using a cron job scheduled for @reboot - or the after.local
> script would seem to be a good place to set it up.

You need to be aware that after.local scripts are not run automatically with
systemd as the concept of “after” is no longer valid. You also need to create
the service to do that, and you cannot be sure that it is started after any
particular event.

A much simpler approach would be to create a script to be run in the background
from boot.local with the command ‘/path_to_my_script/script_name &’. The script
would do a ‘sleep 60’ followed by the appropriate mount command.

On Wed, 19 Dec 2012 15:59:24 +0000, Larry Finger wrote:

> You need to be aware that after.local scripts are not run automatically
> with systemd as the concept of “after” is no longer valid. You also need
> to create the service to do that, and you cannot be sure that it is
> started after any particular event.
>
> A much simpler approach would be to create a script to be run in the
> background from boot.local with the command
> ‘/path_to_my_script/script_name &’. The script would do a ‘sleep 60’
> followed by the appropriate mount command.

Good point, thanks, Larry - I’d forgotten that that wasn’t relevant with
systemd.

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

On Wed, 19 Dec 2012 10:18:09 +0000, Carlos E. R. wrote:

> On 2012-12-19 07:59, Jim Henderson wrote:
>
>>> Can I schedule a script to run as root 1 minute after startup that
>>> does the mounting?
>>
>> You could try using a cron job scheduled for @reboot
>
> And there you can schedule an “at” job to run a minute later. Result:
> job runs a minute after reboot, as requested :slight_smile:

That’d do it too. :slight_smile:

Jim


Jim Henderson
openSUSE Forums Administrator
Forum Use Terms & Conditions at http://tinyurl.com/openSUSE-T-C

Thanks! Can you tell me how I would do this? I’ve found some info on cron jobs but can’t seem to figure out how to schedule my script for a minute after startup. Also, how do I make the script run its commands as root?

OK, I don’t know how to set the suer, but I think for the rest of it, this will do what I want.

In crontab file, I add:


@reboot sleep 60 && my_script.sh

But how do I make it run as root?

It did not work. Here’s what I did:

  1. At command line typed: “sudo crontab -e”
  2. Added the line “@reboot sleep 60 && /home/myusername/mountmyfolder.sh”
  3. Saved it
  4. Created the file “/home/myusername/mountmyfolder.sh” and added the lines:

#!/bin/sh
mount -t vboxsf myfolder /var/www/mysitefolder

This didn’t work. What am I doing wrong?

On 2012-12-20 01:46, 6tr6tr wrote:

> But how do I make it run as root?

By placing it in root’s crontab.

You open a terminal, do “su -” to get yourself root, then run “crontab
-e” to edit the crontab.


su -
EDITOR=/usr/bin/joe crontab -e

If you like “vi”, don’t use the editor variable above.


Cheers / Saludos,

Carlos E. R.
(from 11.4, with Evergreen, x86_64 “Celadon” (Minas Tirith))

I got it to work! As usual, I was the problem. :slight_smile: I forgot to mark the “.sh” file as an executable.

Thanks to everyone for your help!

On 2012-12-20 01:56, 6tr6tr wrote:

> This didn’t work. What am I doing wrong?

I don’t know, you have to find out :slight_smile:

The first thing is learning if the script runs. For that, you set it to
run in 3 minutes time, not at boot. And instead of mounting something,
you set the script to write a line to a file. And then you watch the
messages log, and if you see the cron entry there, also the file that it
is supposed to write to.

If that works, then you do the mounting.

You can also do the 1 minute delay inside the script.

Ah! In crob jobs entries, use full paths.

And, if you have local mail working, you place a line


MAILTO=myusername

in the crontab file and you will get a nice email with the errors.


Cheers / Saludos,

Carlos E. R.
(from 11.4, with Evergreen, x86_64 “Celadon” (Minas Tirith))

On 2012-12-20 02:16, 6tr6tr wrote:
>
> I got it to work! As usual, I was the problem. :slight_smile: I forgot to mark the
> “.sh” file as an executable.

:slight_smile:

> Thanks to everyone for your help!

Welcome.


Cheers / Saludos,

Carlos E. R.
(from 11.4, with Evergreen, x86_64 “Celadon” (Minas Tirith))