Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add volume (UUID) to fstab to prevent automount (macOS)
#!/usr/bin/env ruby
# Usage: no_automount /Volumes/My\ Disk
diskinfo = `diskutil info '#{ARGV[0]}'`.gsub("\n\n", "\n").split("\n").collect do |b|
disk_uuid = diskinfo['Volume UUID']
disk_type = diskinfo['Type (Bundle)']
disk_name = diskinfo['Volume Name']
text ='/etc/fstab')
new_contents = text.gsub(/UUID=#{disk_uuid}.*(:?\n)/, "")
new_contents << "UUID=#{disk_uuid} none #{disk_type} rw,noauto # #{disk_name}", "w") {|file| file.puts new_contents }

This comment has been minimized.

Copy link

commented Feb 6, 2019

file_name is not defined.
I fixed it here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.