OS X: Hiding and Mounting a Partition

In the OS 9 days, there was a low-level disk setting that told the disk whether or not it should automatically mount.  OS X does not have this option and, like many good things in the system, it relies on old-school Unix.

I actually use this trick fairly often (and, it can be considered an adjuct to my August 2006 MacTech column "GUI up Your Script).  It's great to be able to clone the system disk, and then 'hide' it.  The benefit of this is that if the primary drive fails, a cloned disk will just boot, without the operator knowing what happened.

To make sure a partition is 'hidden' or doesn't mount at start up, here's what you need to do.  For argument's sake, let's say we need to hide the "StuC_HD_Backup" partition:

1. We need to find the UUID for the disk.  We can only get that via the slice number, so, we get that first:

# diskutil list
  #:                  type name              size      identifier
  0: Apple_partition_scheme                    *76.7 GB  disk0
  1:    Apple_partition_map                    31.5 KB  disk0s1
  2:              Apple_HFS StuC_HD            76.6 GB  disk0s3
  #:                  type name              size      identifier
  0: Apple_partition_scheme                    *279.5 GB disk1
  1:    Apple_partition_map                    31.5 KB  disk1s1
  2:              Apple_HFS StuC_HD_Backup    139.6 GB  disk1s3
  3:              Apple_HFS backup2            139.6 GB  disk1s5

Great!  Stu_C_HD_Backup is "disk1s3"

2. Now, let's get the UUID:

# diskutil info disk1s3
  Device Node:        /dev/disk1s3
  Device Identifier:  disk1s3
  Mount Point:     
  Volume Name:        StuC_HD_Backup

  File System:        Journaled HFS+
  Owners:            Disabled
  Partition Type:    Apple_HFS
  Bootable:          Is bootable
  Media Type:        Generic
  Protocol:          ATA
  SMART Status:      Verified
  UUID:              CDCDFBA1-EF2C-39FA-998B-94C63B8F23E1

  Total Size:        139.6 GB
  Free Space:        0.0 B

  Read Only:          No
  Ejectable:          No
  Device Location:    "B (lower)"

Note the "UUID" line.  Copy the UUID value.

3. Edit /etc/fstab - the "File System Table".

This file may not exist, so, you'll be creating it from scratch.  You can read the fstab man page for more info, but the idea is this: the system looks to this file to gather mount options for disks.  Since OS X doesn't guarantee assigning the same device id to the same disk each boot, we need to tell the system to use the same mount options for a particular UUID.  The option we need to pass is the 'noauto' flag.  Here's the /etc/fstab entry for the disk in question:

# fstab
# Created 28 March 2006
# Ed Marczak

# Identifier, mount point, fs type, options, dump order, check order
UUID=CDCDFBA1-EF2C-39FA-998B-94C63B8F23E1 none hfs rw,noauto 0 0

4. Reboot, and you'll see that the partition in question hasn't mounted.

It's not 100% 'hidden', though.  You can still use Disk Utility.app, or diskutil in the shell, to see the presence of the disk and mount it.  Short of removing the disk from the system, you can't entirely conceal it.  This is good, though.  Remember when I mentioned the use of this disk as an ASRed clone?  WIth a script, you can automatically mount this hidden partition, update the files on it (so it's current with the master) and unmount it.  Here's the two lines that get you there in a script:

theDisk=`diskutil list | awk '/Backup/ {print $NF}'`
diskutil mount $theDisk

Here, we're searching for the disk by name, since we won't know much else about it beforehand.  With a little more intelligence, you can write a full-featured script that backs up the master disk with error checking, and more importantly, very little effort on the part of the end-user.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Panther way

Panther users... simple way to get the UUID-

Unmount, then remount the volume in question, and you will see the UUID spelled out clearly in system.log

The easiest way to get the

The easiest way to get the UUID is to select the disk in Disk Utility, and hit the "Info" button. The disk identifier, UUID, and all sorts of other info are in there.

I know its hard to fight spam, but you should have a more streamlined way to post comments!