-
-
Save jiatongwu/9990a57065996f9ccacc5b5c58132558 to your computer and use it in GitHub Desktop.
Add volume (UUID) to fstab to prevent automount (macOS)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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'] | |
| text = File.read('/etc/fstab') | |
| new_contents = text.gsub(/UUID=#{disk_uuid}.*(:?\n)/, "") | |
| new_contents << "UUID=#{disk_uuid} none #{disk_type} rw,noauto # #{disk_name}" | |
| File.open(file_name, "w") {|file| file.puts new_contents } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment