You are not logged in.

#1 2019-07-01 23:36:09

Gotit
Member
From: New England, USA
Registered: 2017-04-27
Posts: 73

[Solved]Mount Network Drive with sudoers.d

Hi - having a problem gettring a network drive to mount at boot using scripts and sudoers.d.  I have a network drive, but I only want to try and mount it at boot if I'm in my network.  I have a script that is:
run by "Sessions and Startup" that calls:
an entry in sudoers.d which doesn't require password entry that calls:
a script in a folder owned by root to mount the drive

However, the drive does not mount and I get the following error in the logs

pam_unix(sudo:auth): conversation failed
pam_unix(sudo:auth): auth could not identify password for [user]

I know the script to mount the drive is running because I have it send a message once it starts and I get the message.

If I run from terminal, the script run by "Sessions and Startup", the chain of events noted above is executed and the drive mounts with no request for password.

I have other scripts for other activities that I run through sudoers.d and they work as expected.

It's odd that it works for me when run via terminal, but not when called by "Sessions and Startup".

Any thoughts would be appreciated.

Last edited by Gotit (2019-07-06 13:21:24)

Offline

#2 2019-07-01 23:56:12

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [Solved]Mount Network Drive with sudoers.d

With an active session, you can mount drives using udev, without the need for elevated privileges. See https://wiki.archlinux.org/index.php/Ud … s_in_rules


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2019-07-02 04:58:07

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 74,314

Re: [Solved]Mount Network Drive with sudoers.d

I only want to try and mount it at boot if I'm in my network

https://wiki.archlinux.org/index.php/Ne … r_examples

Offline

#4 2019-07-04 13:34:10

Gotit
Member
From: New England, USA
Registered: 2017-04-27
Posts: 73

Re: [Solved]Mount Network Drive with sudoers.d

@seth Thanks for NM Dispatcher info.  I've installed the scripts modified with my connection's UUID and activated the Dispatcher.  When I boot I see it running, but it can't mount the drive because there's no entry for it in /etc/fstab:

systemd[1]: Started Network Manager Script Dispatcher Service.
nm-dispatcher[800]: req:1 'up' [wlp2s0]: new request (1 scripts)
nm-dispatcher[800]: req:1 'up' [wlp2s0]: start running ordered scripts...
nm-dispatcher[800]: req:2 'connectivity-change': new request (1 scripts)
nm-dispatcher[800]: req:2 'connectivity-change': start running ordered scripts...
nm-dispatcher[800]: mount: /mnt/Netdrive-Files/: can't find in /etc/fstab.

If I place an entry for the drive in fstab, the system will simply try to mount it on each boot, regardless of nm-dispatcher.  If I'm in my network the drive will mount, otherwise it will error out. I must be missing a point here somewhere, what is it?

Last edited by Gotit (2019-07-04 13:39:03)

Offline

#5 2019-07-04 13:38:25

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,104

Re: [Solved]Mount Network Drive with sudoers.d

Add it to the fstab with the noauto option, that way fstab will ignore it for automounting but you will still have the same lookup guarantees so that you don't have to specify the entire mount command in the manual mount invocation

Last edited by V1del (2019-07-04 13:39:15)

Offline

#6 2019-07-04 13:40:27

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,648

Re: [Solved]Mount Network Drive with sudoers.d

https://wiki.archlinux.org/index.php/Fs … al_devices

You can try adding an fstab entry with "noauto,nofail" options.

There is also this: https://wiki.archlinux.org/index.php/Ne … ait_Online

Offline

#7 2019-07-04 16:08:34

Gotit
Member
From: New England, USA
Registered: 2017-04-27
Posts: 73

Re: [Solved]Mount Network Drive with sudoers.d

WOW, thanks for all the assist, guys...

Reading through fstab wiki, I'm now thinking mounting on demand would be a better option than just mounting at boot if in network.  On demand means I won't be carrying the connection overhead until I need it.

So, off to fstab I went.  I can make an entry that mounts at boot, but can't seem to get it to work in an on demand mode.  Here's the pertinent entry I'm trying to use for on demand mount:

 //[IP Address]/netdrive/Media /mnt/Netdrive-Media cifs guest,vers=1.0,noauto,x-systemd.automount,x-systemd.device-timeout=30,_netdev,iocharset=utf8,sec=ntlm 0 0

I'm assuming when I access the folder /mnt/Netdrive-Media via Thunar, that network folder should mount.  Maybe, I'm misunderstanding "on demand" in this context.

Offline

#8 2019-07-06 13:20:37

Gotit
Member
From: New England, USA
Registered: 2017-04-27
Posts: 73

Re: [Solved]Mount Network Drive with sudoers.d

I can't seem to get the "on demand" feature to work quite right, and it seems it needs to mount in /etc/media too.

So, settling for the "when in network, mount on boot" feature as originally sought. 
@V1del and @2ManyDogs thanks for the "noauto" tip.  My final fstab line reads as:

//[driveIP]/netdrive/Files /mnt/Netdrive-Files cifs guest,vers=1.0,noauto,x-systemd.device-timeout=30,_netdev,iocharset=utf8,sec=ntlm 0 0

There is another issue brewing where the drive doesn't actually unmount with the

umount

command even though it reports unmounted!  I'll open a another thread if I need assistance.

Offline

Board footer

Powered by FluxBB