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/disk1 Apple_partition_scheme
/dev/disk1s1 Apple_partition_map
/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:
hdiutil info
Locate the name of the mounted image and note the /dev/disk entry alongside of it.
The hdiutil tool works to mount .iso and other image files as well as being able to convert them to other disk image formats.

Re unmounting. “hdiutil info” under 10.6.8 does not give me the /dev/diskname/. However, the “df” command does
good tip
…or instead of bothering with hdiutil, you could also just type the easier-to-remember “open /path/to/diskimage.dmg”.
There’s no such shortcut for unmounting though.