4

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!

  • idk if whitespace is important, I only have single spaces between those elements & mine works just fine to prevent my cloned boot drive from appearing. After that, maybe double/triple-check the UUID – Tetsujin Mar 21 '16 at 9:52
  • @Tetsujin: changing each <tab> in the file to a single space solved the problem... if you write your comment as an answer I'll gladly mark it as the right one! – lexu Mar 21 '16 at 10:46
  • Ah, glad it turned out to be a simple fix. I'll write it up as an answer... – Tetsujin Mar 21 '16 at 10:52
  • I've got this chmod +x (executable) in my ~/bin/ directory. gist.github.com/voltechs/fc48c9683d50c7c03cab2f0a6477d8da – Volte Dec 30 '17 at 22:22
3

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.

  • According to the manual page for fstab is states, "Each filesystem is described on a separate line; fields on each line are separated by tabs or spaces.". Note: I added the bold highlighting on the relevant part. – user3439894 Mar 21 '16 at 12:19
  • Interesting - however, empirically, that seems to not be the case. Was that the man for Mac or nix? – Tetsujin Mar 21 '16 at 12:20
  • As a test, I just modified my existing fstab file replacing spaces with tabs and then plugged in a drive that has three partitions, two of which are set not to mount. Only the first partition mounted, as it should have, and the two that are set not to mount did not mount, even with tabs being the field separator as stated in the manual page. Note that this is under OS X 10.8.5 and maybe things have changed in OS X 10.11. – user3439894 Mar 21 '16 at 12:36
  • 1
    I've done some testing and will write up what I found in a separate answer. – lexu Mar 22 '16 at 7:54
  • 1
    "no auto" should be a single word, "noauto" in the above examples. (they might be getting interpreted in a way that works as it is, but they're not correct) – Tom Jun 16 '18 at 3:32
4

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

  • Nice bit of research. Would seem, though, that rather than trying to remember which can take tabs & which not, the safest method is to always use single spaces. – Tetsujin Mar 22 '16 at 16:40
  • 1
    I agree .. but using tabs makes the elements line up, I tend to use them were ever I can get away with it (But not in vifs/fstab, apparently :-) – lexu Mar 23 '16 at 9:43
  • These seem to be missing a field... The filesystem type (hfs, msdos, etc.) is supposed to follow the mountpoint (which is none in these examples). (See man fstab for the spec breakdown.) – Tom Jun 16 '18 at 3:40
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
  • thanks, I'll look into this after the year end celebrations! – lexu Dec 30 '17 at 22:49
  • I love answers with self running code❗️ That's self explaining 😄👍 – Yassine ElBadaoui Feb 6 at 5:00
0

On OS X 10.11.6 Whitespaces vs Tabs did not matter for me (confirmed I was using "true" tabs by viewing /etc/fstab in a hex editor and observed 0x09 for field separator byte).

I did use vifs, however, but from what I can tell that simply locks file access to /etc/fstab. Also tested with a leading newline (blank line) under file comment as well as last line of fstab containing no newline or newline (blank line under last fstab entry)

The main thing that mattered for me was:

  1. Use Volume UUID instead of Disk / Partition UUID
  2. Specifying filesystem type is crucial (lexus example lacked this)

Untested factors:

  1. no auto vs noauto (I used noauto)
  2. Text editor configured to use multiple spaces for tabs
  • 1
    Could you please expand on the 'filesystem type'. Where do I specify that? Do you know of documentation for this topic? – lexu Jul 26 '16 at 6:44
  • man fstab lists supported filesystems as well as describes various expected "tokens" (keywords). I only posted because it seemed like the behavior of fstab was broken for awhile on El Capitan, but seems to work as expected / documented as of OS X 10.11.6. – Michael Amie Jul 27 '16 at 4:50
0

The command contains a file system type to be mounted. Make sure that if you are not mounting an apple drive which is hfs, substitute this for your type, for example ntfs if its newer windows disk.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .