[Guide] How to automount remote shares wirelessly

Discussion in 'Linux' started by aspirin, Aug 10, 2008.

Thread Status:
Not open for further replies.
  1. aspirin

    aspirin

    Joined:
    Aug 6, 2008
    Messages:
    8
    Likes Received:
    0
    Keywords: mount, cifs, wireless, autofs, Samba, My Book World Edition storage appliance, symbolic link

    Overview
    If you’ve tried to mount remote file shares to your wirelessly-connected Aspire One at boot time, you already know that hard mount points don’t work, since the boot process finishes before the wireless connection is established. This may not seem like a problem with wired connection, but even in a wired world, if the share is down when the Aspire boots up, the mount will fail.

    This guide shows how to overcome these problems by using the automount facilities of Linux. Once automounting is set up, you simply boot your Aspire (wired or wirelessly) and your shares are available “on demand” as soon as your network connection is up. If the shares go down or offline at any time, no problem. As soon as they’re up again, you’ll be able to access them as before.

    I gleaned the information for this guide from a few sources. They’re cited near the end.

    My Environment
    My network environment is a combination of wired and wireless access points. One wired device is a Western Digital My Book World Edition II network storage appliance serving files to my Windows boxes via Samba (the My Book runs a version of Linux and is itself quite hackable, though no hacking is necessary for this example). The My Book is located at 192.168.0.20, and has several named shared drives. The three I’ll demonstrate mounting are hendrix, satriani and vaughan. Each is located directly off the root of the My Book.

    Steps
    I’ll assume you’re comfortable with the Linpus Package Manager and that you know when and how to use sudo to do file system operations as root. Much of the work below needs to be done as root.

    1. Be sure autofs is installed (if it is, you’ll find several auto.* files in your /etc directory, and /etc/init.d/autofs will exist). autofs wasn’t installed on my Aspire out of the box, so I used the Package Manager to install version 5.0.2-29.i386 (newer versions should work as well).

    2. Make a backup of the current /etc/auto.master file, in case something goes wrong below. Then edit /etc/auto.master, replacing everything inside it with these two lines:

    Code:
    # allow My Book shares to be automounted to the /mbshares directory
    /mbshares	/etc/auto.mbshares
    
    Here, /mbshares refers to a directory of my choosing. Almost any directory will do. (I had trouble with /home/users, so steer clear of that one. We’re going to make symbolic links to these soon-to-be-mounted shares anyway, so just create a convenient, out-of-the-way mount point for now.)

    Also above, /etc/auto.mbshares refers to a file you create to tell autofs what to call the shares on the Linux side, where to find them on the network side, and how to mount them. This file is created next.

    3. Create a file named /etc/auto.mbshares containing the following lines:

    Code:
    # Specify which My Book shares automount inside /mbshares,
    # and what to call each share. 
    # NB: must use IP address (not //MyBookName)
    # NB: "credentials" option hides login credentials from normal users
    # NB: can’t mount entire device (192.168.0.20), only shared directories
    satrianishare -fstype=cifs,rw,noperm,credentials=/root/credentials.txt ://192.168.0.20/satriani
    hendrixshare -fstype=cifs,rw,noperm,credentials=/root/credentials.txt ://192.168.0.20/hendrix
    vaughanshare -fstype=cifs,rw,noperm,credentials=/root/credentials.txt ://192.168.0.20/vaughan
    
    Note that the file system type is cifs (Common Internet File System), not the “usual” Samba (smbfs). This is a newer (and IMHO better) approach. At least it seems to work in more circumstances. All religious arguments to the contrary should be directed to /dev/null. Also note that the My Book’s IP address is used. Attempts to use its network name instead didn’t work (e.g. ://MyBookName/hendrix). It appears you have to use the IP address (if you figure out a way to use names, please post your results).

    You will need to substitute appropriately in the above example, i.e. replace the automount mount point name “satrianishare” with whatever directory you want as your mount point, and replace the network share reference (i.e. ://192.168.0.20/satriani) with the IP address and directory name of your share.

    Added 8/10/08: You'll also need to create the /root/credentials.txt file. This is a root-access only file (chmod 600) that holds the user and password for mounting the shares. By keeping those values in a protected file, security is maintained. The file's contents are shown below. Substitute your own password (user will probably remain the same unless you've moved on from the Aspire One's default user of user):
    Code:
    user=user
    password=yourLinuxPassword
    
    The whole purpose of the /etc/auto.mbshares file is to tell autofs which shares to mount on demand inside the /mbshares directory. So in this example, if the user does this:

    Code:
    $ ls /mbshares
    $
    
    no files or directories are listed below the /mbshares directory. However, if the user types

    Code:
    $ ls /mbshares/satrianishare
    SatchMusic	 surfin-with-the-alien.txt  concertdates.txt
    joe.bio.doc  guitar.jpg
    $
    autofs senses that an automounted share is being accessed, mounts the share immediately using information found in the /etc/auto.mbshares file, and displays the contents of the share. Once mounted, the share will be accessable in the future without remounting (and the share name will be visible under /mbshares), but will be automatically unmounted by autofs if it goes unused for more than 60 seconds (default value—you can change this).

    4. Of course, none of this works if the autofs daemon isn’t running. You can set it to autorun at boot time by adding the following line to your /etc/rc.local file:

    Code:
    /etc/init.d/autofs start
    This will cause the autofs daemon to start once all other boot processes have started, but still well in advance of that slow-to-start-up WiFi connection!

    OK, only one more point needs to be addressed. Since the automounted mount points don’t exist until the share is actually accessed, you can’t see these directory names until they’ve been accessed (and remember, they go away again after 60 seconds of inactivity). This mean that you can’t see the names when you’re using the Linpus File Manager if they’ve never been accessed (or have been, but have been automatically unmounted again). However, you can create symbolic links to these not-yet-in-existence mount points, and those links will always be visible. That way, you’ll always see a reference to the share you’re interested in, even if it hasn’t actually been mounted yet!

    Here’s how I created my symbolic links. Notice that I have them show up my home directory:

    Code:
    $ ln –s /mbshares/hendrixshare   /home/user/hendrix
    $ ln –s /mbshares/satrianishare  /home/user/satriani
    $ ln –s /mbshares/vaughanshare   /home/user/vaughan
    
    This way I can always see the three directories hendrix, satriani, and vaughan in my home directory, and the “real” directories are automounted on demand whenever I access them. And since this is all set up automatically at boot time, I never have to worry that mounts didn’t happen because of the slow establishment of my WiFi connection or because a network share went off line temporarily.

    Summary
    So, if you’re new to Linux, this is probably a lot to digest in one sitting. Here’s an overview of the overall process. The autofs daemon starts at boot time, and begins watching certain directories (/mbshares in this case) for subdirectory access activity (i.e accesses of the /mbshares/hendrixshare, /mbshares/satrianishare, or /mbshares/vaughanshare directories in this case). When one of these directories is accessed, autofs creates a mount point inside the /mbshares directory and mounts the appropriate file system as described in the /etc/auto.mbshares file. And since symbolic links were set up to those shared directories, anytime the user attempts to access one of them, the contents of the appropriate shared network directory is mounted automatically.

    More information on automounting and autofs can be found at:
    http://aisalen.wordpress.com/2007/04/26/how-to-mount-remote-windows-shares/

    More information on mounting with cifs can be found at:
    http://linux.die.net/man/8/mount.cifs

    More information on hacking the My Book World Edition II can be found at:
    http://www.mybookworldedition.co.nr/

    A great little on-line Linux resource is the Linux Cookbook, which can be found at:
    http://dsl.org/cookbook/cookbook_toc.html

    May all your mounts be successful …
     
    aspirin, Aug 10, 2008
    #1
  2. aspirin

    sbessel

    Joined:
    Aug 13, 2008
    Messages:
    25
    Likes Received:
    0
    This is perfect and worked great for a 'newbie' like myself... the only question/issue I have is when I am not on my home network where my shares are it seems to hang/timeout the file manager. Is there anyway around this?

    thanks,

    Scott
     
    sbessel, Aug 14, 2008
    #2
  3. aspirin

    hkalnes

    Joined:
    Aug 1, 2008
    Messages:
    15
    Likes Received:
    0
    Thanx for a great guide!

    One thing though: In the credentials file, I had to use the key "username" instead of just "user" to be able to access restricted shares.

    :D
     
    hkalnes, Aug 15, 2008
    #3
  4. aspirin

    aspirin

    Joined:
    Aug 6, 2008
    Messages:
    8
    Likes Received:
    0
    sbessel: Not sure about the hang/timeout problem, since nothing is really mounted (or even attempted) until you actually try and access the device in question. I take my AA1 to work all the time and don't seem to have any problem with timeout (but then again, I don't try to access those links that point to automount shares). I'll do a few experiments and if I learn anything, I'll post.

    hkalnes: Good catch on the username vs. user!

    Glad you both found the guide helpful!
     
    aspirin, Aug 15, 2008
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Thread Status:
Not open for further replies.