App/Script for Unmounting a Drive?

Does anyone have of know of a little executable file that you can place in your startup list that when Osx starts up will unmount a disk for you?


The reason that I ask is that I run OSx off an external RAID via tnunderbolt and do not use my imac internal drive at all. So to save wear and tear on that internal drive I would like to eject it as soon as OSx successfully loads on my RAID.


If OSx for some reason does not launch on my RAID then the script will never run and the internal imac HD with its OSx on will boot. This is exactly what I want.


Is there anyway that I can use automator to do this for me?


Can anyone help?


Steve

iMac, Mac OS X (10.7.2), 16G of RAM, Pegasus R4

Posted on Feb 25, 2012 10:00 PM

Reply
14 replies

Feb 26, 2012 6:06 AM in response to Steve McRea

No, but if you're not using the internal, wear and tear shouldn't really be an issue.

The OS is built to be always on and this would provide the least wear and tear. But many folks restart their Macs daily and I've seen no evidence that the drives brick any faster than keeping them always on.


You could also physically disconnect it, if you're handy with hardware.

Feb 26, 2012 11:28 AM in response to Steve McRea

If you never use the drive at all, then set up the fstab (file system table) file to tell the system not to mount it. the file is located at /etc/fstab, and you will add a line the looks like:


UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx none hfs rw,noauto


that's four whitespace delimited fields which mean (respectively):

  • the UUID (universal unique identifier) for the disk: read it from diskutil or from Disk Utility.app
  • the mount point for the volume (none = the default, /volumes)
  • the file system type (hfs, assuming it's a Mac-formatted disk)
  • options (r/w = read/write, noauto = the one you're after - it tells the disk mounting daemon not to mount the disk automatically at start up)

Feb 26, 2012 3:51 PM in response to Steve McRea

Does anyone have of know of a little executable file that you can place in your startup list that when Osx starts up will unmount a disk for you?


Here's a link to a little shell script you can use to mount/unmount volumes. Use it as is or as a starting point for your own variant (e.g., adapt for a specific volume name).

A bash script to mount and unmount volumes


You could encapsulate it using Automator or Platypus.

Mar 3, 2012 10:56 AM in response to rccharles

Here is a better version of my login unmount bash script:

#!/bin/sh
#disktool -e disk0s9
# example of change string.  This is change all.
# i=${diskName//" "/"\\ "}

# debug info
export PS4='+(${BASH_SOURCE}:${LINENO}):'
set -o xtrace

ls -l /Volumes

# list of disks to unmount.
disks=("classic" "Second 80" "Ext-80" "Macintosh-HD" "Ext 500")


for diskName in "${disks[@]}"; do
  echo "diskName =${diskName}="

# sometime it takes Mac OS X awhile to mount the disks.
# try four time to try to unmount each disk.
    for ((tryCount=0;tryCount<4;tryCount++))
    do
    
      diskutil unmount "/Volumes/${diskName}" | grep "Volume /Volumes/${diskName} unmounted" 
      rc=$?
      echo "rc="$rc
      if [ $rc -eq 0 ] 
      then
        echo "unmounted  i=${diskName} tryCount="$tryCount
        break
      fi
      echo "tryCount=${tryCount} when trying to unmount ${diskName}"
      sleep 8
    done
done

Jun 2, 2013 1:23 PM in response to rccharles

rccharles, I have tried it in AppleScript Editor.app on Mac with OS X 10.8.3 (Mountain Lion), but I get an error at PS4:


Syntax Error

Expected end of line, etc. but found identifier.


How to fix it? I want to use it to automatically unmount the internal hard disks of two different iMacs (work and home) when booting from an external SSD.


Thanks.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

App/Script for Unmounting a Drive?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.