Skip to main content
Technology & EngineeringFile Formats202 lines

DMG Apple Disk Image

The DMG disk image format — Apple's native mountable container for macOS software distribution, with compression, encryption, and code signing support.

Quick Summary18 lines
You are a file format specialist with deep expertise in the DMG (Apple Disk Image) format. You understand its koly trailer structure, block-based compression options (zlib, bzip2, LZFSE, LZMA), AES encryption, the various DMG variants (read-only, read/write, sparse, hybrid), and its central role in macOS software distribution. You can advise on DMG creation for app distribution, encryption for secure storage, conversion to ISO for cross-platform use, and the `hdiutil` command-line toolchain.

## Key Points

- **Extension:** `.dmg`, `.sparseimage`, `.sparsebundle`
- **MIME type:** `application/x-apple-diskimage`
- **Magic bytes:** `koly` at the end of file (trailer-based format), or `\x78\x01` (zlib) at start
- **Compression:** zlib, bzip2, LZFSE (macOS 10.11+), LZMA, ADC (legacy)
- **Encryption:** AES-128 or AES-256
- **Filesystem:** HFS+, APFS, FAT32, ExFAT, ISO 9660
- **Code signing:** Supports Apple notarization and code signatures
- Compressed/encrypted disk data in blocks (chunks)
- Each chunk: type (raw, zlib, bzip2, lzfse) + offset + length
- Block map (blkx table) describing chunk layout
- Checksum information (CRC-32, MD5)
- Data fork checksum
skilldb get file-formats-skills/DMG Apple Disk ImageFull skill: 202 lines
Paste into your CLAUDE.md or agent config

You are a file format specialist with deep expertise in the DMG (Apple Disk Image) format. You understand its koly trailer structure, block-based compression options (zlib, bzip2, LZFSE, LZMA), AES encryption, the various DMG variants (read-only, read/write, sparse, hybrid), and its central role in macOS software distribution. You can advise on DMG creation for app distribution, encryption for secure storage, conversion to ISO for cross-platform use, and the hdiutil command-line toolchain.

DMG Apple Disk Image (.dmg)

Overview

DMG (Disk iMaGe) is Apple's proprietary disk image format, the standard way to distribute macOS software. When opened, a DMG mounts as a virtual drive on macOS, typically presenting a window where users drag an application to the Applications folder. DMGs can contain any filesystem (HFS+, APFS, FAT32), support compression, encryption, and code signing, and can be verified for integrity.

DMG replaced the older .smi and .img formats on Mac and is deeply integrated into macOS.

Core Philosophy

DMG (Apple Disk Image) is macOS's native format for software distribution. A DMG file is a mountable disk image that typically contains the application bundle (.app) and often a visual layout with a background image, a symbolic link to /Applications, and instructions to drag the app to install. This drag-to-install metaphor is the standard macOS software installation experience.

DMG's disk image nature means it can contain any filesystem content — not just applications. DMGs are used for distributing installer packages (.pkg), documentation bundles, disk utilities, and any collection of files that benefits from being packaged as a mountable volume. DMG supports compression (bzip2, zlib, lzfse), encryption (AES-128, AES-256), and checksum verification for integrity.

For modern macOS app distribution, the Mac App Store (using .app bundles) and notarized DMG/ZIP files are the primary channels. Apple's notarization requirement means DMGs must be submitted to Apple for automated security scanning before distribution. For enterprise and internal tool distribution, DMGs remain the conventional format, though .pkg installers are preferred when the application requires system-level changes.

Technical Specifications

  • Extension: .dmg, .sparseimage, .sparsebundle
  • MIME type: application/x-apple-diskimage
  • Magic bytes: koly at the end of file (trailer-based format), or \x78\x01 (zlib) at start
  • Compression: zlib, bzip2, LZFSE (macOS 10.11+), LZMA, ADC (legacy)
  • Encryption: AES-128 or AES-256
  • Filesystem: HFS+, APFS, FAT32, ExFAT, ISO 9660
  • Code signing: Supports Apple notarization and code signatures

Internal Structure

[Data Fork]
  - Compressed/encrypted disk data in blocks (chunks)
  - Each chunk: type (raw, zlib, bzip2, lzfse) + offset + length
[XML Plist]
  - Block map (blkx table) describing chunk layout
  - Checksum information (CRC-32, MD5)
  - Data fork checksum
[Koly Block (trailer, 512 bytes)]
  - Signature "koly"
  - Version, header size
  - Flags (compressed, encrypted)
  - Data fork offset and length
  - XML plist offset and length
  - Segment information
  - Master checksum

DMG Variants

  • Read-only DMG — Standard distribution format, optionally compressed
  • Read/write DMG — Modifiable disk images
  • Sparse image — Grows as data is added, single file
  • Sparse bundle — Directory of small band files, Time Machine friendly
  • Hybrid DMG — Contains both HFS+ and ISO 9660 filesystems

How to Work With It

Mounting and Using (macOS)

# Mount a DMG
hdiutil attach image.dmg
hdiutil attach image.dmg -mountpoint /Volumes/MyDisk

# Mount read-only
hdiutil attach -readonly image.dmg

# Mount encrypted DMG (will prompt for password)
hdiutil attach encrypted.dmg

# List mounted images
hdiutil info

# Unmount
hdiutil detach /Volumes/MyDisk
# Or
diskutil unmount /Volumes/MyDisk

Creating DMG Images

# From a folder (compressed, read-only — standard for app distribution)
hdiutil create -volname "MyApp" -srcfolder ./MyApp.app -ov -format UDZO output.dmg

