Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Unmount a volume at startup System
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.
    •    
  • Currently 1.60 / 5
  You rated: 1 / 5 (5 votes cast)
 
[29,576 views]  

Unmount a volume at startup | 21 comments | Create New Account
Click here to return to the 'Unmount a volume at startup' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Unmount a volume at startup
Authored by: g00ner on Jun 14, '05 11:19:36AM

I'm a total noob with scripts and alike, but this is just what I need to un-mount my firewire drive, could you tell me how I create a shell script?

I've tried so far and can't get it working so I must be doing something basic wrong?

g00ner.



[ Reply to This | # ]
Unmount a volume at startup
Authored by: adrianm on Jun 14, '05 02:20:28PM
To become root (effectively), in Terminal, do:

sudo -s
and enter your password (assuming you are an adminstrator user)

To create a shell script (or indeed any text file), it might be easiest to use this (built-in and easy to use):


pico filename
to change directory:

cd dirname
That's basically it.

Although if you are unsure of how to create a shell script, you may not know that becoming root enables you to do scary damage to your Mac, so be careful!

[ Reply to This | # ]

Unmount a volume at startup
Authored by: laurencewilks on Jun 14, '05 02:22:03PM
I'm no expert with disks via the command line but I think this line:

/usr/sbin/diskutil unmount /dev/disk0s5

actually unmounts the partition s5 on disk0

To unmount the disk use:

/usr/sbin/diskutil unmountDisk /dev/disk0

To remount a disk use:

/usr/sbin/diskutil mountDisk /dev/disk0

A good place to understand how this works is:

man diskutil

[ Reply to This | # ]
Unmount a volume at startup
Authored by: bdm on Jun 14, '05 09:40:02PM

Yes, you are completely right. My extra disk has only one partition so for me it made no difference, but in general unmountDisk should be used. Your observation also lets us note that individual partitions can be unmounted (or mounted for that matter) at startup by this method. -- Brendan.



[ Reply to This | # ]
Use /etc/fstab
Authored by: jkhong on Jun 15, '05 12:52:40AM

See these:
1. http://www.macosxhints.com/article.php?story=20040716153639236
2. Man page for fstab

Coming from a Linux background (just got my first taste of OSX last week), I'm wondering if /etc/fstab might do the job better:

According to the manual (type "man fstab" in terminal):
The option ``auto'' can be used in the ``noauto'' form to cause a file
system not to be mounted automatically (with ``mount -a'', or system boot
time).

So a line like:

/dev/disk0s5 /Volumes/NAME_OF_PARTITION hfs noauto,rw 1 2

in your /etc/fstab file should tell the system not to auto mount the partition.

*You may also need to tell NetInfo about it, using something like:
$ sudo niload -m fstab / < /etc/fstab

* (Not sure what or why this is needed, definitely not Linux) This came from http://www.macosxhints.com/article.php?story=20040716153639236
It's an excellent tip on partitioning on OSX.



[ Reply to This | # ]
WARNING Use /etc/fstab
Authored by: jkhong on Jun 15, '05 01:52:27AM

Please read TigerKR's comments (below) before trying the /etc/fstab method. There may be problems with this.



[ Reply to This | # ]
Use /etc/fstab
Authored by: valexa on Jul 24, '10 08:39:14AM
you should use the partition's UUID instead of it's device description to make things less risky as the description can vary
UUID=4236231D-1117-333F-8899-3235F9B8000 /Volumes/NAME_OF_PARTITION hfs noauto,rw 1 2
instead of
/dev/disk0s5 /Volumes/NAME_OF_PARTITION hfs noauto,rw 1 2
to get the UUID do:
diskutil info /dev/disk0s5

[ Reply to This | # ]
Unmount a volume at startup
Authored by: TigerKR on Jun 15, '05 12:58:23AM

A word of caution:

You have absolutely no assurance that what was /dev/disk1s2 (for example) one day will still be /dev/disk1s2 the next time you boot.

Character device description files (such as /dev/rdisk0s10) are created at boot time and do not survive a shutdown. Unless the boot volume is a CD, disk0 should contain the boot volume, but all other numbers cannot be assumed to remain stable.



[ Reply to This | # ]
Unmount a volume at startup
Authored by: jkhong on Jun 15, '05 02:04:28AM

Hi TigerKR, thanks for taking the time to caution users about the potential problems with /etc/fstab and changing device ids. I found your comments describing the issue deeper to be very helpful.

Other readers might want to read up TigerKR's comments describing the situation.



[ Reply to This | # ]
Unmount a volume at startup
Authored by: jitterbugboy on Jun 15, '05 03:49:27PM

assuming that the drive numbers are dynmaic, you can unmount using the partition name like this

/usr/sbin/diskutil unmount /Volumes/Emergency/

where Emergency is the name of a partition I would rather unmount.



[ Reply to This | # ]
Unmount a volume at startup
Authored by: bdm on Jun 15, '05 07:33:54PM

It is not true that disk0 is always the boot disk. Mine is disk1 right now. I'm guessing that the startup code assigns numbers in some sort of hardware order: my two internal hard disks are numbered in the order that they appear on the ATA bus and the numbering was constant over many restarts. However, you are right in that we shouldn't assume anything not clearly documented. The solution is to use the mount point name, as jitterbugboy suggested. So the diskutil line in the original hint can be changed to

/usr/sbin/diskutil unmount "/Volumes/Whateveritscalled"

I knew there were possible solutions using fstab and similar, but fiddling with things like that will just give trouble at the next OS upgrade.

Brendan.

[ Reply to This | # ]
Unmount a volume at startup
Authored by: TigerKR on Jun 15, '05 11:56:07PM

You're absolutely right. Looking now at df my boot drive is /dev/disk2s12



[ Reply to This | # ]
Unmount a volume at startup
Authored by: g00ner on Jun 18, '05 06:11:08AM

Many thanks for this tip guys it works well.

After reading through this thread and looking at the 'man diskutil' commands in Terminal I've now modified the script slightly by using 'eject' rather than 'unmountDisk'. This works better for me as It now also stops my LaCie FW drive's fan (which is noisier than my G4 MDD!)

Many thanks for all the info.

g00ner.



[ Reply to This | # ]
Unmount a volume at startup
Authored by: TigerKR on Jun 15, '05 01:04:16AM
Also, Panther doesn't mount non-IDE drives until the user logs in (and then unmounts them when the user logs out). I'm not sure about Tiger.

If you're using non-IDE drives, in the terminal, type:

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


[ Reply to This | # ]
Unmount a volume at startup
Authored by: balserj on Jun 24, '05 09:14:42PM

Do you know if "non-IDE" applies to RAID volumes like fibre channel or SCSI devices?



[ Reply to This | # ]
Unmount a volume at startup
Authored by: TigerKR on Jul 05, '05 02:09:03AM

Yes, Fibre and SCSI are certainly non-IDE.



[ Reply to This | # ]
Unmount a volume at startup
Authored by: derekhed on Aug 02, '05 01:41:06PM

Thanks, I was looking all over for this information. This works great for me as I have drives I don't want unmounted every time I log out of the GUI.

I haven't tried this on 10.4 yet, but will need this same functionality.



[ Reply to This | # ]
Automatically mounting non-ide volumes at startup
Authored by: boote on Dec 29, '05 08:34:05AM

Nice hint! I've been trying to find a reasonable way to have my firewire drive mounted at system startup for some time. (I have been using fstab, but this is better because I don't have to worry about device numbers changing.)

Where did you find this information? I have dug through a fair amount of the automount information and I did not find this setting. (I'm wondering where I can find other gem's like this!)



[ Reply to This | # ]
always mounting all volumes at startup
Authored by: BjarneDM on Apr 08, '09 03:13:58AM

This works under 10.5 Leopard as well with a APPLE_HFSX mirrored RAID1 consisting of two Iomega MiniMax 1TB external HDs



[ Reply to This | # ]
Unmount a volume at startup
Authored by: TigerKR on Jul 05, '05 02:22:10AM

My setup is this: 3 Devices (1 Firewire, 2 SCSI), the Firewire device has only one volume, and each SCSI device has 3 volumes each.

I would like to unmount one volume from each SCSI device at login. I will create a Platypus App to execute a simple SH script. Then I will add this App to my Login Items in the Accounts PrefPane in System Preferences.

Here is Platypus' link:

http://www.macupdate.com/info.php/id/12046

Download and install Platypus (its free).

Launch Platypus.

Input your App Name (I used UnmountVolumesLogIn), then click on "New" underneath the script path area. Paste the following text (change MyVolume1):

###########

#!/bin/sh
diskutil unmount /Volumes/MyVolume1
exit

###########

Then click "Save"

Then click "Create" and save the App to wherever you desire.

Then add your new app to the login items in the accounts prefpane, and restart.



[ Reply to This | # ]
Unmount a volume at startup
Authored by: TigerKR on Jul 05, '05 02:28:20AM

You many need to add this line to your sh script:

sleep 1

And you also may need to be an administrator user to unmount volumes.



[ Reply to This | # ]