This site is now 100% read-only, and retired.

Handling network mounts on a very mobile laptop?

Posted by geekneck on Thu 5 Nov 2009 at 06:43

I have a laptop that travels with me to work as well as being used at home. I have a number of network CIFS mounts that I like to have available when I am at home, so I have them set to "auto" in /etc/fstab. When I am at work, I use a Mobile Broadband card to connect to the Internet. When at home, I typically use Ethernet.

The problem is that when I shift locations, I need proper handling of those network mounts. Typically, I will suspend my laptop at home, come into work the next day, and resume the laptop with the Broadband card. The problem is that I am now on a different network, and those CIFS shares are no longer available, causing most operations to hang. I typically have to hard restart the laptop in order to gain proper functionality.

I have tried using noauto in /etc/fstab, but then I have to manually connect the CIFS shares at home. I still have to remember to manually disconnect them before suspending at night.

I would think this is not an uncommon usage scenario. Does anyone have any insights as to handle this seamlessly? Thanks in advance!

 

 


Re: Handling network mounts on a very mobile laptop?
Posted by omarhem (212.30.xx.xx) on Thu 5 Nov 2009 at 07:36
I had similar issues with nfs mounts and I found autofs to be the best solution for me. It only actually mounts the stuff when I try to access it and the mounts timeout shortly if they are not accessed. So its always handy when I need it and not in the way when I don't.

[ Parent ]

Re: Handling network mounts on a very mobile laptop?
Posted by nitrogen (208.106.xx.xx) on Thu 5 Nov 2009 at 07:36
Try using the automounter. You can use a script if you need a password. You can configure it to unmount after x number of minutes of inactivity. YOu can also mount remote filesystems on the fly via /net (e.g. cd /net/hostname.tld/export/dir

[ Parent ]

Re: Handling network mounts on a very mobile laptop?
Posted by jawi (84.233.xx.xx) on Thu 5 Nov 2009 at 08:14
I believe the "ifupdown" networking scripts on Debian already provide you with the desired capabilities to run scripts (thus mount/unmount shares) when interfaces are brought up or down.
See http://www.debian.org/doc/manuals/debian-reference/ch05.en.html (sections 5.3 and up) for more information.

[ Parent ]

Re: Handling network mounts on a very mobile laptop?
Posted by joerg (84.58.xx.xx) on Thu 5 Nov 2009 at 09:31
There are two other solutions. One is ifplugd and the other is the 'dispatcher' mechanism of the NetworkManager. I've used ifplugd a long time, but now I'm using a dispatcher script. This script must be stored in /etc/NetworkManager/dispatcher/! It will be called by NetworkManager with the interface as parameter $1 and the action as $2. Available actions are "pre-up", "up", "down" and "post-down".

My personal mounting script ;-) uses "up" mount some of the entries inside /etc/fstab. Because I use DHCP, I can scan the domain within the script. My fstab comes with mount pathes, which include the domain! So I'm able grep all mounts only with this string.

Another possible way is the usage of arping. Here you can ping a server and use the MAC address to decide with mount should be used.

At last, you can use iwconfig to exrect the ESSID.

Nevertheless, using NetworkManager gives you a "per user" way to mount stuff.

By the way: if you are interessed in my script, drop me an mail...

[ Parent ]

Re: Handling network mounts on a very mobile laptop?
Posted by Anonymous (83.170.xx.xx) on Thu 5 Nov 2009 at 17:12
I have such similar configuration, and i have finally worked it out with pre/post connect/disconnect scripts as mentioned above.
The only difference is that i have wifi on both home and work and i use wicd as network manager on ubuntu. with wicd there is no need to manually edit scripts, each network can have couple of pre/post scripts and since i use wifi, it works almost seamlessly!
I mount CIFS shares on post connection and unmount them on pre disconnect.
You can have similar config on wired networks, give it a try: http://wicd.sourceforge.net/

[ Parent ]

