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

Unmount an individual disk partition System
I was trying to find a way to prevent certain volumes (partitions, in my case) from automatically mounting on startup/login. I wanted to set up a specific partition as an offline volume where I could keep a backup of certain files. The idea was to have it invisible (unmounted) to the OS, so that apps and other users couldn't modify what I had stored there, unless specifically called for (mounted).

According to The OpenDarwin FAQ, you can't pick and choose which volumes are mounted and which are not. Apparently the autodiskmountd daemon will attempt to mount any available filesystems it finds at startup. At present, there doesn't appear to be any way to modify this behavior. Disabling this daemon is probably not a good idea either, even though doing so would probably have allowed traditional methods (such as customizing /etc/fstab) to do the trick.

Read the rest of the article for the solution and more discussion on the question of unmounting just one partition of a volume.

NOTE: The discussion behind this tip is kinda long and hasn't been extensively researched. Nevertheless, it's presented here in hopes that it could provide the solution someone is looking for and that others may be able to fill in the gaps.

As the above-mentioned FAQ notes, the next best thing is to leave autodiskmount alone and explicitly unmount any unwanted volume instead. At this point, one might consider simply using the Finder to eject the unwanted volume. The problem is that the Finder's idea of unmounting a filesystem is to eject the device. So if you tried to remove a certain volume/partition from the Finder, it would happliy comply, and eject any other partitions on the same device as well!

Another line of reasoning would be to issue an unmount /Volume/unwantedvolume on startup/login. The nice thing about this method is that it relies on standard user-level tools and doesn't require modifying any files that may confuse or break things with later Apple Software Updates. And while this does appear to work, the problem is that it seems to confuse the Finder. My guess is that the Finder or some other abstraction layer needs to syncrhonize certain data structures on the volumes it sees. Thus, doing a device-level mount/unmount of volume does the trick at the BSD layer, but not for the Finder.

What I finally found was the undocumented disktool command. disktool appears to know how to cleanly mount or unmount individual partition volumes while keeping the Finder happy. The only problem is that it only works with device names, not volume names. This means that you'll need to get a particular volume's device name by issuing the df or mount command from the terminal. In my case, the the volume I wanted to unmount had the device name 'disk0s13' so I used:
  /usr/sbin/disktool -p disk0s13 0
(the zero after the device name is required). So what I ended up doing was creating a simple AppleScript:
  do shell script "/usr/sbin/disktool -p disk0s13 0 > /dev/null"
that I have set up as a login app.

  • This method is slightly cumbersome because it relies on device nodes, not volume names.

  • disktool is undocumented and may very well go away in later releases of OSX. Can someone verify whether or not disktool is part the standard release or is it part of the DevTools?

  • To mount the volume (without rebooting or re-logging in) is equally clumsy, as you need to issue the following from the command line:
      /usr/sbin/disktool -m disk0s13
    (or whatever device node you're using) and the previously-unmounted volume partition will appear in the Finder. The disktool -m command appears to block; it won't return you to the command prompt without hitting Ctrl-C, but the volume will mount fine.

  • Re-launching the Finder or restarting the autodiskmountd daemon will probably grab any volumes unmounted and make them visible again.

  • Regarding the reason for this tip: Yes, I know about mountable disk images. In most cases, if you're concerned with security and/or privacy, then encrypted disk images are probably the way to go. In my case, I just wanted a built-in storeroom with a closed door, not a portable security vault. For the ultra-paranoid, you might consider combining both methods: Keep your encrypted disk images on an unmounted partition.
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)

Unmount an individual disk partition | 14 comments | Create New Account
Click here to return to the 'Unmount an individual disk partition' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
unmounting partitions
Authored by: byronic on Jul 01, '02 10:58:25AM

I have four partitions on a single drive and accidentally unmounted one of them once while playing with my toolbar. I was customizing the toolbar and dragged the eject command to the toolbar as well as each of my partitions and hard drives for easy access from any open folder or volume window. I had a partition window open and hit the toolbar eject thinking it would open the internal drive, but it unmounted the partition. The other partitions were still accessible, and the setting stayed after I logged out and back in again. I had to use disk utility to remount the partition. I just tried this method again with the same results, but once the dock disappeared until I logged in again; I suspect this was due to a utility I installed which puts mounted volumes in the dock.

