How to prevent automount of a partition in El Capitan

There are two boot partitions on my MacBook. A working, bootable, El Capitan is installed on both.

How can I prevent automounting partition2, when booting from partition1?

According to many pages I found via google this is done by editing fstab via vifs an adding the line

UUID=uuid_of_partition2_here       none    hfs     rw,noauto

But that doesn't work! The partition is mounted anyway!


Solution 1:

It appears that the syntax must use single spaces, not tabs, to be recognised by the system.

This would fall in line with many command line processes; the only exception that springs to mind is the hosts file, which can use any amount of whitespace.

That would make the correct syntax

UUID=uuid_of_partition2 none hfs rw,noauto

rather than

UUID=uuid_of_partition2       none    hfs     rw,noauto

... subtle but important difference.

Solution 2:

Tetsujin and user3439894's comments and observations prompted some testing.

Turns out, there is more than one UUID when you look at drives and partitions and the 'diskutil list' command doesn't report the UUID that needs to be used in the vifs/fstab commands.

  root %> diskutil info disk1 | grep -e UUID

Shows that there are Volume, Disk / Partition, LV,LVF and LVG UUIDs .. I'm only interested in the first two!

When I enter diskutil list I get the "Disk / Partition UUID", when I enter diskutil info disk1 I get both the "Disk / Partition UUID" and the "Volume UUID" (and more ..) I also get the "Volume Name" (the disk label)

Some tests I performed with the Volume - UUID and the disk label indicate:

  • the UUID in vifs/fstab is the "Volume UUID", don't use tabs!
  • the UUID command in vifs/fstab doesn't work with the "Disk / Partition UUID", tab/space makes no difference here
  • when using the "LABEL" syntax, don't use tabs!

Here are the two examples I got to work:

UUID=<Volume UUID><SPACE>none<space>rw,noauto

LABEL=<Volume Name><SPACE>none<space>rw,noauto

You can find the <Volume UUID> and the <Volume Name> of your internal disk by running

diskutil info disk1 | grep -e "Volume\ Name" -e "Volume\ UUID"

On my system the external disk-info shows up for disk2s1 and disk3s1

Solution 3:

These are all great (and correct) answers!

I thought I'd share a small script/utility that I use to make this easier.

I've got this no_automount file executable in my ~/bin/ directory. (Don't forget to chmod +x it!)

https://gist.github.com/voltechs/fc48c9683d50c7c03cab2f0a6477d8da

#!/usr/bin/env ruby

# Usage: no_automount /Volumes/My\ Disk

diskinfo = `diskutil info '#{ARGV[0]}'`.gsub("\n\n", "\n").split("\n").collect do |b|
    b.strip.split(/:\s+/)
end.to_h

disk_uuid = diskinfo['Volume UUID']
disk_type = diskinfo['Type (Bundle)']
disk_name = diskinfo['Volume Name']

fstab_filename = '/etc/fstab'
text = File.read(fstab_filename)

new_contents = text.gsub(/UUID=#{disk_uuid}.*(:?\n)/, "")
new_contents << "UUID=#{disk_uuid} none #{disk_type} rw,noauto # #{disk_name}"

File.open(fstab_filename, "w") {|file| file.puts new_contents }

After using the script, if you sudo vifs you'll see something like this (mine looks like this).

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

UUID=51C2250E-9CE4-1953-8AF6-3EEDD46F594D none ntfs rw,noauto # Windows 10
UUID=7E55582C-6D91-4148-28C6-208D03071164 none ntfs rw,noauto # Windows Storage
UUID=CF294178-3B0D-4B23-AC72-24D10AAC6735 none ntfs rw,noauto # Windows Games