Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to add a few files into a dmg. How do I create a DMG file from a directory?

share|improve this question
Could you be more precise? You can create DMG with Disk Utility, do you want something to automate it (bash scripting...)? – Loïc Wolff Apr 12 '12 at 16:07
@LoïcWolff Nope, no need to be. I didn't know that Disk Utility allowed for that. – Moshe Apr 12 '12 at 16:15
up vote 6 down vote accepted

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.
share|improve this answer
How does one create a DMG of the smallest size for the given folder? I'm referring both to the size of the .dmg file, and to the size of the filesystem when it's later mounted. If I'm compressing a 73MB folder, I'd like both of these to be 73MB + the minimal filesystem overhead. I'd also like the .dmg to be compressed, so that it takes up less space. Are these possible? I see no options for these two in Disk Utility, on Mavericks. – Kartick Vaddadi Aug 15 '14 at 14:23
What exactly do you mean by "place"? When I click and drag a folder to the newly created disk image, nothing happens. And I don't see another option for adding files. – user124384 Jul 6 '15 at 22:08

If you want to do it from the command line, you can use hdiutil like so:

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

Man hdiutil for more details.

share|improve this answer
Just what I was looking for! Made a bash script to help automate it for convenience: – Alistair A. Israel Apr 4 '13 at 7:15
accepted answer didn't work for me, this one did! – Ewout Aug 20 '14 at 15:58

On Yosemite this did it for me too.

Made a small function:

  hdiutil create -fs HFS+ -srcfolder "$1" -volname "$2" "$2.dmg"

Usage in Terminal:

dmg /My/Source/Folder NameOfDmg
share|improve this answer
You have to add where to save the function (e.g. .bash_profile) – klanomath Feb 13 at 17:03

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.