Skip to content

Instantly share code, notes, and snippets.

@shokai
Created August 5, 2011 06:48
Show Gist options
  • Save shokai/1127041 to your computer and use it in GitHub Desktop.
Save shokai/1127041 to your computer and use it in GitHub Desktop.
mount ramdisk on Mac OSX
#!/usr/bin/env ruby
mount = '/Volumes/ramdisk'
newfs = '/dev/disk1'
if !ARGV.empty? and ARGV.first =~ /^-+u$/i
system "umount #{mount} && hdiutil detach #{newfs}"
else
if File.exists? newfs
STDERR.puts "already mounted - #{mount}"
STDERR.puts "use \"#{$0.split('/').last} -u\""
exit 1
end
size = 200000
size = ARGV.first.to_i if !ARGV.empty? and ARGV.first =~ /^\d+$/
puts "mount RAM #{size*512} bytes"
Dir.mkdir mount unless File.exists? mount
system "hdid -nomount ram://#{size} && newfs_hfs #{newfs} && mount -t hfs #{newfs} #{mount}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment