How do I prevent automatic mounting of all the partitions on a flash drive?

I have a flash drive that I use for various diagnostics on macs. Most of the partitions on the drive are accessible by holding down the option key on boot. I also have one extra partition that is not bootable and used strictly for diags after the macs OS has loaded. My challenge is finding a way to not mount all the option boot partitions when trying to use the non bootable one.

Any ideas? Thanks


Solution 1:

Borrow a trick from Apple - set the partition type to something besides Apple_HFS. The Apple_Boot partition type is used by Lion Recovery, and should provide the exact behavior you want. This process is NOT for the faint-of-heart, and you should definitely have a backup. If any of this process is unclear, DO NOT DO IT. Note that all numbers and drive names will be different on your computer.

First, determine which "BSD disk" your target drive is. Very likely disk1, but not necessarily. For example, this is my current system:

bash-3.2$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *120.0 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh SSD           119.2 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *320.1 GB   disk1
   1:                        EFI                         209.7 MB   disk1s1
   2:                  Apple_HFS Secondary HD            319.7 GB   disk1s2

What follows is a copy-paste-edit job from Dmitry Dulepov:

We need to change the type of this partition. This involves noting partition parameters, deleting and creating a patition with gpt. Firsts, let find out parameters:

bash-3.2$ sudo gpt show disk1
         start       size  index  contents
            0          1         PMBR
            1          1         Pri GPT header
            2         32         Pri GPT table
           34          6
           40     409600      1  GPT part - C12A7328-F81F-11D2-BA4B-00A0C93EC93B
       409640  246725744      2  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
    247135384     262144
   247397528    1269528       3  GPT part - 48465300-0000-11AA-AA11-00306543ECAC
    248667056    1402591
    250069647         32         Sec GPT table
    250069679          1         Sec GPT header 

Next, delete and add the partition. Note that we use values found on the previous step.

bash-3.2$ sudo gpt remove -b 247397528 -s 1269536 -t 48465300-0000-11AA-AA11-00306543ECAC disk1
disk0s3 removed
bash-3.2$ sudo gpt add -b 247397528 -s 1269536 -t 426F6F74-0000-11AA-AA11-00306543ECAC
disk0 disk1s3 added

Notice the different GUID. That is important because it tells OS X the type of the partition.

Check if everything is ok:

bash-3.2$ diskutil list disk1

You should see what had previously been an Apple_HFS partition should be listed as Apple_Boot. Such partitions are bootable on an Intel Mac without being auto-mounted by a running system. Repeat this general process with each partition that you want to "hide" normally.