Automount shared directory on Leopard

Following my last post, here’s another handy new thing to do in Leopard. I never used this in Tiger (MacOS X.4) because it was not practical (besides being possible), but I swear it was usable by the time.
Auto-mounting remote shared server (Samba, NFS, AFS) wherever I want, without being stuck with a dead Finder.app whenever I lost wifi network, I change room or my mac goes to sleep (yep I used to have some problems with this).
So now how to do this ? NetInfo is gone so where can I define my automount points, remember when I said NetInfo is dead for the best ?

First, you should edit /etc/auto_master :

sudo nano /etc/auto_master

The stock version should looks like this :

#
# Automounter master map
#
+auto_master    # Use directory service
/net      -hosts    -nobrowse,nosuid
/home      auto_home  -nobrowse
/Network/Servers  -fstab
/-      -static

You need to add a line like this, just before /- -static. :

/my/mount/point/path    auto.smb

Where /my/mount/point/path will be the full path to the directory where remote shared folders will appears. Mine is set to /Users/_myusername_/Desktop/Shares.

Now create a new file in /etc/auto.smb :

sudo nano /etc/auto.smb

And add one line per remote folder you want to mount automatically, each line should looks like this :

www -fstype=smbfs ://username:password@remote_server_name_or_ip/shared_folder_name

www : this is the name you want to give to the remote folder locally

-fstype=smbfs : specify the kind of filesystem to use, I only cover samba here.

://username:passwordremote_server_name_or_ip/shared_folder_name@ : this is the informations to connect to the remote server. Change username and password with yours, specify remote_server_name_or_ip to reflect the way you access the machine and set shared_folder_name to the name of the remote folder.

Then set permission on the new file :

sudo chmod 600 /etc/auto.smb

Now restart automount daemon :

automount -vc

You should see your new mount point as well as stock ones :

automount: /net updated
automount: /home updated
automount: /my/mount/point/path updated
automount: no unmounts

Notice just like /etc/hosts that Leopard seems to only detect a change if a line is added/removed, so anytime you make a change that does not change the line number in the file add a comment (#) at the beginning or end to force a reload.[…]

Published on Sat, 26 Jan 2008 21:28
2 comments

Hosts aliases in Leopard

Back in Tiger days, I used to love having aliases pointing to localhost or other servers saving me some typing and allowing me to use Apache vhosts locally. To achieve this without restarting the whole system, I used NetInfo to add a new Machine entry, this works great, no restart needed only NetInfo reload.

With Leopard, NetInfo is gone (for the best) and it has been replaced by a folder hierarchy full of flat .plist files. No more NetInfo Manager, but a new dscl command and a bunch of related one : dscacheutil (lookupd replacement), dseditgroup, dsmemberutil, etc.

For today, we’ll use dscl and dscacheutil, let’s create a new Host entry to map myvhost.loc to 127.0.0.1 (I like adding .loc to distinguish my added hosts, but you’re free to use anything else) :

sudo dscl localhost -create /Local/Default/Hosts/myvhost.loc IPAddress 127.0.0.1

Then to be sure it’s looked up correctly by software (in fact it’s only needed if you tried to access the myvhost.loc before adding it) :

sudo dscacheutil -flushcache

A little handy feature of the new dscacheutil when we’re at it :

sudo dscacheutil -cachedump -entries Host

This will list all entries cached by Leopard, it can comes in handy when trying to solve a name resolution problem.

And finally if you want to get ride of your entry later on :

sudo dscl localhost -delete /Local/Default/Hosts/myvhost.loc

[Update 2008/01/07]
Benjamin Stiglitz wrote a comment to say /etc/hosts is now automatically watched for changes on Leopard, so there’s no more need to play with dscl to add simple host. Thanks again Benjamin.
[…]

Published on Sat, 05 Jan 2008 17:36
23 comments

Leopard Spaces Tips

Here’s a quick tips for those of you using Leopard Spaces functionnality. If you want to move a window from one “space” to another simply drag the window to the right/left/top or bottom edge of the screen (depending to which “space” you want to put it in) just like if wanted to put it out of the screen and wait a second.

Spaces should automaticaly switch to the next “space” and the window still be under your cursor. Drop it there or reiterate to move it to another “space”.[…]

Published on Fri, 23 Nov 2007 08:44
0 comments

RSS