[ Reply to This | # ]
What the heck?
Authored by: derek23 on Jul 01, '02 05:51:34PM

This method would be great for me as I have been looking for a good way to hide the bootable OS 9 partitions I use for Apple Software Restore purposes. So I tried this in terminal and it worked great. Unmounted the volume. Remounted fine with -m. Made the Applescript and tried to run it and now disktool -p doesn't work at all anymore. Not saying Applescript broke it but that's the last thing I did before it stopped working. Here's what I get now:

[yellowstone:~] admin% /usr/sbin/disktool -p disk0s10 0
disk0s10 partition will attempt to be unmounted ...
***Notifications Complete for type 1
***Autoresponding yes to unmount - disk0s10
***Disk NOT Unmounted('disk0s10'), errorCode(16), dissenter(-1)
Got end signal

Any ideas?

[ Reply to This | # ]
Use hdiutil rather than disktool
Authored by: _merlin on Jul 01, '02 07:35:17PM

hdiutil is a fully documented command-line tool that can be used to do this kind of thing. To unmount your disk, you can use 'hdiutil unmount /dev/disk0s13' and to mount it again, you can use 'hdiutil mount /dev/disk0s13'. Of course, you could wire up awk to parse the output from df and automatically unmount the correct device, given a volume name...

[ Reply to This | # ]
Why not hide it?
Authored by: Arkham on Jul 02, '02 08:25:43AM

Have your tried setfile, frome the developer tools? You can make a volume invisible to the GUI (mostly) by typing

sudo /Developer/Tools/SetFile -a V /Volumes/HideMe ( note the capital "V" you have to relaunch the finder to make this effective)

The best part, is that the volume is still mounted and available to the command line and to some applications like Retrospect. More, there is a way to get to them with the goto folder command of the finder...

For me, this method has worked better...

[ Reply to This | # ]
Why not hide it?
Authored by: derek23 on Jul 02, '02 11:40:54AM

Hmm well the Finder didn't auto-relaunch (and it seems it should by your wording related to the capital "V") Force quitting the finder hid the volume. But now how do I get it back?

Any ideas why my finder didn't re-launch on it's own? Getting the volume unhid is not that big of a deal for my needs as the partition still appears in the startup disk CP.



[ Reply to This | # ]
Why not hide it?
Authored by: derek23 on Jul 02, '02 11:47:35AM

Ok using the man page I see the V specifies hidden and v gets it back. Cool. So if i could just figure out how to auto-relaunch the finder... :)

Any reason why this command wouldn't work in an applscript? Is there a better way to auto-hide a parition at login?


[ Reply to This | # ]
Can't you use Drive Setup?
Authored by: soosy on Jul 09, '02 05:10:04PM

I'm not sure about OS X's Disk Utility, but I was formatting a drive with OS 9's Drive Setup the other day and noticed that you could set an option on each partition to automatically mount or not. Perhaps you can just uncheck this option to prevent mounting on startup.

[ Reply to This | # ]
Can't you use Drive Setup?
Authored by: LC on Feb 06, '04 12:17:26PM

I think that used to work since we were in effect modifying the SCSI driver options for those devices/slices, but I might be a bit off; Larry.

[ Reply to This | # ]
ctrl-C problem
Authored by: djn1 on Aug 05, '02 04:17:34PM
/usr/sbin/disktool -m disk0s13
(or whatever device node you're using) and the previously-unmounted volume partition will appear in the Finder. The disktool -m command appears to block; it won't return you to the command prompt without hitting Ctrl-C, but the volume will mount fine.

Did you ever find out how to quit disktool without needing to enter ctrl-C? I'm using your tip to run a cron job to mount a firewire drive that I use for backup purposes and as a consequence of disktool -m refusing to quit every so often I need to manually kill the process(es). Each time it runs it leaves another occurrence of itself running. This probably isn't a big problem but it is untidy ;)

[ Reply to This | # ]
disktool self-documenting, depricated in 10.2
Authored by: darrenaddy on Sep 17, '02 08:30:46AM

Learned on the OS X Server list yesterday that you can see the documentation on disktool by typing it at the command line with no arguments.
prompt% disktools

I needed a way to open the CD door on a QuickSilver without the keyboard (disktool -o is the answer up through 10.1.5)

[ Reply to This | # ]
Unmount (perhaps spin down) a disk device
Authored by: LC on Feb 06, '04 12:42:44PM
In Panther, I wanted to manipulate the status of the internal (20GB, 4200rpm ATA) disk drive; I found that these are effective --

/usr/sbin/diskutil mountDisk disk0
/usr/sbin/diskutil unmountDisk disk0
(* stdout: *) Disk disk0 unmounted
But the "unmountDisk" (or any other unmount) doesn't spin down that drive, so this will actually spin it down:

/usr/sbin/diskutil eject disk0
(* stdout: *) Disk disk0 ejected
I suspect that mount no longer consults /etc/fstab, so we can't specify to ignore filesystems there. An entry in which file will tell autodiskmount to ignore a Volume? Larry.

[ Reply to This | # ]
Unmount (perhaps spin down) a disk device
Authored by: LC on Feb 06, '04 08:23:04PM
Uh, I noticed that diskutil depends on a bunch of frameworks including DiskArbitration. It's only usable after SystemStarter
has been executed. I even managed (by doing something dumb in the boot scripts) to provoke the dreaded --
Carbon Lazy Values Total size: 11057 bytes!
by trying to execute diskutil before the kernel extension loader service was up! (Duh;)
After SystemStarter is done, I can play with diskutil just fine; Larry.

[ Reply to This | # ]
Unmount an individual disk partition
Authored by: PCheese on Oct 17, '04 04:39:50PM
You may want to look at this topic as well.

[ Reply to This | # ]
Unmount an individual disk partition
Authored by: syzygies on Jan 18, '06 10:27:15AM

Ahh, but asking Finder to eject will eject all volumes on a physical device, not what the OP wanted. Also, even within a try block, if the Finder can't eject a volume in use, the error will hang the AppleScript.

[ Reply to This | # ]