Categories
Tutorials

Preventing a volume from automatically mounting in OS X

Heads up! This is a really old post that will contain outdated info for modern macOS!

In a previous post I mentioned that I was going to install Snow Leopard on a smaller, separate partition. After doing this, I realized that both partitions were going to be mounted when I booted into either operating system – Leopard or Snow Leopard. I wanted to prevent Spotlight from trying to index the files on both as I’d have duplicate entries for files and applications. I tried to disable indexing the Snow Leopard partition from the Leopard in Spotlight’s preferences, but for some reason this configuration was stored universally meaning Snow Leopard would also exclude its own partition and only include Leopard’s. The best thing to do at this point was to keep the partitions from being mounted at the same time, and as separate as possible.

Before we start I must say I don’t recommend anyone who may be slightly scared of the Terminal, “vi”, and or possibly really screwing something up to do this. If you have access to a nerd who knows what they’re doing, I suggest you grab them. I’m not responsible for any hosed systems.

To keep any partition from automatically mounting in OS X do the following:

1. In Terminal, run “sudo vifs”

Why we run this:

The command “sudo” just means run the command after it (in this case “vifs”) as another user, namely root – so that we can make changes to files regular users normally wouldn’t have access to.

The command “vifs” is a utility to safely edit the “/etc/fstab” file – the configuration file we’re going to tell to not mount our partition. The “vi” part is actually from the fact that we’re using the text editor “vi” to change our file.

2. Add the entry of the partition you want to keep from mounting

If the file “fstab” in /etc/ didn’t already exist, vifs will generate it for you. If it did already exist and there were entries, you’ll see them listed. Most users will just see this:

#
# Warning - this file should only be modified with vifs(8)
#
# Failure to do so is unsupported and may be destructive.
#

What we want to do now is add our entry. This can be tricky for people who aren’t familiar with the wonderful world of the vi text editor. Move the cursor down to the last line (with the down arrow key or by pressing shift+G) and then go to the end of that line (by pressing the right arrow or ‘)’). Press ‘i’ and hit the right arrow over one, then press enter to create a new line. At this point you should be able to type text on a new line.

Here’s an example entry of what we’ll put on that line:

UUID=12A4B6C8-1A3B-1C3D-6E8F-123456789876 none hfs rw,noauto

There are four parts to each entry we need to supply: partition, mount point, file system type, and options. All of the things you can do in fstab are way beyond the scope of this article. Running “man fstab” will give you plenty of information if you need to do something different.

In OS X one way to get the UUID for the partition is to go to Disk Utility, right-click on the partition you want to prevent from being automatically mounted, and select “Information”. From there you will be able to copy the “Universal Unique Identifier” line. Pasting it into our Terminal window is as simple as right-clicking and selecting “Paste”.

“none” simply means we’re not giving it a location to mount – this will be handled automatically by OS X.

“hfs” is the type of file system we’re dealing with. Since my partition was a Mac OS Extended (Journaled) type, this is what I used. If the partition is another type, this must match what type it is. This information is also explained in “man fstab” and many places on the web.

“rw,noauto” is our options. “noauto” tells OS X not to automatically mount the partition.

After you’ve added your line, your Terminal should look close to this:

#
# Warning - this file should only be modified with vifs(8)
#
# Failure to do so is unsupported and may be destructive.
#

UUID=12A4B6C8-1A3B-1C3D-6E8F-123456789876 none hfs rw,noauto

To save our file and quit hit “esc”, then type “:wq” and press Enter. If something went wrong and you want to exit vi without making any changes, type “:q!” instead.

Reboot to test this out and you should be good to go. If you want to, check out your system logs in Console to make sure there weren’t any fstab errors.