19

I am trying to prevent 2 volumes from mounting at startup.

I created a new fstab using vifs and added the UUIDs of the volumes I don't want to mount at system startup, but for some reason this does not seam to work in High Sierra. Both volumes will mount as usual.

Any idea what's missing?

The following syntax is what i used -

UUID= none apfs rw,noauto

0

4 Answers 4

12

To prevent a volume from automatically mounting you need to know the filesystem type and either the volume name or volume UUID. This information can be found by using the Terminal application command diskutil info name, where name is the volume name. For example, volume names can be found under Devices in the sidebar of a Finder application window.

On my computer, the output from the command diskutil info "Macintosh HD" is given below.

   Device Identifier:        disk2s1
   Device Node:              /dev/disk2s1
   Whole:                    No
   Part of Whole:            disk2

   Volume Name:              Macintosh HD
   Mounted:                  Yes
   Mount Point:              /Volumes/Macintosh HD

   Partition Type:           41504653-0000-11AA-AA11-00306543ECAC
   File System Personality:  APFS
   Type (Bundle):            apfs
   Name (User Visible):      APFS
   Owners:                   Disabled

   OS Can Be Installed:      Yes
   Media Type:               Generic
   Protocol:                 Disk Image
   SMART Status:             Not Supported
   Volume UUID:              F21AD81B-B114-456C-B2A0-BF4452E4842D
   Disk / Partition UUID:    F21AD81B-B114-456C-B2A0-BF4452E4842D

   Disk Size:                1000.0 MB (999981056 Bytes) (exactly 1953088 512-Byte-Units)
   Device Block Size:        4096 Bytes

   Volume Total Space:       1000.0 MB (999981056 Bytes) (exactly 1953088 512-Byte-Units)
   Volume Used Space:        3.4 MB (3416064 Bytes) (exactly 6672 512-Byte-Units) (0.3%)
   Volume Available Space:   996.6 MB (996564992 Bytes) (exactly 1946416 512-Byte-Units) (99.7%)
   Allocation Block Size:    4096 Bytes

   Read-Only Media:          No
   Read-Only Volume:         No

   Device Location:          External
   Removable Media:          Removable
   Media Removal:            Software-Activated

The pertinent lines are shown below.

   Volume Name:              Macintosh HD
   Type (Bundle):            apfs
   Volume UUID:              F21AD81B-B114-456C-B2A0-BF4452E4842D

Note: You can not use the Disk / Partition UUID, except when the Disk / Partition UUID is the same as the Volume UUID.

Either of the lines given below could be added to the /etc/fstab file to prevent this volume from automatically mounting.

UUID=F21AD81B-B114-456C-B2A0-BF4452E4842D none apfs rw,noauto
LABEL=Macintosh\040HD none apfs rw,noauto

Note: The character sequence \040 is just the octal representation of the space character.

9
  • Your fundamental error in the 1st version was: APFS containers don't accept HFS/HFS+ volumes. So far only APFS volumes are supported...
    – klanomath
    Dec 30, 2017 at 1:52
  • 1
    I've used the method you outlined here many times for non-APFS volumes, but it doesn't seem to work for me using APFS volumes on Mojave. I have an external SSD with two APFS volumes (1 container) and I only want one of them to mount automatically. Regardless of whether I add the Volume UUID or the label (or both), every time I plug in the device, both volumes mount. Any suggestions?
    – parzival
    Mar 15, 2019 at 1:23
  • 2
    APFS volumes on Mojave fail for me (nothing happens) if I use UUID. Referring to the same volume by its device name (e.g. /dev/disk3s3) works fine. Seems bugged. Apr 19, 2019 at 21:02
  • @AmmoGoettsch could you provide an example? I don't seem to get this working using LABEL= or UUID= for device name.
    – riorben
    May 25, 2019 at 20:36
  • @riorben correct, I cannot get it to work with LABEL or UUID either, so I use the device name itself. I am currently running with two lines in my fstab. The first one keeps MacOS disk utility from mounting my drive to the default /Volumes/volumename, and the second one allows me to mount it to a specific location via 'sudo mount -a'. It does not process the second line automatically on start up though, so I still have to mount it via login script. LABEL=volumename /Users/username/Pictures apfs rw 0 2 /dev/disk3s3 /Users/username/Pictures apfs rw 0 2 May 26, 2019 at 17:34
8

EDIT 2: Unfortunately after upgrading to Big Sur, this no longer is sufficient. You also have to edit /etc/fstab and add:

UUID=[put UUID of volume here] none auto noauto

EDIT: After more testing, it appears the ONLY change needed is to add the "D" for Data flag to the APFS volume. /etc/fstab changes are not needed.

I've changed the text below to show this.


I got this to work on APFS volumes in macos Catalina 10.15.2 - I can't confirm if this works on earlier versions. This also does not apply to HFS as far as I know.

Suppose your volume name is TestVolume, and the device path is /dev/disk2s4. You can get both of these from the output of

diskutil list

The device path is /dev/[IDENTIFIER].

You need to modify the apfs volume meta-data flags for this volume. I found I had to add the "D" flag for which stands for "Data". Without this flag, the volume is still mounted automatically on boot even with the correct fstab line added.

diskutil apfs changeVolumeRole /dev/disk2s4 D

Again, change /dev/disk2s4 to YOUR volume. After doing both of these things, the volume no longer attempts to mount itself. You will have to use Disk Utility to mount the volume or the command line.

You can confirm that the metadata flag has been set by typing:

diskutil apfs list

You're looking for the line that says:

APFS Volume Disk (Role):   disk2s4 (Data)
2
  • macOS Catalina 10.15.6 - this solution worked for me. Thank you! Aug 30, 2020 at 18:33
  • On macOS 11.5.2, my time machine disk got ejected so I wanted to do a file system check. It would not really unmount like it should. I set the disk as Data and added the line to /etc/fstab, used Disk Utility (app) to repair the volume, then removed /etc/fstab and set the type back to Time Machine (T).
    – pedz
    Aug 24, 2021 at 18:30
2

I had this problem on Mojave and it seems nothing solves the combination of APFS and automatic mounting of volumes.

However, if you have an encrypted volume, it is possible to disable the prompting for the volume password which keeps the volume from being mounted.

The part that does the prompting for the password is the file bundle:

/System/Library/CoreServices/SecurityAgentPlugins/DiskUnlock.bundle 

If you disable SIP (System Integrity Protection), you can rename the file to something else, e.g. DiskUnlock.bundlexxx and you will no longer be prompted for a password. (SIP can be re-enabled after the change.)

DOWNSIDES include that no encrypted volume will be mountable via the GUI (including using the Disk Utility).

The only way to unlock an encrypted volume is through diskutil or by storing the passphrase in the system Keychain.

You can mount encrypted volumes with something like:

$ diskutil apfs unlockVolume [Volume GUID here] -passphrase [Passphrase here]

The volume ID is obtained with the output from:

diskutil apfs list
....
+-- Container disk3 XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX [ignore the GUID here]
====================================================
APFS Container Reference:     disk3
Size (Capacity Ceiling):      5000771321856 B (5.0 TB)
Capacity In Use By Volumes:   577949696 B (577.9 MB) (0.0% used)
Capacity Not Allocated:       5000193372160 B (5.0 TB) (100.0% free)
|
+-< Physical Store disk2s2 XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX [ignore the GUID here]
|   -----------------------------------------------------------
|   APFS Physical Store Disk:   disk2s2
|   Size:                       5000771321856 B (5.0 TB)
|
+-> Volume disk3s1 XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX [ <---HERE IS THE GUID YOU WANT]
    ---------------------------------------------------
    APFS Volume Disk (Role):   disk3s1 (No specific role)

The passphrase is whatever you picked for the password for the encrypted volume.

Also, if you saved a password for the volume in the system Keychain, you'll need to remove it using the Keychain Access utility.

There is a tool that avoids having to type these commands manually:

Semulov on Github

2
  • 2
    Deleting/renaming system files is a Very Bad Idea. Aug 5, 2020 at 17:02
  • I agree. But if you want the system to do thy bidding, it is sometimes necessary. Especially on Macs. Oct 2, 2021 at 5:41
0

I found a script that does this nicely. I've just don it on my iMac running 12.5 just updated today. So it works with the current version. As there is no /etc/fstab I simply did "su touch /etc/fstab" first, then created this script, and ran it with my name "Macintosh HD" that I want permanently unmounted.

As in '~/bin/no_automaount Macintosh\ HD'

I also created the bin directory in my home directory. Out of sight and out of mind...

I'm booting off an external Crucial X8 SSD. https://akrabat.com/prevent-an-external-drive-from-auto-mounting-on-macos

Thanks to Rob Allen's DevNotes for the excellent very well-commented script.

You must log in to answer this question.

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