Skip to main content
Topic: How to automount a network share after boot? (Read 2437 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

How to automount a network share after boot?

My fstab contains the following entry for the network share:

//192.168.7.1/sd /home/userx/Public/.sd cifs _netdev,soft,rw,exec,guest,uid=1001,gid=998,file_mode=0755,dir_mode=0755,vers=3.0,nofail,│
echo_interval=5,actimeo=10 0 0

It works great when running "mount -a" as normal user without sudo after reboot, but same command does not work in @reboot cronjob as it requires sudo. I've tried chatgpt but it always suggest to create a runit service for this.

What is the best way to achieve this in Artix?

Re: How to automount a network share after boot?

Reply #1
Put the same cronjob mount command in /etc/rc.local.

 

Re: How to automount a network share after boot?

Reply #2
I was assuming rc.local cannot work since the internet runit services such as NetworkManager are not ready yet when it runs. Will try that next thanks.

Re: How to automount a network share after boot?

Reply #3
@Shoun2137  unfortunately adding /usr/bin/mount -a  to rc.local does not work, I believe for the reason mentioned above.

Re: How to automount a network share after boot?

Reply #4
but same command does not work in @reboot cronjob as it requires sudo.
Not if it's a root cronjob.
I was assuming rc.local cannot work since the internet runit services such as NetworkManager are not ready yet when it runs.
It runs last, on openrc at least, so maybe added a small sleep might help if it really is a race condition ?

Re: How to automount a network share after boot?

Reply #5
@gripped even after adding a 10 seconds sleep in front of it in rc.local, there is still no automount after login:

/usr/bin/sleep 10
/usr/bin/mount -a






Re: How to automount a network share after boot?

Reply #6
I'd check if rc.local is running at all by putting something like
Code: [Select]
touch /tmp/test-rc.local
in there and checking for it's existence after a reboot.


Re: How to automount a network share after boot?

Reply #7
rc.local is working great, in fact it solved a separate issue I've raised, of mounting a second nvme: https://forum.artixlinux.org/index.php/topic,8532.0.html

It is mounting my second nvme without problems and the sleep command delays the start for 10 seconds as well, but the mount command just does not work for the network share at all when in rc.local.

Re: How to automount a network share after boot?

Reply #8
Is anything like the "network" service set included in s6 provided for runit? Hooking a `mount -O _netdev` there could work.

Failing that, hooking into a networking service would work. I know dhcpcd can do that.

Or making a runit service that, idk, pings every few seconds until it succeeds, mounts the network shares, then execs pause.

Re: How to automount a network share after boot?

Reply #9
There must be a simpler way of doing this. I only need the mount command to run in a @reboot cronjob somehow...

Re: How to automount a network share after boot?

Reply #10
Unless you have the logs to back it up, I doubt it's related to permissions. Both cronie and fcron run as root and don't drop privileges for cronjobs on the root crontab. I'm able to use commands that require root just fine (such as chpst -u, writing to root-owned folders, etc.) here.

You can set up nopasswd rules using visudo so whatever user your cronjobs are running as can call mount.

If cronjobs are running as root (or another user able to mount the network share) and failing due to no network, then you can't avoid scripting a network wait. It can probably be done with a loop in the cronjob itself.

Re: How to automount a network share after boot?

Reply #11
Plug this into /etc/rc.local just to test if this isnt a fault of mount -a, because if this is defined in fstab, this shouldve been mounted regardless:
Code: [Select]
#!/bin/sh

while : ; do
    if df | grep -q '/home/userx/Public/.sd' ; then
        exit 0
    fi

    mount -t cifs "//192.168.7.1/sd" "/home/userx/Public/.sd" -o rw,exec,guest,uid=1001,gid=998,file_mode=0755,dir_mode=0755,vers=3.0,soft,echo_interval=5,actimeo=10

    sleep 5
done