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

  • 4
    Could you be more precise? You can create DMG with Disk Utility, do you want something to automate it (bash scripting...)? Commented Apr 12, 2012 at 16:07
  • 1
    @LoïcWolff Nope, no need to be. I didn't know that Disk Utility allowed for that.
    – Moshe
    Commented Apr 12, 2012 at 16:15

4 Answers 4


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.
  • 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. Commented Aug 15, 2014 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
    Commented Jul 6, 2015 at 22:08
  • @VaddadiKartick Choose File > New Image > Image from Folder… instead of what is stated in the answer. Commented Apr 25, 2020 at 11:35

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.

  • I really liked this option. Do you know if there's a way to exclude some directories or files within the -srcfolder ? Asking because I currently use -skipunreadable to avoid copy error Operation not permitted errors when it tries to access apple files and directories like .DocumentRevisions-v100
    – Merricat
    Commented Apr 20, 2022 at 22:24

On Yosemite this did it for me too.

Add this function to ~/.bash_profile:

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

Usage in Terminal:

dmg /My/Source/Folder NameOfDmg
  • 2
    You have to add where to save the function (e.g. .bash_profile)
    – klanomath
    Commented Feb 13, 2016 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

  • 1
    Note that recent versions of macOS — since Apple deprecated HFS+ with macOS High Sierra — have the default -fs set to APFS, so you can skip this parameter. Commented Jun 12, 2021 at 15:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .