I called

 file file.dmg

and got the message zlib compressed data. I extract the dmg file with 7z:

7z x file.dmg

and then I create a directory test mount the hfs file

mount -t hfsplus -o loop 4.hfs test

then I modify the data and add few files and want to build later a new dmg file with my modified data, but how?

  • How about: genisoimage -D -V "Volume Label" -no-pad -r -apple -o <dest.dmg> <src>.
    – harrymc
    Feb 25, 2019 at 10:31
  • But if I run file it returns test.dmg: ISO 9660 CD-ROM filesystem data 'Volume Label'.
    – ikreb
    Feb 25, 2019 at 20:46
  • It's probably an uncompressed dmg.
    – harrymc
    Feb 26, 2019 at 10:31

2 Answers 2


Below are some references that I found for creating a dmg file (but have no experience with).


The libdmg-hfsplus repository, which includes a number of portable libraries and utilities that manipulate the HFS+ file system and DMG images, is still in its experimental stage, so it doesn’t contain any utility that allows building Apple’s DMG images from scratch, but can convert an ISO file.

The following commands were found in the article How to Build DMG Files for Windows-Based Applications on Linux, to build from source using a forked version of the library:

    sudo apt-get install gcc
    sudo apt-get install g++
    sudo apt-get install cmake
    sudo apt-get install zlib1g-dev
    sudo apt-get install genisoimage
    git clone https://github.com/hamstergene/libdmg-hfsplus.git
    cd libdmg-hfsplus
    cmake .

The resulting program will be found in dmg/dmg and can be used like this:

    # Generates IMG disk image with the help of genisoimage
    genisoimage -D -V "SetMeitClient" -no-pad -r -apple -file-mode 0777 -o generated.img original && \
    # Converts IMG into DMG ($dmgPath is the path that points to the DMG utility)
    dmg generated.img generated.dmg

github create-dmg

This open-source project is described as :

A shell script to build fancy DMGs.

I found testimonies in several places saying that it does the job.


This open-source project requires npm and is described as:

Generate beautiful DMG-images for your OS X applications.

There are also testimonies for its working well.

  • Thank you very much! Very good answer!
    – ikreb
    Mar 5, 2019 at 11:50
  • A bit too late for the bounty.
    – harrymc
    Mar 5, 2019 at 11:58
  • Sorry, but I thought you got the points.
    – ikreb
    Mar 5, 2019 at 12:51
  • See superuser.com/help/bounty
    – harrymc
    Mar 5, 2019 at 13:39
  • Boot your favorite version of Mac OSx using your favorite Hypervisor.
  • Mount the DMG
  • Using Disk Utility, make a copy of the DMG that is writable.
  • Unmount the original DMG
  • Mount the new writable copy.

Now you can use the mounted DMG like any other filesystem: copy, delete, rename, whatever you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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