Mount a DMG from the Command Line in Mac OS X
A helpful command line tool called hdiutil is included in Mac OS X that allows disk image files (.dmg extension) to be mounted directly from the Terminal, without the need of using the GUI. Using hdiutil for such a task is helpful for scripting or remote connections through SSH.
Mounting a Disk Image File (DMG) from the Terminal
From the command line use the following syntax to mount the image:
hdiutil attach /path/to/diskimage.dmg
When the .dmg is mounted, a message will display something like this:
/dev/disk1s2 Apple_HFS /Volumes/Mounted Disk Image
Take note of the last entry with the name of the just mounted disk image, you will use the first part of this line to unmount the disk (/dev/disk1s2).
Unmounting a DMG from the Terminal
Recalling that the device name of the mounted image, use the following syntax to unmount the dmg:
hdiutil detach /dev/disk1s2
If you missed the device location earlier, you can retrieve information on all mounted drives and images by using:
Locate the name of the mounted image and note the /dev/disk entry alongside of it.