Re: Handling network mounts on a very mobile laptop?
Posted by Anonymous (83.170.xx.xx) on Thu 5 Nov 2009 at 17:14
I have such similar configuration, and i have finally worked it out with pre/post connect/disconnect scripts as mentioned above.
The only difference is that i have wifi on both home and work and i use wicd as network manager on ubuntu. with wicd there is no need to manually edit scripts, each network can have couple of pre/post scripts and since i use wifi, it works almost seamlessly!
I mount CIFS shares on post connection and unmount them on pre disconnect.
You can have similar config on wired networks, give it a try: http://wicd.sourceforge.net/

[ Parent ]

Re: Handling network mounts on a very mobile laptop?
Posted by Anonymous (198.97.xx.xx) on Thu 5 Nov 2009 at 21:03
Add _netdev (instead of auto) to the mount options: this indicates that the filesystem should only be mounted when network access is available.

[ Parent ]

Re: Handling network mounts on a very mobile laptop?
Posted by Anonymous (198.97.xx.xx) on Thu 5 Nov 2009 at 21:05
Add _netdev (instead of auto) to the mount options: this indicates that the filesystem should only be mounted when network access is available.

[ Parent ]

Re: Handling network mounts on a very mobile laptop?
Posted by Anonymous (88.248.xx.xx) on Fri 6 Nov 2009 at 05:52
You can use a VPN tunnel to connect your home network. This way, your connection to your home will pwrsist even after switching configurations.

[ Parent ]

Re: Handling network mounts on a very mobile laptop?
Posted by Anonymous (86.59.xx.xx) on Fri 6 Nov 2009 at 10:50
gvfs seems to have methods set up for this. i just recently noticed that copy/move processes in gnome just change the interface when new connections show up in ubuntu jaunty.

(tested only for ssh, but i suppose it will work for other connections as well; in a setup like yours, using sshfs provides an advantage because it can use an sshconfig dispatch to figure out how to establish the connection based on where you are)

i suppose you need "proper" file system support, which is provided by gvfs-fuse. as opposed to the old gnome-vfs, gvfs has no gnome/x11 dependencies any more.

[ Parent ]

Re: Handling network mounts on a very mobile laptop?
Posted by kvv (82.161.xx.xx) on Fri 6 Nov 2009 at 20:53
There is a package called whereami. It detects known network environments and runs associated actions, e.g. mounting your personal file shares on the current network.

[ Parent ]

Re: Handling network mounts on a very mobile laptop?
Posted by Anonymous (220.233.xx.xx) on Thu 23 Dec 2010 at 15:06
I have my own script to connect to my server and some backup boxes, it works perfectly, all you would need to do is detect what connection is up, easy to do. I would recommend using sshfs and setting up a ssh key (with a passphrase) so you don't need to type in your password all the time with your script always running. My setup is for my desktop but it can be used for local and nonlocal use.. all you would need is say i'm local eth0 is up so lets try to connect to 192.168.2.3 (or what ever its ip is) or Hey im at work 3G-USB-NAME is up, lets try to connect to 123.45.67.890 just as an example.. you could also use /etc/cron.d/hourly/mount-server.sh (see what connection is up, its changed, unmount server & re-mount with new ip addr) or you run it manually when you login. BTW: I would not recomend suspending the computer as its not always reliable, I have had lots of probs with suspending with a low battery, always shutdown and turn on. If you are using debian.5 then if you want you can upgrade to debian squeeze to improve boot time by about a min.. (kfreebsd-debian-squeeze-gnome,is what i will use soon)

So pointers:
Create a bash script.
It must detect what connection interface we are using..
If it has changed then unmount the server (if already mounted) then re-mount.
Use /etc/cron.d/hourly to run it..
Don't suspend: it's not always reliable and can be annoying when you have a low battery.
Debian-Squeeze is faster and when released I'd recommend updating, use kfreebsd version so you can use zfs, and also dont forget to backup everything you need then install to a new partition to test it out then if you like it backup your old install and have fun reinstalling the new version and getting everything you need there too, then keep the backup there so you can boot it when you need it, you could also put a live DVD iso there to boot. :) always easy to recover if you need to..

[ Parent ]

Re: Handling network mounts on a very mobile laptop?
Posted by jamesm (220.233.xx.xx) on Thu 23 Dec 2010 at 15:26
This was my post BTW..

[ Parent ]