Mount an SMB/CIFS Share via Linux Automount

I have to admit, I love thinking that others read my weblog posts, and actually find them semi-useful…but realistically, I write them to leave my increasingly feeble mind breadcrumbs for repeating tasks which are performed infrequently, and that are either complex, or poorly documented elsewhere. This post is a great example.

It is no secret that I am a Linux user. I have tasks for which I still use other platforms, but I tend to try to centralize on the platform I actually enjoy using for most major undertakings. One of my recent undertakings was creating a Mon server to monitor an enterprise. Along with service checks for network continuity, ssh, FTP, DNS, etc., I needed to be able to perform free space checks on various file systems on both Unix and Windows platforms. While manually creating static mounts for connecting to various file servers proved trivial, it required interactive work anytime the Mon server was rebooted. With many connections, this was no fun. Another option would have been to use the /etc/fstab file, and create mount entries for all of the remote file systems, but mucking with the core system mount structure bothered me philosophically, and was far less dynamic for quick directory additions. Making use of autofs for automounting of directories is much easier on the admin in all respects. Unix (NFS) file system automounting is easy. So, it turns out, is the process of automounting a Windows file system…once you remember how to do it.

Breadcrumb here:

Of course, the fundamental configuration must be in place for autofs to work. Primarily, your /etc/autfs/auto.master (or equivalent) must contain the appropriate entry for the map you intend to use. Its top-level mount point must also exist. An example of this file might look like this:

 # Sample auto.master file
 # Format of this file:
 # mountpoint map options
 # For details of the format look at autofs(8).
 /misc           /etc/autofs/auto.misc
 /home  	 /etc/autofs/auto.home
 /windirs        /etc/autofs/auto.windirs

I’m going to use /windirs as an example map for successfully automounting a share on a Windows 2000 Server. First, /windirs must exist on the machine to create the automount points below it. Then you must create entries in the /etc/autofs/auto.windirs file for the connections you wish to make. This file might look like this:

 # share1 is a share mounted to give owner permissions to uid 1000.

 share1 -fstype=smbfs,credentials=/path/to/credentials.txt,\
  workgroup=workgroup,uid=1000 ://win32server/share1

 # share2 is a share mounted giving root owner permission. Others can read.

 share2 -fstype=smbfs,credentials=/path/to/credentials.txt,\
  workgroup=workgroup ://win32server/share2

The credentials.txt file is a nifty tool to avoid placing your username and password directly in the map file. You can create the credentials file, and chmod 700 to help keep things slightly more secure. The contents of the file are simply:

 username = juser
 password = somesecretpasswordnoonewillguess

The workgroup directive is the workgroup or domain used to authenticate the user specified in the credentials.txt file for connecting to the specified server. Common sense, but worth mentioning just in case.

Cool thing about autofs…the only time when you must send a HUP to autofs is when you edit the auto.master file. Changes to any of the maps already defined in auto.master automagically are reflected under your mount points as they are made.

One last thing. I still cannot get used to the way Linux automounting works differently than automounting in Solaris. In Solaris, mount points defined in your automount maps show up as directories when you run the ls command. For instance, on Solaris, a ls of /windirs would show share1 and share2 even if they weren’t active mounts on the system. Under Linux’s automounting, /windirs shows up as empty until action is performed on share1 or share2. This action can be cd’ing into the directory, running a df command…you get the picture. This means that the best way to make sure you know what mounts you actually have available may be to create a directory full of symlinks to your automounted directories. This way you have a listing even if the mounts are not active.

Just so there’s no confusion later…this information applies directly to autofs-4.1.3 and samba-3.0.6 (specifcially, the client portion). Mileage may vary with other versions of this software set.

Ciao for now.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: