Apple - How to prevent automount of a partition in El Capitan
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
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
Updated for macOS Mojave and macOS Catalina etc.
macOS Mojave 10.14 and later are more strict about editing system files.
Editing /etc/fstab
is strongly discouraged. They now what you to use vifs
. I have aggregated the info from other answers and created a bash oneliner that you can run and it will give you a list of UUID…noauto
lines that you could add for each disk. Then you have to freedom to copy the line of your choice and then use sudo vifs
and paste it in the file safely.
mount | sed -E '/\dev\/disk/!d; s/^([^ ]+)[^/]*([^(]+) \(.*/\1:\2/' | while read mount_info; do echo -e "\n\nDisk ${mount_info%%:*} is mounted at ${mount_info##*:}" >/dev/stderr; sudo diskutil info ${mount_info%%:*} | grep UUID | tee /dev/stderr | printf '# To prevent auto mount of this disk, add the following line to `sudo vifs`\tUUID=%s none rw,noauto\n\n' $(sort| head -n1 | sed 's/.*: *//;s/ *//g;') | sed 's/.*UUID= .*/<no UUID found>/' | tr '\t' '\n'; done
That's a monster oneliner, I don't want to bore you with an explanation of what it does. (But if I get a request in the comments I will update this.)
Here is an example run:
$ mount | sed -E '/\dev\/disk/!d; s/^([^ ]+)[^/]*([^(]+) \(.*/\1:\2/' | \
while read mount_info; do
echo -e "\n\nDisk ${mount_info%%:*} is mounted at ${mount_info##*:}" >/dev/stderr;
sudo diskutil info ${mount_info%%:*} | grep UUID | \
tee /dev/stderr | \
printf "$(echo \
'# To prevent auto mount of this disk, add the following line' \
'to `sudo vifs`\tUUID=%s none rw,noauto\n\n'
)" $(sort| head -n1 | sed 's/.*: *//;s/ *//g;') | \
sed 's/.*UUID= .*/<no UUID found>/' | \
tr '\t' '\n'
done
Disk /dev/disk1s5 is mounted at /
Volume UUID: 066AF3CD-C098-4D28-9C3A-AD6C53A443ED
Disk / Partition UUID: 066AF3CD-C098-4D28-9C3A-AD6C53A443ED
# To prevent auto mount of this disk, add the following line to `sudo vifs`
UUID=066AF3CD-C098-4D28-9C3A-AD6C53A443ED none rw,noauto
Disk /dev/disk1s1 is mounted at /System/Volumes/Data
Volume UUID: 760B55A4-3E55-4FFA-B22D-B48F0D227EEB
Disk / Partition UUID: 760B55A4-3E55-4FFA-B22D-B48F0D227EEB
# To prevent auto mount of this disk, add the following line to `sudo vifs`
UUID=760B55A4-3E55-4FFA-B22D-B48F0D227EEB none rw,noauto
Disk /dev/disk1s4 is mounted at /private/var/vm
Volume UUID: B6011DF2-6391-4E5C-9A94-D73FF9AB51DC
Disk / Partition UUID: B6011DF2-6391-4E5C-9A94-D73FF9AB51DC
# To prevent auto mount of this disk, add the following line to `sudo vifs`
UUID=B6011DF2-6391-4E5C-9A94-D73FF9AB51DC none rw,noauto
Disk /dev/disk1s3 is mounted at /Volumes/Recovery
Volume UUID: 14EDD79D-0EDA-42B0-A1C4-7B025159146B
Disk / Partition UUID: 14EDD79D-0EDA-42B0-A1C4-7B025159146B
# To prevent auto mount of this disk, add the following line to `sudo vifs`
UUID=14EDD79D-0EDA-42B0-A1C4-7B025159146B none rw,noauto
Disk /dev/disk2s1 is mounted at /Volumes/Install macOS Mojave
Volume UUID: B14957BD-83D2-3A36-A828-89CF03C7F45A
# To prevent auto mount of this disk, add the following line to `sudo vifs`
UUID=B14957BD-83D2-3A36-A828-89CF03C7F45A none rw,noauto
Disk /dev/disk3s2 is mounted at /Volumes/TM Backup
Volume UUID: 5E0A580C-2894-3529-9B52-3E33BD10DF53
Disk / Partition UUID: 22D06480-5187-48BD-9079-D95D34B0494E
# To prevent auto mount of this disk, add the following line to `sudo vifs`
UUID=22D06480-5187-48BD-9079-D95D34B0494E none rw,noauto