Working with hdiutil

This is more of a personal note regarding the hdiutil tool.

  • To create a sparse image:
$ hdiutil create NAME -volname NAME -type SPARSE -fs hfs+j
  • To mount the drive:
$ hdiutil attach NAME.sparseimage
  • To add data to the drive:
$ mv data.txt /Volumes/NAME
  • To unmount the drive:
$ hdiutil detach /Volumes/NAME

Then, if we delete the NAME.sparseimage file, it’s gone forever and ever.