Unmount a volume at startup

Jun 14, '05 09:31:00AM

Contributed by: bdm

I have a second disk inside my G4 desktop, but don't want users to see it when they log in. So I want to unmount it at system boot time. Here is one way; maybe someone will tell us a simpler way. An earlier hint does something similar during login, but this one does it for all users during startup. Here's how:

  1. Find out what the device name is (using Disk Utility for example). I'll assume it is /dev/disk0s5.

  2. As root, create a directory named Unmount in /Library/StartupItems/, containing two files (Unmount and StartupParameters.plist, as shown below). Use any name in place of Unmount, but make sure to use the same name twice.

  3. Set protections and ownerships like this:
    
      drwxr-xr-x   root  wheel   Unmount
      -rwxr-xr-x   root  wheel   Unmount
      -rw-r--r--   root  wheel   StartupParameters.plist
    
  4. Reboot to see if it works!
Read the rest of the hint for the two scripts...

The file Unmount is a shell script (change disk0s5 to whatever your device name is):

  #!/bin/sh
  . /etc/rc.common
  if [ "$1" == "start" ]
  then
     /usr/sbin/diskutil unmount /dev/disk0s5
  fi
The file StartupParameters.plist is a properties list:
   <?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" 
     "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
   <plist version="1.0">
   <dict>
        <key>Description</key>
        <string>Try to unmount the old disk</string>
        <key>Provides</key>
        <array>
              <string>Unmount</string>
        </array>
   </dict>
   </plist>
I tested it on 10.4 but it should work from 10.2 an onwards, at least.

Comments (21)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2005052804075538