Create Modern Mac Disk Images

Sep 30, 2023

Mac applications outside the App Store are often delivered using disk images (dmg files), but many apps are not delivered using a modern or efficient disk image format. Below I provide my recommendations for creating more optimal disk image files.

Filesystem

If you target macOS 10.13 or later, you should prefer APFS over HFS+ for the disk image filesystem.

APFS supercedes HFS+. HFS+ is generally worse than APFS for extraction speed, especially for larger workloads under heavy compression in my testing.

Given that Xcode no longer supports deploying to macOS versions older than 10.13 anymore, HFS+ should not be used much. If you mount an existing disk image, you can check its filesystem by examining the output from diskutil list.

Compression Format

You should default to using lzfse as your compression format for disk images.

If you want to create disk images optimized for smaller file sizes (at the expense of slower extraction), you may consider using lzma if your users are running macOS 10.15 or later. However if you still support older OS versions, you may need to consider using bzip2 instead for creating smaller disk images.

lzfse (macOS 10.11+) supercedes zlib and lzma (macOS 10.15+) supercedes bzip2 (which hdiutil deprecated). The successors are better both by file size and extraction speed.

You can check the compression format of an existing disk image by running the file command on it.

Tooling

As a Mac developer, you may be using another developer’s tool for creating disk images and may be concerned about its support for creating modern dmg files. Indeed, a year ago I observed that many tools lacked support for creating APFS or lzfse/lzma disk images. But I have some good news!

Earlier this year I contributed patches to several projects to adopt the more modern options (in no particular order):

I also nudged the authors for enhancing the following software:

Below is a screenshot showing DMG Canvas, which defaults to LZFSE and APFS but allows choosing other compression options like LZMA.

Image of DMG Canvas defaulting to LZFSE and APFS but allows choosing other compression options like LZMA

Conclusion

When creating a new disk image for your Mac application, prefer using APFS and lzfse. If you want to optimize for a smaller file size, prefer to use lzma but consider bzip2 for supporting older macOS versions.

If you use another developer’s tool for creating disk images (rather than using hdiutil directly), chances are it has been updated to support these options. Otherwise check man hdiutil for how do adopt them.