# With better compression (bzip2)
hdiutil create -volname "MyApp" -srcfolder ./src -format UDBZ output.dmg

# Encrypted
hdiutil create -volname "Secure" -srcfolder ./private -encryption AES-256 -format UDZO secure.dmg

# Create empty read/write DMG
hdiutil create -volname "Data" -size 1g -fs HFS+ -type UDIF writable.dmg

# Create sparse image (grows as needed)
hdiutil create -volname "Data" -size 10g -fs APFS -type SPARSE data.sparseimage

# Create hybrid ISO+HFS for cross-platform
hdiutil makehybrid -o hybrid.dmg source_folder/ -iso -joliet

Converting

# Convert to read-only compressed
hdiutil convert input.dmg -format UDZO -o compressed.dmg

# Convert DMG to ISO (for use on non-Mac systems)
hdiutil convert input.dmg -format UDTO -o output.cdr
mv output.cdr output.iso

# Convert ISO to DMG
hdiutil convert input.iso -format UDRW -o output.dmg

# Resize a sparse image
hdiutil resize -size 20g data.sparseimage

Extracting on Non-Mac Systems

# Linux — using 7-Zip
7z x image.dmg

# Linux — using dmg2img
dmg2img image.dmg output.img
sudo mount -t hfsplus output.img /mnt/dmg

# Python (limited support)
# p7zip or libdmg-hfsplus for programmatic access

Common Use Cases

  • macOS app distribution: Primary format for distributing .app bundles outside the Mac App Store
  • macOS installers: Operating system and software installers
  • Encrypted containers: Secure storage for sensitive files on macOS
  • Disk backup: Exact copies of physical disks or partitions
  • Development: Distributing SDKs, frameworks, and development tools
  • Cross-platform media: Hybrid DMGs containing both HFS+ and ISO filesystems

Pros & Cons

Pros

  • Native macOS support — double-click to mount, deeply integrated into Finder
  • Multiple compression options (zlib, bzip2, LZFSE) for different speed/size tradeoffs
  • Strong encryption (AES-128/256) built into the format
  • Code signing and Apple notarization support for security verification
  • Checksums ensure integrity of the entire image
  • Customizable appearance (background images, icon placement in mounted volume)
  • Sparse variants allow efficient storage of partially filled images

Cons

  • macOS-only — very limited support on Windows/Linux
  • Proprietary Apple format with no official specification
  • Cannot be extracted on other platforms without third-party tools
  • Larger than simple ZIP for distributing a single .app
  • Modern macOS prefers .pkg installers for apps requiring system modifications
  • App Translocation security feature can complicate direct-from-DMG execution

Compatibility

PlatformMountCreateNotes
macOSNativehdiutilFull support, deeply integrated
WindowsNoNo7-Zip can extract some DMGs; TransMac for mounting
LinuxLimitedNodmg2img + hfsplus mount, 7-Zip for extraction
iOSNoNoNot supported

Programming languages: Limited — most tools use hdiutil CLI. Python (dmglib), C (libdmg-hfsplus).

Related Formats

  • ISO — Cross-platform disc image format
  • PKG — macOS installer package (for apps needing installation steps)
  • ZIP — Cross-platform alternative for distributing macOS apps
  • Sparseimage/Sparsebundle — Growing DMG variants
  • VHD/VHDX — Microsoft's equivalent virtual disk format
  • IMG — Raw disk image format

Practical Usage

  • Distributing a macOS application: Create a polished DMG with hdiutil create -volname "MyApp" -srcfolder ./MyApp.app -ov -format UDZO output.dmg, then customize the mounted volume's background and icon layout to guide users through the drag-to-Applications workflow.
  • Encrypted portable storage: Create an AES-256 encrypted sparse image with hdiutil create -volname "Vault" -size 5g -fs APFS -encryption AES-256 -type SPARSE vault.sparseimage for a secure container that grows only as data is added.
  • Cross-platform ISO creation: Convert a DMG to ISO with hdiutil convert input.dmg -format UDTO -o output.cdr && mv output.cdr output.iso when you need to share disc content with Windows or Linux users.
  • Notarized distribution: After creating the DMG, staple the Apple notarization ticket with xcrun stapler staple output.dmg so that Gatekeeper accepts the DMG even when users are offline.
  • macOS installer packaging: For apps requiring system modifications (kernel extensions, launch daemons), embed a .pkg installer inside a DMG rather than distributing the .pkg directly, providing a familiar mounting experience.

Anti-Patterns

  • Using DMG for cross-platform distribution — DMG has essentially zero support on Windows and Linux without third-party tools. Use ZIP for cross-platform macOS app distribution, as macOS can open ZIP natively and so can every other platform.
  • Distributing uncompressed DMGs — Always use UDZO (zlib) or UDBZ (bzip2) compression. An uncompressed DMG of a 200 MB app wastes bandwidth and storage when compression typically reduces size by 30-50%.
  • Creating DMGs with HFS+ filesystem for modern macOS — APFS is the standard filesystem on macOS since High Sierra. Use -fs APFS for new DMGs unless backward compatibility with pre-10.13 systems is required.
  • Expecting DMG to work as an installer — A DMG is just a mountable container, not an installer. It cannot run scripts, modify system files, or manage permissions. Use .pkg format for anything beyond simple drag-and-drop application delivery.
  • Distributing unsigned/un-notarized DMGs — macOS Gatekeeper increasingly blocks unsigned and un-notarized DMGs, showing scary warnings to users. Always code-sign and notarize DMGs for public distribution.

Install this skill directly: skilldb add file-formats-skills

Get CLI access →