Mounting script doesn't run at boot

oepenSUSE 12.3 x86_64, KDE 4.10
Sorry if this is in the wrong froum, I’m not quite sure where to put it.

I have the following script I’m trying to run at boot to mount some shares on an NAS, which require time to be woken up by WOL so fstab won’t mount it. Curiously, fstab won’t mount it even after it’s started and I reboot the computer, and I have to run “mount -a” manually. Here’s the script:

#!/bin/sh

sleep 20

wol  -p 9 4C:E6:xx:xx:xx:xx

sleep 150

mount -t cifs //10.0.0.7/dh_home -o username=x,password=y /media/dh_home && mount -t cifs //10.0.0.7/Movies -o username=x,password=y /media/Movies && mount -t cifs //10.0.0.7/Music -o username=x,password=y /media/Music

The script itself works when run as root. The problem arises when I try to get it to autostart on boot, which I’ve attempted through this desktop script:
startNAS.desktop

[Desktop Entry]
Name=startNAS
Exec=/home/davidh/startNAS.sh
Type=Application
Terminal=false

The mounting script is located in my home folder, and I’ve tried putting the .desktop script in both /etc/xdg/autostart and /usr/share/autostart with ownership and permissions set the same as other .desktop files in the folder, but the shares won’t mount at boot.
As for fstab not mounting the shares when the NAS is already started, it could be that the NIC hasn’t pulled an IP address before fstab is read, but shouldn’t the “_netdev” option take care of that? I’ve tried it, and it hasn’t.

I’d appreciate any advice on this.

I’ve just found out that when I run the startNAS script as root, it mounts my shares with root ownership. That’s to be expected, because there’s nothing in the “mount -t” command to specify that it be mounted under my user account credentials, when “x” and “y” are the NAS credentials. So, where do I put the computer account credentials?

I fixed the startNAS script by including UID and GID arguments, and now the script mounts the shares correctly as user when run as root, so this doesn’t appear to be a SAMBA issue. The problem is the script won’t run as autostart. What gives?

Autostart programs are run when someone logs in, not when computer boots. You need to create systemd unit (or legacy initscript) to do it on boot.

So shouldn’t the autostart program run when my user account logs in? That’s the problem, it’s not running at log in as intended.
For my uses, it doesn’t matter if it mounts at boot or login.

By default non-privileged users are not allowed to mount filesystems. You can setup sudo or enter your filesystems in /etc/fstab with options noauto,users (in addition to any specific option you require) to allow non-root to mount it.

That doesn’t appear to be the problem. The startNAS script works when I run it manually (as root) after logging in (as user). I can do the same thing from shell:
su -
mount -t cifs //network username=x,password=y,uid=a,gid=b /mountpoint
and the share mounts as desired, with user ownership.

My fstab appears to be okay, because I can get the same results after I log in by running :
su -
mount -a
However, as mentioned in a post above, fstab doesn’t mount the network shares at boot even when the NAS is started and ready, but only after running mount -a manually.

I’ll try noauto, users and see if it changes anything, but I doubt it will.

No dice with “noauto,users”.
Fstab network mounts work, just not at boot but rather after I log in and run mount -a.
My script works when I run as root, after logging in (as user).

All I want it to do is make my script run automatically as root. I had thought the starNAS.desktop program was supposed to do that.
If I can run it manually (as root) and it works, then why can’t it be done automatically?

You need to use simple “mount /mount/point” for it to be effective. If using full form “mount /dev/ice /mount/point”, /etc/fstab will be effectively ignored.

If I can run it manually (as root) and it works, then why can’t it be done automatically?

I suggested you to use sudo.

I’m pretty convinced fstab is not the problem. I use the same fstab configuration in an oS 12.4 laptop that connects by wireless and mounts the NAS shares just fine, if the NAS is already awake.

su -
mount -a

and

sudo mount -a

both read fstab, and both work.

 su -
mount -t cifs .....

and

sudo mount -t cifs .....

The script that uses mount -t cifs … works, both in waking up the LAN and mounting the shares, when I run it manually.

Weird…

Now it seems the script is running. I removed a redundant crontab that invoked WOL to wake the NAS, and the NAS still autostarted when after a long shutdown and reboot, showing that WOL runs from the script…

If I invoke a script as root, won’t everything in the script run as root, even if the script itself is not owned by root?

On 2013-10-07 05:16, HuaiDan wrote:

> Code:
> --------------------
> #!/bin/sh
>
> sleep 20
>
> wol -p 9 4C:E6:76:92:F9:BB
>
> sleep 150
>
> mount -t cifs //10.0.0.7/dh_home -o username=x,password=y /media/dh_home && mount -t cifs //10.0.0.7/Movies -o username=x,password=y /media/Movies && mount -t cifs //10.0.0.7/Music -o username=x,password=y /media/Music
>
> --------------------

Replace with:



sudo wol ....

sudo mount ...


Then, do not mount ANYTHING under /media. Leave the /media directory to
the system automatics, you should use /mnt for manual mounts.

On 2013-10-07 10:36, HuaiDan wrote:

Code:

sudo mount -a

Don’t use “mount -a” that much. Mount only the specific mount you want.
That way you do not need to use sudo.


mount /mnt/dh_home


Cheers / Saludos,

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

On 2013-10-07 11:46, HuaiDan wrote:
> If I invoke a script as root, won’t everything in the script run as
> root, even if the script itself is not owned by root?

But your script is called as user when done automatically at login.


Cheers / Saludos,

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

For anything you want run as root from a bash script on startup, have a look at my blog on the after.local script: systemd and using the after.local script in openSUSE 12.1 - Blogs - openSUSE Forums

Thank You,

sudo wol …

sudo mount …

Unfortunately, that didn’t work. I changed the mount folder to /mnt, and tested it manually, but it still didn’t work automatically on boot/login even with the added “sudo”.

Then, do not mount ANYTHING under /media. Leave the /media directory to
the system automatics, you should use /mnt for manual mounts.

I know, I’m trying not to, but I’m just using it to test my configuration. What it shows is that my fstab works when invoked manually and the NAS is already on and ready, but it doesn’t mount my network shares automatically on boot/login, even when the NAS is on/ready.

But your script is called as user when done automatically at login.

Really? Even when invoked by the startNAS.desktop program which is located in /etc/xdg/autostart and /usr/share/autostart? I thought that was the whole point of those folders: to start programs at boot/login as root!

What gave you this idea? The whole point of these folders is to provide system-wide default configuration.

Finally, something that worked! Thank you!

Now that just leaves the problem of why my fstab mounts won’t mount on boot, even when the NAS is up and ready, but will mount with “mount -a”. A typical entry looks like this:

//10.0.0.7/dh_home /mnt/dh_home cifs _netdev,username=aa,password=bb,uid=x,gid=users 0 0

My suspicion is that the NIC doesn’t grab an IP before fstab is read, but I thought that’s what the “_netdev” option was for.

Are you using ifup or NetworkManager for network?

Assuming it’s ifup, I’d say that’s where it is, I’ve seen issues like this with NIS, NFS, Samba:

Check Yast - Networkdevices - Networksettings.
Tick the ethernet device, click Edit
In the general tab, change “at cable connection” to “at boot”.
Save the changes, check behaviour on reboot.

Network Manager.
My old laptop, also running 12.3 (oSUSE since 12.1) , has the same configuration but it’s wireless, and slow to connect at that. It has no problems mounting the same shares from fstab.