58

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

4
38

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.

7
  • dmg's created this way are showing up "locked" in Finder, I'm told. Is there any way to change that?
    – uckelman
    Apr 24 '12 at 19:22
  • Packages to install if not already in your distro are: kmod-hfsplus (from elrepo) and hfsplus-tools
    – Soren
    Oct 15 '12 at 16:27
  • I know this is an old answer, but is there a tool in Windows to make this possible? Like something in Cygwin or something? Unfortunately the games I'm building requires Windows or a Mac, and I don't have a Mac.
    – Japtar
    Aug 12 '14 at 18:12
  • @Japtar: genisoimage seems to available in cygwin, and is also capable of dmg-files.
    – Daniel
    Mar 24 '18 at 8:48
  • 1
    genisoimage -D -V "$(PROJECT) $(VERSION)" -no-pad -r -apple -o project-$(VERSION)-uncompressed.dmg $(DARWIN_DIR) This appears to work. But I still need to validate wether or not the resulting .dmg is actually useable. Don´t have my mac right now.
    – Max
    Jun 21 '19 at 14:00
34

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
6
  • Thanx, saved my day!
    – Yaronius
    Oct 12 '16 at 18:38
  • You mention a tool you created that makes dmg's, from what I assume is a directory. Do you have a link to said tool? (not to create compressed dmg's from normal dmg's).
    – AlienDrew
    Jan 26 at 23:44
  • @AlienDrew genisoimage is available in most Linux distributions. Check your package manager.
    – uckelman
    Jan 26 at 23:47
  • @uckelman so no direct way to convert a folder to dmg? I have to create an image first and then convert?
    – AlienDrew
    Jan 27 at 0:00
  • One of the supported file systems for a dmg is ISO-9660, so you can treat an ISO-9660 image as an uncompressed dmg. The file produced by genisomage in my example above is a valid dmg, so the example does directly convert a folder to a dmg---but I suspect that this doesn't answer your question.
    – uckelman
    Jan 27 at 0:11
9
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

1
  • How to create a dmg file from an iso file using dmg? The help isn't very helpful.
    – Gergely
    Jan 30 '14 at 20:07
8

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.

1
  • You should also be able to do it using command line tools under Linux, similarly to how one would create a DMG from the command line on Mac OS X. Nov 14 '08 at 1:23
4

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.

4
  • In the future, you can leave information like this in a comment under the original answer, rather than creating a new answer. You can still get upvotes, too.
    – Zenexer
    Jul 23 '13 at 0:47
  • I'm just curious, what about my answer doesn't qualify it as an answer? Not being rude, just curious. I don't really care about the up-votes though.
    – MattWeiler
    Jul 24 '13 at 15:04
  • 2
    It's more of a response to another answer. Someone else has already posted this procedure, as you've noted in your answer. When you have feedback regarding an answer (such as your experience with the solution), comments are a great place to add that information. When you want to significantly change the procedure, you should post a new answer.
    – Zenexer
    Jul 25 '13 at 5:30
  • It is truly astonishing how bad Apple is at understanding the need for cross compiling and platform portability for CI/CD. Same with Oracle; there is no good way of building installable java apps for multiple targets on the same host without a gigantic mess of contorted scripts.
    – nyet
    Jul 6 '20 at 6:18
2

See mkfs.hfsplus

-36

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.

7
  • 25
    He hasn't said he doesn't have a Mac. I could imagine a build environment where all other platforms are prepared on one system (with cross-compilers, say) and he wants to build the Mac distro there, too. Nov 13 '08 at 7:40
  • 18
    Actually, several people build Windows installers on Linux, and I believe the same tools also work on a Mac. Such is the magic of cross-compiling: a single machine can build for all the targets.
    – CesarB
    Nov 13 '08 at 10:58
  • 16
    -1 because I think ‘just use a mac’ is not a good answer. I don’t have one and don’t want one. My users provide me with testing feedback if there are Mac issues, but normally I don’t need to test specifically on that platform (I am building and distributing a Java application). Also having to get on a separate machine to build and deploy a release is a nuisance. Zip archives work (Maven can create them) but DMG is better to provide better familiarity with the common install procedure used by Mac users. Apr 4 '11 at 12:33
  • 11
    "If you're distributing Mac apps, then surely you have a Mac to write and test them." That is not true. I am a Python developer, and I write programs for Win/Mac/Linux without ever having to use my Mac! (I only have an outdated PPC G4, no good for compiling Python/PyGTK files.) And, we software developers do have to build software for people other than ourselves, thus creating the need for .dmg files. Sep 7 '11 at 22:42
  • 5
    If he is building his software with a build server, for doing continuous integration or automated deployment, it is quite possible that he doesn't have access to a mac for the production version of his software.
    – RodeoClown
    Dec 9 '11 at 5:22

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.