Keep the following program running at all times in the background, e.g. by auto starting using launchd
:
#include <CoreFoundation/CoreFoundation.h>
#include <DiskArbitration/DiskArbitration.h>
DADissenterRef BlockMount(DADiskRef disk, void *context)
{
DADissenterRef dissenter = DADissenterCreate(kCFAllocatorDefault, kDAReturnNotPermitted, CFSTR("forbidden!"));
CFDictionaryRef description = DADiskCopyDescription(disk);
// UUID of the disk you don't want to mount:
CFUUIDRef backupDisk = CFUUIDCreateFromString(NULL, CFStringCreateWithCString(NULL, "3B5315C1-96AE-3471-B43C-2C41CDB12A64", kCFStringEncodingUTF8));
if (CFDictionaryContainsKey(description, kDADiskDescriptionVolumeUUIDKey)) {
CFUUIDRef value = CFDictionaryGetValue(description, kDADiskDescriptionVolumeUUIDKey);
if (CFEqual(backupDisk, value)) {
return dissenter;
}
}
return NULL;
}
int main (int argc, const char * argv[])
{
DAApprovalSessionRef session = DAApprovalSessionCreate (kCFAllocatorDefault);
if (!session)
{
fprintf(stderr, "failed to create Disk Arbitration session");
}
else
{
DARegisterDiskMountApprovalCallback(session, NULL, BlockMount, NULL);
DAApprovalSessionScheduleWithRunLoop(session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
while (true) {
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 60 /* seconds */, false);
}
DAApprovalSessionUnscheduleFromRunLoop(session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
DAUnregisterApprovalCallback(session, BlockMount, NULL);
CFRelease(session);
}
return 0;
}
Find out the UUID of the volume you don't want to mount using diskutil list
(to get the device name) and diskutil info
to read the UUID.
Save as main.c and compile using the following command (you need Developer Tools):
cc main.c -o mountstopd -framework Foundation -framework DiskArbitration
On Mac OS X 10.7.1, doing the following worked for me just now (pretty much identical to what's in the OS X Hint):
First, find out the device name of the volume you don't want to be mounted:
diskutil list
Partial output looks like this:
/dev/disk3
#: TYPE NAME SIZE IDENTIFIER
0: Apple_partition_scheme *2.2 TB disk3
1: Apple_partition_map 32.3 KB disk3s1
2: Apple_HFS DroboBackup 2.2 TB disk3s3
In this example, DroboBackup is the actual partition, so /dev/disk3s3
is the device we need next. Then find out its UUID:
diskutil info /dev/disk3s3
Look for Volume UUID
, e.g. 3B5315C1-96AE-3471-B43C-2C41CDB12A64
.
Then, enter the following:
sudo touch /etc/fstab
sudo sh -c 'echo "UUID=3B5315C1-96AE-3471-B43C-2C41CDB12A64 none hfs rw,noauto" >> /etc/fstab'
This will prevent the disk from mounting.