Skip to content

Instantly share code, notes, and snippets.

@byassine52
Forked from voltechs/no_automount
Last active February 1, 2020 12:47
Show Gist options
  • Save byassine52/dfb697bafe086585e22333f834074173 to your computer and use it in GitHub Desktop.
Save byassine52/dfb697bafe086585e22333f834074173 to your computer and use it in GitHub Desktop.
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|
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 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment