Prevent Automounting on macOS
With huge external drives being far more affordable these days I usually have one hooked up permanently to my laptop dock for Time Machine. But I don’t need all that space dedicated to backup, so it gets chopped up into a backup partition, an encrypted APFS storage container and a bunch of 20 GB partitions which hold a bootable macOS backup, plus a couple of recent macOS installers – just in case I end up having a really bad day.
However, in common with many Mac users I’m sure, I can’t be dealing with all that clutter on the desktop or Finder sidebar when so many partitions are mounted. What a mess! Luckily, /etc/fstab
is still a thing you can use in macOS Mojave, so there’s a quick and easy way to prevent these emergency-use volumes from mounting automatically.
First of all, plug in the drive and let everything mount, then fire off a diskutil list
in Terminal. You’ll see all of your drives and their identifiers. In my example the external drive shows up as disk2 with various partitions being disk2s1, disk2s2, etc.
andymacbookpro:~ andy$ diskutil list
/dev/disk2 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *4.0 TB disk2
1: EFI EFI 209.7 MB disk2s1
2: Apple_HFS Install macOS 10.15 ... 20.0 GB disk2s2
3: Apple_HFS Install macOS Mojave 20.0 GB disk2s3
4: Apple_HFS Install macOS High S... 20.0 GB disk2s4
5: Apple_CoreStorage Time Machine 1.4 TB disk2s5
6: Apple_Boot Boot OS X 134.2 MB disk2s6
7: Apple_APFS Container disk5 2.5 TB disk2s7
It’s easy to see which identifier matches which name, so I’d like to prevent disk2s2, disk2s3 and disk2s4 from mounting. It’s possible to do this with drive names, but it’s more robust to use the unique Volume UUID. That way you also avoid false positives.
Use diskutil info /dev/disk2s2 | grep "Volume UUID"
to get the unique ID for that volume. You should see something like:
Volume UUID: 0C097241-6DAB-304C-B6DB-3FD2CCAC9449
Do this for each of the volumes you wish to hide and copy the UUID into a text editor. Once you have them all, type sudo nano /etc/fstab
. Pop in your password and the editor will load the file, if it exists. It doesn’t by default, so you may have an empty file to work with.
For each drive, add a line like this:
UUID=0C097241-6DAB-304C-B6DB-3FD2CCAC9449 none hfs ro,noauto
Replacing the UUID with the ones from your own drive. Add them one per line; my laptop fstab file looks like this:
UUID=0C097241-6DAB-304C-B6DB-3FD2CCAC9449 none hfs ro,noauto
UUID=B27C19DE-2EF0-30DD-82B6-21F50C990BBF none hfs ro,noauto
UUID=5F1731F8-6A3D-39B6-8929-F33B4F684E05 none hfs ro,noauto
Now, eject the drive and disconnect it as normal. Plug it back in and none of the partitions you’ve added to fstab should mount.
I’ve not tried this in macOS Catalina as yet so YMMV. If you do give it a shot, zap me a tweet with the button below and let me know how it goes.