How do I create a DMG file from a directory?

Some step by step instructions can be found here.

After opening Disk Utility:

  1. Click the New Image icon
  2. Place the contents of folder/directory into the newly created disk image.

If you want to do it from the command line, hdiutil will provide more control than Disk Utility over how the DMG is created. As an example, you can use hdiutil like so:

hdiutil create -volname WhatYouWantTheDiskToBeNamed -srcfolder /path/to/the/folder/you/want/to/create -ov -format UDZO name.dmg

See man hdiutil for more details.


On Yosemite this did it for me too.

Add this function to ~/.bash_profile:

dmg(){
  hdiutil create -fs HFS+ -srcfolder "$1" -volname "$2" "$2.dmg"
}

Usage in Terminal:

dmg /My/Source/Folder NameOfDmg

I ran across this just as late, and I figured I'd save some time for people.
I used this thread to make my dmg file, but I had to use the "-fs " parameter or hdiutil would error with error -5341.
Using Yosemite, I ran the following:

hdiutil create -fs HFS+ -srcfolder /Users/danlund/TestFolder/ -volname Test test.dmg