Is it possible to build a .dmg file (for distributing apps) from a non-Mac platform? And if yes, how?
-
1How did you finally implement your DMG file creation? Are you able to produce compressed DMG files? I've raised a similare question to yours here: http://stackoverflow.com/questions/5576392/how-to-update-a-dmg-file-from-windows – Pierre Arnaud Apr 07 '11 at 05:33
-
I just use a Mac; the most interesting answer is mkfs, but I don't use Linux for building. – michelemarcon Apr 07 '11 at 07:55
-
Thanks; were you able to automate the whole process? – Pierre Arnaud Apr 09 '11 at 09:41
-
https://askubuntu.com/questions/1117461/how-do-i-create-a-dmg-file-on-linux-ubuntu-for-macos – Channa May 21 '21 at 16:35
7 Answers
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.

- 491
- 5
- 5
-
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 08:48
-
This works locally. But Im trying to build the dmg in gitlab-ci. I used an alpine docker image for the package stage. Turns out you cannot use mount in docker at all (unless you workaround adding priviledges to the container) So Im still looking for a way to copy a .app directory into it without ever mounting the file. – Max Jun 21 '19 at 12:08
-
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
-
Yes, it did work. But as it turns out a privileged container for gitlab-ci is also not a bad solution. If you have a dedicated runner (like gitlab recommends you do anyway). You cant really screw up that much. And its also how gitlab recommends building docker images in ci. Witch a docker runner that is priviledged. It just means it can do things that it normally could not. Like mounting images and building docker within the docker image. – Max Jul 25 '19 at 14:56
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

- 25,298
- 8
- 64
- 82
-
-
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). – Andrew Larson Jan 26 '21 at 23:44
-
@AlienDrew genisoimage is available in most Linux distributions. Check your package manager. – uckelman Jan 26 '21 at 23:47
-
@uckelman so no direct way to convert a folder to dmg? I have to create an image first and then convert? – Andrew Larson Jan 27 '21 at 00: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 '21 at 00:11
-
@uckelman I actually just misunderstood is all. I figured out what you were meaning, and now able to create my own dmg's, thanks! – Andrew Larson Jan 27 '21 at 00:35
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
-
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
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.

- 39,067
- 29
- 104
- 160
-
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. – saschabeaumont Nov 14 '08 at 01:23
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.

- 789
- 1
- 12
- 21
-
1In 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 00: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
-
2It'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 05: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 06 '20 at 06:18
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.

- 13,556
- 3
- 45
- 57
-
26He 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. – Rob Kennedy Nov 13 '08 at 07:40
-
3The tools to build for a platform are typically specific to that platform. I would no more expect to build Windows installers on a Mac than I'd expect to build Mac disk images on Windows. – Chris Hanson Nov 13 '08 at 08:39
-
18Actually, 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. – Laurens Holst Apr 04 '11 at 12:33
-
3Zip archives cause trouble on OS X. The user needs to use apple's Archive Utility to unzip them, because third party programs don't preserve the +executable bit on the files when unzipping. (Some Apple extension to the zip format?) – codewarrior Jul 12 '11 at 21:31
-
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. – CodeMouse92 Sep 07 '11 at 22:42
-
5If 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 09 '11 at 05:22