PDA

View Full Version : How to auto-mount USB disks attached to an Airport Extreme




parish
Jul 28, 2012, 08:53 AM
I found this thread (https://discussions.apple.com/message/10511740?messageID=10511740#10511740?messageID=10511740) which explains how to have USB disks attached to an AEBS auto-mount at login.

I created this script in AppleScript Editor

mount volume "afp://heathrow._afpovertcp._tcp.local/Iomega_HDD"
mount volume "afp://heathrow._afpovertcp._tcp.local/TimeMachine"
mount volume "afp://heathrow._afpovertcp._tcp.local/Vaults"

and added it to my Login Items - but the disks don't mount.

I've confirmed that the commands are correct as if I run it from the AppleScript Editor, the disks all mount correctly.

The original thread was related to doing this on Leopard. Why should it not work on ML?



btbrossard
Jul 28, 2012, 08:55 AM
What about just adding the disk to the log in items?

The "Remote Disk" is connected to the Airport Extreme.

parish
Jul 28, 2012, 09:36 AM
What about just adding the disk to the log in items?

The "Remote Disk" is connected to the Airport Extreme.

Yes, that works, but as it mentions in the link I posted, a Finder window opens for each mount, which is doubly annoying because there is quite a delay before it happens so you're in the middle of typing an e-mail when 3 Finder windows pop-up on top.

btbrossard
Jul 28, 2012, 10:32 AM
You could also use Automator to build an application that mounts the requested server volumes.

I just created one to mount two server volumes on my network, and using Automator doesn't open finder windows when it runs at startup.

parish
Jul 28, 2012, 04:56 PM
You could also use Automator to build an application that mounts the requested server volumes.

I just created one to mount two server volumes on my network, and using Automator doesn't open finder windows when it runs at startup.

Thanks, that works but since it's in Login Items it only works when I log in so the volumes don't remount when waking from sleep. Is there anyway to make this (or another) script run when on wake from sleep?

brand
Jul 28, 2012, 05:37 PM
There are apps in the Mac App Store that will do this. Look there.

Don Kosak
Jul 28, 2012, 07:17 PM
I think mrichmon's answer a few years back is exactly what you're looking for to totally automate this in the background without any of the issues you're facing with other solutions.

I'm just going to quote his (her) answer below:


You need to do two things:

create an fstab entry, and
set the automounter to run during system boot.


Set up fstab
The OS X fstab entry is almost identical to the linux fstab format. However, since you are talking about external drives then you need to use a unique identifier to identify the drive rather than the device id. The problem with using the device id (eg. /dev/disk2) is that any changes in the connected devices (adding or removing an external drive, adding a hub, etc) can change the order in which the devices are enumerated and thus changing the device id (eg. from /dev/disk2 to /dev/disk3 if you add a new drive).

An OS X fstab should look like:

# Fsck Pass Number
# |
# Dump Flag |
# | |
# Mount Options | |
# | | |
# Filesystem | | |
# | | | |
# Mount Point | | | |
# Filesystem Identifer from diskutil | | | | |
# | | | | | |
UUID=4236231D-1117-333F-8899-3235F9B8000E none hfs rw,auto 1 2

Where the fields in order are:

first field is the unique device id,
second field is the mount point. That is, where you want the device to mount such as /mounts/mydisk -- in this case "none" is specified with causes the drive to default to the /Volumes/<filesystem name> mount point,
third field is the filesystem type,
fourth field is the mount options,
fifth field is the dump flag, and
sixth field is the fsck pass number.


To find the UUID for a particular drive you should open the terminal and run mount without any arguments to list the mounted filesystems and identify the device node for your external drive. The device node will be something like /dev/disk1s3. Ensure that the device you identify is for your external drive and not your internal drives. Now, using the device node you found, run the command diskutil info <device node> to obtain the UUID. For example, if your device node is /dev/disk1s3 then you run the command diskutil info /dev/disk1s3. In the list of information printed you will see a long UUID string. This is the UUID you need to use in your fstab file instead of the traditional device node entry.

Setting up a /etc/fstab file will ensure that drives will mount with your specified options when they are automounted. But an additional step must be performed to ensure that the automounter mounts the drives when the system boots.

Set automounter to run
Under OS X by default, external drives are only mounted when a user logs into the system on the console. Other systems such as linux and Solaris typically mount drives during system boot. This means that if you ssh into OS X then your external drives will not be mounted until someone logs into the console.

To change this default behavior you need to set a property on the system to ensure that the automounter runs when the system boots. To do so, open a terminal window and run the following command:


sudo defaults write /Library/Preferences/SystemConfiguration/autodiskmount AutomountDisks


You'll probably want to look into Mac's fstab format a bit for guidance on substituting your AFP path in instead of using the UUID=xxxx-yyy-zzz format.

This is the way to go, and how we manage mounting various network shares in general at boot time.

- Don

parish
Jul 29, 2012, 06:18 PM
I think mrichmon's answer a few years back is exactly what you're looking for to totally automate this in the background without any of the issues you're facing with other solutions.

I'm just going to quote his (her) answer below:

Ah, so OS X does look at /etc/fstab? I'm familiar with it from the Unix world, but there is no such file in OS X (at least on my system) so I assumed that it isn't used.

So, is it a case of if it exists then it gets read and the contents executed, but the boot/system disk is mounted without needing an entry in /etc/fstab?

You'll probably want to look into Mac's fstab format a bit for guidance on substituting your AFP path in instead of using the UUID=xxxx-yyy-zzz format.

This is the way to go, and how we manage mounting various network shares in general at boot time.

- Don

So you recommend using afp:// rather than the UUID?

Don Kosak
Jul 29, 2012, 09:37 PM
Yeah,

The line in his "step 2" causes Mac OS X to look at /etc/fstab after it's finished mounting the disks it normally mounts (system, firewire, usb, etc.)

sudo defaults write /Library/Preferences/SystemConfiguration/autodiskmount AutomountDisks

A network drive won't have a UUID (only directly connected drives do.)

The regular command line mount command for an AFP share looks like:

mount -t afp afp://username:password@server.local/directory mountpoint

where:
'username' is the authorized user for the share (if you have one)
'password' is the password (again, if you have one)
'server.local' is the name of the server, it can be an ip number instead.
'directory' is the name of the afp shared directory
'mountpoint' is the local path to where you're connecting the share.

An example:
mount -t afp afp://don@timecapsule/files /Users/don/tc-files

I think you can do the same thing inside your fstab file, although you need to use the fstab format shown by mrichmon. Something like:

afp://don@timecapsule/files /Users/don/tc-files afp rw,auto 1 2

I hope this helps.

Don Kosak
Jul 29, 2012, 10:52 PM
Actually, I found a much more definitive post that had full examples of using /etc/fstab for afp (airport/timecapsule) mounted disks.

http://www.kristijan.org/2010/11/automount-afp-shares-in-osx/

They have an example of an /etc/fstab line of:

192.168.0.109:/Media /Users/kristijan/Media url automounted,url==afp://kristijan:fakepass@192.168.0.109/Media /Users/kristijan/Media 0 0

And also point out that you can use the "sudo automount -vc" to test your /etc/fstab file without rebooting.

parish
Jul 30, 2012, 07:08 AM
Actually, I found a much more definitive post that had full examples of using /etc/fstab for afp (airport/timecapsule) mounted disks.

http://www.kristijan.org/2010/11/automount-afp-shares-in-osx/

They have an example of an /etc/fstab line of:

192.168.0.109:/Media /Users/kristijan/Media url automounted,url==afp://kristijan:fakepass@192.168.0.109/Media /Users/kristijan/Media 0 0

And also point out that you can use the "sudo automount -vc" to test your /etc/fstab file without rebooting.

Don, that's great. Thanks for you help :)

I'm away for a week now so won't be able to try it until I get back.

parish
Jul 30, 2012, 07:01 PM
@Don

Had time to do this before I went away, but there are a couple of problems with the stuff you quoted:

Firstly, the sudo defaults write ... command is truncated; it should be:

sudo defaults write /Library/Preferences/SystemConfiguration/autodiskmount AutomountDisksWithoutUserLogin -bool true

Secondly, in the second link you posted, the /etc/fstab entry in that tutorial is wrong; he includes the mount point a second time, immediately before the dump flag - took me ages to spot it, but once I had, and removed it, it worked fine.

The only problem with using the automounter is that the remote disks don't show up as mounted in Finder and if you click on them, Finder creates a second mount with `-1` appended to the mount point, e.g. Vaults-1, so you have the same share mounted twice on different mount points which I don't believe is a good thing. Hmm, more investigation needed I think...

Don Kosak
Jul 30, 2012, 07:44 PM
Awesome. Sounds like you made a lot of progress.

I may fiddle around with this a little myself. Right now I'm mounting NFS shares via /etc/fstab, and it seems to work a little different.

I didn't spot the 2nd mount point in the afp example from Kristijan either. You've got good eyes.

We're creating a great reference thread for others here. I hope we can work out the kinks.

Mrichmon used a mount point of "none" in his example. I wonder if that was to avoid the double mounting problem. Automounter is supposed to mount requested drives on demand using the info in /etc/fstab.

I'll post if I figure something out that makes this work better.

hafr
Aug 3, 2012, 11:29 AM
I've got a somewhat different problem... My iTunes library is located on an external drive which is connected to my Airport Extreme Base Station, and if I wake the computer from sleep via ATV - I never log on and I can't play anything on my ATV since the drive is not mounted until logon.

Would trying to follow the steps discussed here help me with having the drive mount (or not unmount as the computer goes to sleep)?

parish
Aug 10, 2012, 12:56 PM
OK, I'm back from my travels to foreign parts and have looked into this more.

This statement I made turns out not to be the case...

The only problem with using the automounter is that the remote disks don't show up as mounted in Finder and if you click on them, Finder creates a second mount with `-1` appended to the mount point, e.g. Vaults-1, so you have the same share mounted twice on different mount points which I don't believe is a good thing. Hmm, more investigation needed I think...

Firstly, they won't show as mounted in Finder until you click on them. That is the whole point of the automounter; it's a daemon that only performs the actual mount on demand, i.e. when something attempts to access the drive, such as clicking on it in Finder.

As for the duplicate mounts (with '-1' appended to the mountpoint name) this is not happening now, although it definitely was when I was playing around before. What I think happened to cause this was that I was testing multiple methods - AppleScript, Automator, and /etc/fstab - and if the disks had been mounted using AS or Automator, then unmounted in Finder, and remounted using the /etc/fstab entries via sudo automount -vc then the duplicates occurred, probably because the AS (or Automator) "held" the mountpoints (i.e. they still existed in /Volumes, even though nothing was mounted on them) thereby preventing the automounter using them.

Once I'd disabled the AS and Automator, and rebooted, everything works as expected. So, the /etc/fstab is the way to go.

Hope this helps :)