Finder showing Network Mounts

Article:
Network Mounts
Mac and Windows

Updated: November 16, 2007

This article is about mounting Windows shares on the Mac, and vice-versa - mounting Mac shares on Windows.

So what's the problem?

I wanted a simple way to make it easy to use the shared resources of my Windows and Mac computers without having to 'mentally crash gears' as I move from machine to machine. The problem's obvious. You mount a Windows share on the Mac. It shows up as /Volumes/<sharename>. On the host Windows machine, it shows up as C: and on another windows machine as K: To make things worse, it can vary from day to day when you assign the drive letters. Gosh, it isn't easy to work with this. And you have to use the GUI to create the network drives and enter the passwords. Just too tedious.

So I wanted to make it a breeze. On the Mac you simply do: mountK and the directory /K appears. On Windows you simply do: mountK and K: appears. So you can cp /K/whatever/file and not have to think about how it works. Right?

More information

Discussion Threadhttp://forums.macosxhints.com/archive/index.php/t-16189.html
Article

The objective is to create scripts to mount network shares. I have the following:

mountK   - mounts the C drive on my Windows computer as K: on Windows and /K on the Mac
mountP   - mounts the harddrive of my PowerBook as P: on Windows and /P on the Mac
unmountK - unmounts K: on Windows and /K on the Mac
unmountP - unmounts P: on Windows and /P on the Mac
In fact, I have [un]mount{H|I|K|L|P|W} for 6 different resources I use all the time. And I have the scripts installed on 5 different machines (2 Macs and 3 Windows).

  1. Mounting on the Mac
  2. Mounting on Windows
  3. Unmounting and status on the Mac
  4. Unmounting and status on Windows

1 Mounting on the Mac

Just using the mount command simply doesn't cut it. Sure it creates a mount point - however the Finder doesn't know anything about it. We want the network share K to appear in the Finder and the directory /K to work from the terminal. Easy - here's how.

#!/bin/csh
if ( ! -e /K ) then
    ln -s /Volumes/K /K
endif

ls /K/windows >& /dev/null
if ( $status ) then
    echo "/K isn't mounted.  Hang on."
    osascript -e 'mount volume "smb://domain;username:password@machine-name/sharename"'
else
    echo '/K is mounted'
endif

Now when we create the share (with the osascript command in a moment), the share actually appears on the Mac filesystem as /Volumes/sharename (in this case /Volumes/K). Not too helpful. So start by creating a symbolic link from /K -> /Volumes/K.

And now we tell the Finder to create the share with the osascript comment. This tells Finder to create the share. But first we check if it's not already mounted by looking at /K/windows. And if not, then we mount it.

There is however another complication. The sharename on Windows for the C: drive is usually "C". With Windows/XP-Pro (SP2), you can create a share with a name of your own choosing. Use K of course.

Use the following tip at your own risk: With XP/Home Edition, you don't appear to be able to assign your own name to a network share. It insists that the sharename of C: is C. I had to mess in the registry with the settings in HKLM/SYSTEM/CurrentControlSet/Services/lanmanserver/Shares. I renamed 'C' to be K and I renamed Security/C to be Security/K. And that did the trick and changed the share name to "K". The drive letter remains as "C:".

There is another way to mount the drive and get it to appear in the Finder. Use a command like this:

mkdir /Volumes/K
sudo mount_smbfs "//domainname;username:password@machinename/share" /Volumes/K && disktool -r
This does the business. However, there are a couple of drawbacks. Firstly, you have to enter the password for sudo (for which I have a workaround, which I'll explain in a moment). Secondly, having been mounted this way, it appears to be impossible to unmount it again! I think it must be 'locked' into the OS by some daemon and the command '... umount /Volumes/K' delivers the message 'Resource Busy'. By the way, I have an alias in .cshrc which sets up:
setenv PASSWORD secretmagic
alias ... 'echo $PASSWORD | sudo -S \!*'
So, I can use ... command instead of sudo command and not have to enter the password. Of course the downside of this is that my password is in the .cshrc file. However, as I work at home on my own, there's nobody snooping around to discover the password!

2 Mounting on Windows

The batch file mountK.bat on Windows is easy:

@echo off
net use K: \\machinename\sharename password /USER:domain\username

No difficulty with this. However this does create a network connection. When you're on the host machine, you may prefer to use a subst instead. I suspect this is much more efficient, however I've never bothered to investigate this.

subst k: c:\

3 Unmounting and status on the Mac

The script unmountK on the Mac is easy:

#!/bin/csh
umount /Volumes/K
We don't need to tell the finder to do it. He sees the share disappear, and removes it from the desktop and the Finder UI. Getting status is easy. For example:
df /K
df | grep Volumes
This reports the available space on all drives (and then filter to show only the shares in Volumes). You can use the script unmountAll:
#!/bin/csh
umount /Volumes/?
And finally the mountAll script to get all the network resources active at once.
#!/bin/csh
mountH
mountL
mountK
mountP
mountW

4 Unmounting and status on Windows

The batch file unmountK.bat on Windows is easy:

net use K: /delete
Of course if you used subst to create K:, then umountK.bat is
subst K: /d
I have a legal copy of the MKS toolkit installed on my Windows laptop. I like MKS a lot. This also saves a lot of 'mental gear crashing'. UNIX commands like df (disk free) work fine, detect and report the network shares. So it's obviously possible to enumerate the shares. However I don't know the DOS commands for this.

I haven't bothered to think about mountAll and unmountAll for Windows - I really haven't felt a need for this. They're probably trivial!

Comments?

I'm very happy to accept comments, feedback and suggestions for any of my articles. I'm always happy to hear you - especially if you have constructive suggestions. And I'm particularily pleased if you can let me know about corrections.


Home ......... About

Page design © 1996-2007 Robin Mills / webmaster@clanmills.com

Updated Friday November 16, 2007