You are not logged in.

#1 2009-10-25 10:54:06

Urfaust
Member
From: Germany
Registered: 2009-01-30
Posts: 164

Networkmanager and mount / umount CIFS shares

Hi

I'm trying to mount a CIFS share at boot via /etc/fstab. Everything is ok when i do

# mount -a

but the share doesn't mount at boot because the network is not instantly connected after loading the networkmanager daemon.

My daemons array looks like this

DAEMONS=(syslog-ng crond @alsa hal networkmanager @netfs)

So is there a way to delay the process of mounting this share in /etc/fstab or something? I know I could write the mount command to /etc/rc.local but this an ugly hack because I have to manually umount the share before shutdown...
Any opinions?

EDIT: changed topic

Last edited by Urfaust (2009-10-25 17:04:17)

Offline

#2 2009-10-25 11:11:36

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Networkmanager and mount / umount CIFS shares

Put something like that in /etc/NetworkManager/dispatcher.d/ and chmod it 700.

case "$2" in
   up)
              mount -a -t cifs
              ;;
   down)
              umount -a -t cifs
              ;;
esac

Offline

#3 2009-10-25 13:19:26

Urfaust
Member
From: Germany
Registered: 2009-01-30
Posts: 164

Re: Networkmanager and mount / umount CIFS shares

Thanks! This works.....kind of.
I am trying to mount the share depending on which ESSID I am connected to.

#!/bin/bash                                                                    
## INITIALISIERUNG                                                             
#Diese Werte werden vom NetworkManager an das Skript übergeben                 
INTERFACE=$1                                                                   
ACTION=$2                                                                      

## ESSID des Home-Netzwerkes
ESSID_home="mywireless"               

## ESSID des verbundenen Netzwerks bestimmen
ESSID=$(iwconfig $INTERFACE | grep ESSID | cut -d":" -f2 | sed -e 's/"//g')


## DEBUGGING
# Falls DBG_MODE=1 werden verschiedene Angaben nach $LOG ausgegeben
DBG_MODE=1                                                         
LOG=/tmp/dispatcher.log                                            

log_action() {
if [ $DBG_MODE=1 ]; then
        echo $(basename $0): >> $LOG
        echo $(date) >> $LOG        
        echo "ACTION: $ACTION, Device: $INTERFACE_COMMITTED \n" >> $LOG
fi                                                                     
}                                                                      



## Funktionen durchführen, je nach Aktion eine andere
case "$2" in                                         
        up)     log_action                           
#               /etc/rc.d/openntpd start             
                if [ $ESSID = $ESSID_home ]; then    
                {
                        mount -t cifs -o username=xxx,password=xxx //192.168.1.254/xxx /media/nsa220-xxx/
                        mount -t cifs -o username=xxx,password=xxx //192.168.1.254/yyy /media/nsa220-yyy/
                }
                fi
                ;;

        down)
                if [ $ESSID = $ESSID_home ]; then
                        umount /media/nsa220-*

                fi
                ;;

        pre-up)
                ;;

        post-down)
                ;;

        *)
                echo $"Usage: $0 {up|down|pre-up|post-down}"
                exit 1
esac

This only works if I execute the script manually. But it gets executed at startup (saw it in the log). Any idea? This is kind of strange... :-/
I also put sleep 5 && in front of the mount to delay it a bit but no effort....

Offline

#4 2009-10-25 13:29:28

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Networkmanager and mount / umount CIFS shares

Can't get essid from iwconfig before the interface is up, I guess. Essid should be passed in $CONNECTION_UUID by networkmanager - it didn't work in my case, though.

-edit-

Hm, I thought that this variable contained essid, but actually it contains an uuid - I've found mine in /etc/NetworkManager/system-connections/, but I don't know if it works for non-system connections too.

NM's documentation seems kind of sparse.

Last edited by lucke (2009-10-25 13:50:27)

Offline

#5 2009-10-25 13:56:47

Urfaust
Member
From: Germany
Registered: 2009-01-30
Posts: 164

Re: Networkmanager and mount / umount CIFS shares

Yeah, unmounting doesn't work either. roll
Man, I wish only one of the networkmanagers (wicd, knetworkmanager, networkmanager) out there would function properly. The only thing I want to do is mount and umount some shares and bring up a VPN connection, all depending on the network I am currently connected to. This is a real pain in the ass.

Last edited by Urfaust (2009-10-25 13:57:43)

Offline

#6 2009-10-25 14:21:50

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Networkmanager and mount / umount CIFS shares

Silly, CONNECTION_UUID works in up), but not in down). Still, you should be able to get essid from iwconfig inside those.

Offline

#7 2009-10-25 14:39:07

Urfaust
Member
From: Germany
Registered: 2009-01-30
Posts: 164

Re: Networkmanager and mount / umount CIFS shares

I could live with that. I try to mount the share everytime the interface gets up. If I am on the wrong network I get a timeout...ok.

But if only umounting the drives would work. Everytime I shutdown networkmanager it says that the script exited abnormally and the systems hangs...
Think I throw the whole thing out and mount manually if I need it..:rolleyes:

Last edited by Urfaust (2009-10-25 14:39:39)

Offline

#8 2009-10-25 14:54:50

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Networkmanager and mount / umount CIFS shares

Unmount in /etc/rc.local.shutdown?

Offline

#9 2009-10-25 15:15:34

Urfaust
Member
From: Germany
Registered: 2009-01-30
Posts: 164

Re: Networkmanager and mount / umount CIFS shares

Seems like Networkmanager closes the connection to early, so I get a:

Oct 25 16:08:47 netbook kernel: wlan0: disassociating by local choice (reason=3)                             
Oct 25 16:08:49 netbook shutdown[3210]: shutting down for system halt                                        
Oct 25 16:08:49 netbook init: Switching to runlevel: 0                                                       
Oct 25 16:09:05 netbook kernel: CIFS VFS: No response for cmd 50 mid 608

Offline

#10 2009-11-01 18:06:17

Urfaust
Member
From: Germany
Registered: 2009-01-30
Posts: 164

Re: Networkmanager and mount / umount CIFS shares

I think I'm getting crazy. I modified the script and now I check if the server is reachable before connecting (connect depending on ESSID doesn't work). This works if the network device is going up but not for going down. So if the network shuts down I check if the mountpoint is mounted and if so it should be unmounted.
The whole thing is working for NFS shares but if the share is mounted via CIFS the umounting doesn't work anymore and the system hangs at "Unmounting Filesystems" at shutdown screen. mad

Here is the dispatcher script for the CIFS share and yes I know it's ugly. wink

#!/bin/bash                                                                    
## INITIALISIERUNG                                                             
#Diese Werte werden vom NetworkManager an das Skript übergeben                 
INTERFACE=$1                                                                   
ACTION=$2                                                                      

## DEBUGGING
# Falls DBG_MODE=1 werden verschiedene Angaben nach $LOG ausgegeben
DBG_MODE=0                                                         
LOG=/tmp/dispatcher.log                                            

log_action() {
if [ $DBG_MODE=1 ]; then
        echo $(basename $0): >> $LOG
        echo $(date) >> $LOG        
        echo "ACTION: $ACTION, Device: $INTERFACE_COMMITTED \n" >> $LOG
fi                                                                     
}                                                                      

##Ping
ping -c 1 -t 1 192.168.1.254 > /dev/null 2> /dev/null
if [ $? -eq 0 ]; then                                
       nas=1 #NAS up                          
else                                                 
       nas=0 #NAS down                      
fi                                                   

## Funktionen durchführen, je nach Aktion eine andere
case "$2" in                                         
        up)     log_action                           
#               /etc/rc.d/openntpd start             
               if [ $nas = 1 ]; then                
               {                                    
                       mount -t cifs -o username=xxx,password=xxx,iocharset=utf8 //192.168.1.254/path /media/path/                                                                                              
               }                                                                                                
               fi                                                                                               
                                                                               
                ;;                                                                                

        down)
               mount|grep "on /media/path type" > /dev/null
               if [ $? -eq 0 ]; then
               {
               umount /media/path
               }
               fi

                ;;

        pre-up)
                ;;

        post-down)
                ;;

        *)
                echo $"Usage: $0 {up|down|pre-up|post-down}"
                exit 1
esac

Last edited by Urfaust (2009-11-01 18:06:40)

Offline

#11 2011-10-28 12:05:30

ubuntologist
Member
From: sydney australia
Registered: 2011-10-28
Posts: 1

Re: Networkmanager and mount / umount CIFS shares

Had this problem today - I found the easiest way to solve the issue was to edit /etc/rc.d/netfs and include the line "sleep 20" in the start case statement.

This allows the network to come up while the netfs daemon keeps running in the background (i.e. @netfs in /etc/rc.conf) before attempting to mount after 20 seconds.

e.g. /etc/rc.d/netfs

case "$1" in
          start)
                  sleep 20
                  stat_busy "Mounting Network Filesystems"
                  mount -a -t "$NETFS"
                  rc=$?
                  mount -a -O _netdev
                  (( rc || $? )) && stat_die
                  add_daemon netfs
                  stat_done
                  ;;

Good luck!


ilya

Offline

#12 2012-03-19 13:20:59

jkmunk
Member
Registered: 2012-03-19
Posts: 1

Re: Networkmanager and mount / umount CIFS shares

Hi,

This works for me when mounting

/etc/NetworkManager/dispatcher.d/99smartsynergy.sh:

#!/bin/sh
#Recognize network with ESSID = my_network_essid

IF=$1 #interface
STATUS=$2 #interface status (up|down)

if [ "$IF" = "wlan0" ] ;
    then
    if [ "$STATUS" = "up" ] && /sbin/iwgetid | /bin/grep -c my_network_essid ;
	then
	/usr/bin/mountingscript
    elif [ "$STATUS" = "down" ] ;
	then
	/usr/bin/unmountingscript
	fi
    fi 

But alas, also doesn't unmount, I'm trying with

 mount -f /mountingpath 

/JKMUNK

Offline

Board footer

Powered by FluxBB