Prevent a partition from mounting in OS X

If you have a specific volume on your Mac that you would like to keep from being edited when attached, here's how to protect it.

When you boot OS X or attach a hard drive, the system will automatically try to mount any available volumes so you can access or format them for use. However, there may be times when you don't wish this to happen.

For example, if you have a dual-boot setup such as OS X 10.7 on one partition and OS X 10.8 on another, then you may wish to prevent one boot volume from being easily modified and perhaps corrupted when you are in the other operating system.

Volume UUID in OS X
Running "diskutil info" on the designated volume will reveal its UUID (click for larger view). Screenshot by Topher Kessler/CNET

To do this, you will need to make use of the system's filesystem table (fstab) file, which manages special circumstances for the mounting of volumes in the system. Using the fstab file, you can set a volume to either not mount, or mount in read-only mode so it cannot be modified.

First, open the Terminal (in the Applications > Utilities folder) and type "diskutil info" followed by a single space. Then drag the desired disk to the Terminal window, and you should see a full path to it complete, so it looks something like the following command:

diskutil info /Volumes/Snow\ Leopard

Now press Enter to execute the command, and you should see a list of details about the drive. Locate the one called Volume UUID and select and copy this number.

Next, in the Terminal run the following command to edit the "fstab" file (you will be prompted for your password, which will not show when you type it):

sudo pico /etc/fstab

fstab modification in OS X
Use the UUID (red arrow) from the previous command, and then adjust the underlined options accordingly to prevent mounting or force read-only modes (click for larger view). Screenshot by Topher Kessler/CNET

When done, a small editor will show in the Terminal. Enter one of the following lines, replacing "NUMBER" with the copied UUID from the prior command. Also, the use of "hfs" in these lines indicates the drive is in Apple's HFS format, so change it to "ntfs" or "msdos" for a drive that is formatted in NTFS or FAT32:

UUID=NUMBER none hfs rw,noauto

UUID=NUMBER none hfs ro

The first of these will prevent the drive from being mounted, but if you do mount it using Disk Utility or another means, then the drive will be read and writable. The second option will make the disk be treated as read-only, but it will still show up automatically in the Finder when you start your system.

When finished with the edit, press Control-O followed by Enter to save the changes, and then press Control-X to exit the editor.

To undo these changes, simply run the "sudo pico /etc/fstab" command in the Terminal again to edit the fstab file, and delete the lines you added.



Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.

About the author

    Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.

     

    Join the discussion

    Conversation powered by Livefyre

    Don't Miss
    Hot Products
    Trending on CNET

    HOT ON CNET

    Find Your Tech Type

    Take our tech personality quiz and enter for a chance to win* high-tech specs!