Skip to content

Instantly share code, notes, and snippets.

@erikdoe
Last active February 9, 2020 11:24
Show Gist options
  • Save erikdoe/1b501bccc87bdf43e457a8a6dfbf672f to your computer and use it in GitHub Desktop.
Save erikdoe/1b501bccc87bdf43e457a8a6dfbf672f to your computer and use it in GitHub Desktop.
Mounts the EFI partition of the disk identified by the search string
#!/usr/bin/env ruby
search = "*1.0 TB"
efimnt = "/Volumes/EFI"
def run(cmd, &block)
puts "** #{cmd}"
if block == nil
system(cmd)
else
return IO.popen(cmd, &block)
end
end
def efi_dev(lines, search)
disk = nil
lines.each do |line|
match = /#{Regexp.escape(search)}.*(disk[0-9])/.match(line)
if match
disk = match[1]
end
end
slice = nil
lines.each do |line|
match = /EFI.*#{disk}(s[0-9])/.match(line)
if match
slice = match[1]
end
end
return "/dev/#{disk}#{slice}"
end
run("mkdir #{efimnt}")
efidev = run("diskutil list") { |out| efi_dev(out.readlines, search) }
puts "found #{efidev}"
run("mount -t msdos #{efidev} #{efimnt}")
run("open #{efimnt}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment