Laurent Pertois’s useless blog

March 2, 2009

Detecting mount points in Mac OS X

Filed under: Mac OS X — lolopb @ 12:58
Tags: , ,

Mac OS X comes with an automounter for volumes. This is great but unfortunately this can be a nightmare to manage in scripts if you need to access a specific volume using its path. But, using UUIDs we can find precisely a volume and its mountpoint even if the volume name changed.For this we’re gonna take the use of rsync as a support for our demonstration.

In a simple setup, rsync can be used to synchronize data between two volumes using something as simple as this :

rsync -aE --delete / /Volumes/BigVolume

We synchronize everything from the root volume to a volume called “BigVolume”.

This is great and will work as long as our volume “BigVolume” is mounted as /Volumes/BigVolume.

But there can be some problems if, for any reason, you mount a second volume that is also called “BigVolume”. In that case, the automounter will mount the firs “BiVolume” as /Volumes/BigVolume and the second one as /Volumes/BigVolume 1. If you wanted to synchronize on the second one, it won’t happen, your sync will go on the first one.

Even worst, if, for any reason, someone renames the volume to something else, rsync will in fact copy your data in a folder called “BigVolume” inside /Volumes.

We need to find a reliable way to discover where the volume is mounted by the automounter (autofs, by the way, in Mac OS X v10.5.x).

For this, we’re gonna use a unique identifier that is associated to any volumes, the UUID.

You can discover that UUID using Disk Utility or its command-line equivalent diskutil :

$ diskutil info /Volumes/BigVolume
Device Identifier: disk2
Device Node: /dev/disk2
Part Of Whole: disk2
Device / Media Name: Apple read/write Media

Volume Name: BigVolume
Mount Point: /Volumes/BigVolume
File System: Journaled HFS+
Journal size 8192 KB at offset 0x3000
Owners: Disabled

Partition Type:

Bootable: Not bootable
Media Type: Generic
Protocol: Disk Image
SMART Status: Not Supported
Volume UUID: 37635406-5BB1-36E9-85A6-74E5BCC45006

Total Size: 10.0 Mi (10485760 B) (20480 512-byte blocks)
Free Space: 1.7 Mi (1830912 B) (3576 512-byte blocks)

Read Only: No
Ejectable: Yes
Whole: Yes
Internal: No
OS 9 Drivers: No
Low Level Format: Not Supported

The interesting elements is this line :

Volume UUID: 37635406-5BB1-36E9-85A6-74E5BCC45006

Each volume is assigned a UUID which is generated for each volume.

Using this information we can find where our volume, whatever is the name, is stored, for example, with the same volume as before we can use this command :

$ diskutil info 37635406-5BB1-36E9-85A6-74E5BCC45006 | grep "Mount Point" | awk '{ print $3 }'
/Volumes/BigVolume

As we can see, our volume is mounted in /Volumes/BigVolume.

Now, what if I rename this volume as “BigVolume2”, well, immediately the mountpoint is modified :

$ diskutil info 37635406-5BB1-36E9-85A6-74E5BCC45006 | grep "Mount Point" | awk '{ print $3 }'
/Volumes/BigVolume2

But using the UUID, I could find it without having to check all volumes to discover which one is the good one.

So, instead of hard coding the path in your rsync script, you should first search the mountpoint of your volume.

Of course, if you change the name of the volume during the synchronization, you’re done, be careful…

Advertisements

3 Comments »

  1. This utility overwrites your data thirty-five times,
    scrambles the original file name, and truncates the file size to
    nothing before Permanent Eraser finally unlinks it from the
    system. One therefore needs to keep formatting and re-formatting
    the i – Pod while switching from Mac to Windows etc. I would greatly consider purchasing a new netbook just for this OS as I am on the
    internet more than 8 hours per day and would
    benefit greatly from a quick loading internet based operating system.

    Comment by Install Snow Leopard on PC — July 22, 2013 @ 8:40 | Reply

  2. You’re so interesting! I don’t believe I’ve read through a single thing like that before. So nice to find somebody with genuine thoughts on this issue. Seriously.. many thanks for starting this up. This website is one thing that’s needed on the internet,
    someone with a little originality!

    Comment by Georgia — July 29, 2013 @ 4:00 | Reply


RSS feed for comments on this post. TrackBack URI

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

Blog at WordPress.com.

%d bloggers like this: