How to build a dmg Mac OS X file (on a non-Mac platform)?

MacosInstallationDmg

Macos Problem Overview


Is it possible to build a .dmg file (for distributing apps) from a non-Mac platform? And if yes, how?

Macos Solutions


Solution 1 - Macos

Yep, mkfs.hfsplus does it.

dd if=/dev/zero of=/tmp/foo.dmg bs=1M count=64
mkfs.hfsplus -v ThisIsFoo /tmp/foo.dmg

This creates a dmg file (in this case 64M) that can be mounted on a mac. It can also be mounted on linux, with something like

mount -o loop /tmp/foo.dmg /mnt/foo

after wich you just copy the content you want to it (in /mnt/foo). Unmount it, and the dmg can be copied over to a mac and mounted there.

Solution 2 - Macos

A project I work on creates DMG files on Linux using genisoimage:

mkdir -p dmgdir/progname.app/Contents/{MacOS,Resources}
...copy your PkgInfo, Info.plist to Contents...
...copy your .icns to Resources...
...copy your other things to where you expect them to go...
genisoimage -V progname -D -R -apple -no-pad -o progname.dmg dmgdir 

If you want to be really fancy, you can steal the .DS_Store file from a DMG made on a Mac with a volume name progname and app bundle called progname.app (i.e., matching what you want to create off the Mac) where you've put a background in .background/background.png and a symbolic link to /Applications in the root dir, and put that in dmgdir along with your own a symbolic link to /Applications.

Finally, if you want to create a compressed DMG, get the dmg tool from libdmg-hfsplus:

dmg uncompressed.dmg compressed.dmg

Solution 3 - Macos

git clone https://github.com/hamstergene/libdmg-hfsplus
cd libdmg-hfsplus && cmake . && make && cd dmg
./dmg --help

Makefile:

dmg:
    genisoimage -D -V "$(PROJECT) $(VERSION)" -no-pad -r -apple -o project-$(VERSION)-uncompressed.dmg $(DARWIN_DIR)
    ./dmg dmg project-$(VERSION)-uncompressed.dmg project-$(VERSION).dmg

uncompressed works out of the box, compression may cause problems - the origin/master at least produces a 'checksum' error on snow-leopard

Solution 4 - Macos

It does seem possible to create DMG files with some third party tools. A quick google search reveals at least a few commercial tools:

Not sure about any OSS/freeware options, but it does at least seem possible if you are so inclined.

Edit: I also forgot about MacDrive, which is another great tool for working with HFS+ filesystems under windows. Since a DMG is basically just a HFS+ filesystem snapshot, it is probably possible with MacDrive to create DMG's as well.

Solution 5 - Macos

I'm not sure if anyone is still watching this thread, but I tried TransMac as recommended by Nik Reiman.

Using this tool I was able to, running on Windows 7, create dmg files which were mountable on OSX 10.8.3.


Downside

The only downside for us is that this tool doesn't appear to be command-line friendly; for us that's a deal-breaker as we need to be able to have an automated tool which our build server (Windows based) can use to build dmg files on-the-fly.

Solution 6 - Macos

See mkfs.hfsplus

Solution 7 - Macos

If you're distributing Mac apps, then surely you have a Mac to write and test them. Why not simply use that same Mac to create the disk image?

[Edit] Alternatively, if you're distributing a portable app, for example a Java .jar file, why bother with a disk image? Macs understand .zip and .tar.gz archives just fine.

I guess what I'm getting at is, I don't understand how one might need a DMG disk image, but not have a Mac with which to create it.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmichelemarconView Question on Stackoverflow
Solution 1 - MacosjstckView Answer on Stackoverflow
Solution 2 - MacosuckelmanView Answer on Stackoverflow
Solution 3 - MacosnameView Answer on Stackoverflow
Solution 4 - MacosNik ReimanView Answer on Stackoverflow
Solution 5 - MacosMattWeilerView Answer on Stackoverflow
Solution 6 - MacosJoshView Answer on Stackoverflow
Solution 7 - MacosSherm PendleyView Answer on Stackoverflow