Browsing the Windows network with your linux machine with automatic mounting and discovery of all hosts and shares.

Want to support HowtoForge? Become a subscriber!
 
Submitted by stefbon (Contact Author) (Forums) on Mon, 2007-08-27 13:18. :: Linux | Samba | Storage

The most recent version you'll find at:

http://linux.bononline.nl/linux/automountsmbshares/index.php

Index

  • 1. Introduction and Summary

Introduction

For some time I've been looking for a good way to let my computer discover the Windows network and mount shares on demand. There isn't a good enough solution for at this moment. After trying the kioslaves in the desktop of my choice (KDE) and the FUSE programs Fusesmb and SmbNetFs, I was not really satisfied. There had to be an way to let my computer discover all the workgroups/domains, the hosts and the shares, and mount a share on a hosts on demand. Some will say: mount the shares of your choice by hand, and off you go. But no!! This is not what I want. I can let my computer discover automatically discover all the hosts and shares available, and mount the share only when needed. This should be possible! And after trying I've found out it is!

The following issues are necessary imho:

  • automatic discovery of the SMB network (domains, hosts and shares)
  • building of a representation which makes sense to the users logged in their homedirectory
  • automatic mounting of shares on demand
  • automatic unmounting of shares after some time unused
  • use of a kernel fs like SMBFS or CIFS
  • independent of a Desktop Manager
  • support of other networkservices like SSH and FTP

 

The FUSE program Fusesmb comes very near to what I'm looking for, but lacks the extended capabilities CIFS has, like the right presentation of the permissions, support of inotify, symlink and ATTR/ACL. It took me some time to find out why the FUSE program lacks these features. FuseSMB is based upon the smbclient library smbclient.so, which is part of the Samba package, and has nothing to do with smbfs or cifs.

The result

The result of this construction is a networkrelated directory (Global Network) in your homedirectory, where the automounter provides a browseable tree to access all the supported networkservices.

At this moment it supports the services SMB and SSH (I'm working on FTP). Accessing the "network mountpoint":

/home/sbon/Global Network/
                        SSH hosts
                        Windows Network

Accessing the Windows Network (==smb), all the workgroups and/or domains appear:

/home/sbon/Global Network/
                        SSH hosts
                        Windows Network
                           BONONLINE
                           CWWERKGROEP

Entering the workgroup CWWERKGROEP, all the servers and other hosts do show up:

/home/sbon/Global Network/
                        SSH hosts
                        Windows Network
                           BONONLINE
                           CWWERKGROEP
                              ROUTER
                              PC1

Entering the server ROUTER, the shares available to the connecting user appear:

/home/sbon/Global Network/
                        SSH hosts
                        Windows Network
                           BONONLINE
                           CWWERKGROEP
                              ROUTER
                                 cwdocumenten
                                 public
                                 sbon

Accessing a share, it's automatically mounted (with CIFS or SMBFS). The use of credentials is supported, guest logins are the default.

To build the "multi mount map" for the smb service, a networkcache is used. It provides information about workgroups and/or domains. hosts and server and shares available. It is maintained by some scripts, which make use of some utilities (nbtscan to determine the hosts and workgroups/domains and smbclient to determine the shares per host).

Accessing the SSH hosts (=ssh), all the hosts where this user has access to appear:

/home/sbon/Global Network/
                        SSH hosts
                           192.168.0.2
                        Windows Network

Here no cache is used to create this tree, but the file .known_hosts. Futher there was no mount.sshfs available. I've created one, using FUSE and sshfs. (and umount.sshfs).
Now when accessing the host 192.168.0.2, the root on 192.168.0.2 is mounted.

How does it work

This construction makes use of the automounter. When an user logs in, and a new session starts, a "networkmountpoint" to the auto.master file is added and the automounter daemon gets a "reload" signal.  This mountpoint, name default "Global Network" is in the homedirectory of the user. Linked to it is a script (auto.network) which creates a map, based on all the networkservices supported and resources discovered. Together with the browse option, this provides a browseable map, where shares/hosts are mounted when accessed.

When the user logs off, and thus the session ends, the mountpoint is removed again, and the automounter daemon gets a reload signal again to make the changes effective.

Here the ability of KDM to run scripts with root privilege at the beginning and the end of a session is used.

At this moment only SMB and SSH are supported.

Known issues

There are some bottlenecks:
- when a share is added, a host goes offline or anything else changes in the smb environment, it takes some time when it's also visible in the cache. This cache is maintained through some script, which work with a "pull" based mechanism. Second, the automounter does not detect by itself that the data in the cache has changed. It only renews it own data (the multi mount map) after a timeout, and even then it does noet completely gets all the changes.
- the automounter is instructed to present a browseable mount map. This means that the toplevel directories are always available. This is a very good thing, the available networks are always visible and accessible to the user, even after a timeout. In practice sometimes one of the "network services" disappears...
- the automounter has some problems when starting with an empty auto.master file (and empty includes). At boottime, when there are no user logged in, and thus no autofs managed network mountpoints, the automounter has to be started with an empty map.

Links

Accessing windows or samba shares using autofs

a guide to setup autofs for SMB shares, using existing files;

Integrating Your Linux Host into a Windows Environment

a guide to setup autofs to access shares in an alternative way.

HOWTO Automount filesystems (AUTOFS) / udev with autofs

Here almost the same construction is used to mount hardware using autofs with udev. Here also mountpoints are dynamically added and removed to the auto.master file.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.