Skip to content

Instantly share code, notes, and snippets.

@windwiny
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save windwiny/9726e9827fcb7fc340aa to your computer and use it in GitHub Desktop.

Select an option

Save windwiny/9726e9827fcb7fc340aa to your computer and use it in GitHub Desktop.
osx make memory disk
#!/usr/bin/env ruby -w
# OSX 创建内存盘
puts '================================================================'
cmd="hdiutil attach -nomount ram://1048576"
puts ">>> #{cmd}"
new_disk=`#{cmd}`
new_disk.strip!
puts new_disk
puts '================================================================'
cmd="newfs_hfs -v RamDisk#{new_disk[-1]} #{new_disk}"
puts ">>> #{cmd}"
puts `#{cmd}`
tmp_dir=''
['','2','3','4','5','6'].each do |i|
tmp_dir="/tmp/ttt#{i}"
if !File.directory?(tmp_dir) && !File.file?(tmp_dir)
Dir.mkdir(tmp_dir)
break
end
end
puts '================================================================'
cmd="ls -ld #{new_disk} #{tmp_dir}"
puts ">>> #{cmd}"
puts `#{cmd}`
puts '================================================================'
cmd="mount -t hfs #{new_disk} #{tmp_dir}"
puts ">>> #{cmd}"
puts `#{cmd}`
puts "\n\n\n DESTROY RAMDISK COMMAND !!!"
puts '================================================================'
cmd="DESTROY: hdiutil detach #{new_disk}"
puts cmd
cmd="RMDIR: rmdir #{tmp_dir}"
puts cmd
puts '================================================================'
__END__
# # create
# hdiutil attach -nomount ram://1048576
# newfs_hfs -v RamDisk1 /dev/disk1
# mkdir /tmp/ttt
# mount -t hfs /dev/disk1 /tmp/ttt
#
# # destroy
# hdiutil detach /dev/disk1
# rmdir /tmp/ttt
----
# # create
# hdiutil attach -nomount ram://1048576
# newfs_exfat /dev/disk1
# mkdir /tmp/ttt
# mount -t exfat /dev/disk1 /tmp/ttt
#
# #destroy
# hdiutil detach /dev/disk1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment