DMG

Also known as: Apple Disk Image · disk image file

On this page 7

DMG, short for Apple Disk Image, is a file format in macOS that stores the complete contents and structure of a volume inside one file, so the system can mount it and present it as if it were a physical disk. A disk image file can carry a file system such as APFS or HFS+, a partition map, optional compression and optional AES encryption, which makes it a flexible container for storage, backup and software delivery.

In the macOS storage & backup toolset, a DMG sits between a plain archive and a real drive. It is mounted by the DiskImages framework, appears in the Finder sidebar and on the desktop, and is ejected like any external disk. Developers use it to ship applications, administrators use it to capture and restore volumes, and ordinary users meet it every time they install software downloaded from the web.

How a DMG file works inside macOS

A DMG works by emulating a block device: when it is opened, macOS attaches the image as a virtual disk and then mounts the file system found inside it. The command-line tool hdiutil and the graphical Disk Utility both drive the same DiskImages framework, which translates reads and writes on the virtual disk into reads and writes on the image file.

Internally, a modern DMG consists of a data fork with the disk blocks followed by a trailer called the koly block, which records offsets, checksums and a property list describing how each chunk of data is stored. Chunks can be raw, zero-filled or compressed, so an image of a mostly empty 10 GB volume can occupy only a few hundred megabytes on disk.

The process of opening an image follows a fixed order. The steps below show what happens when a user double-clicks a downloaded DMG.

  1. macOS reads the trailer and verifies the checksum unless verification is disabled.
  2. If the image is encrypted, the system asks for the passphrase or retrieves it from the keychain.
  3. The DiskImages framework attaches the image as a device node such as /dev/disk5.
  4. The file system inside is mounted under /Volumes, and the Finder shows it as a volume.
  5. Ejecting the volume detaches the device and closes the image file cleanly.

DMG image formats and their properties

Every DMG has a format code that determines whether it is writable, compressed or growable. Choosing the wrong format is the most common reason an image is too large, too slow or impossible to modify. The table lists the formats that hdiutil and Disk Utility create most often.

Format codeDescriptionWritableTypical use
UDRWUncompressed read-writeYesWorking copy before conversion
UDROUncompressed read-onlyNoFast access, no modification
UDZOzlib-compressed read-onlyNoClassic software distribution
UDBZbzip2-compressed read-onlyNoSmaller files, slower opening
ULFOLZFSE-compressed read-onlyNoModern distribution, macOS 10.11 and later
ULMOLZMA-compressed read-onlyNoHighest ratio, macOS 10.15 and later
UDSPSparse imageYesGrowable storage, single file
UDSBSparse bundleYesNetwork and backup storage in bands
Common disk image formats

Encryption is an independent option layered on top of the format. macOS offers 128-bit and 256-bit AES encryption, and the key is derived from the passphrase, so the strength of the protection depends heavily on passphrase quality. A strong passphrase with 256-bit AES is the sensible default for confidential data.

A DMG differs from neighboring containers mainly in whether it holds a file system and how it grows. A ZIP archive stores files only, while a DMG stores a whole volume with permissions, extended attributes and a layout that can include a custom Finder window. The sparse bundle, a close relative, splits its data into many band files rather than one large file.

ContainerHolds a file systemGrows on demandBest suited for
DMG (read-only)YesNoShipping applications and archives
Sparse imageYesYes, single fileLocal encrypted storage
Sparse bundleYesYes, in bandsNetwork shares and incremental backup
ZIP archiveNoNot applicableCross-platform file exchange
ISO imageYes, ISO 9660 or UDFNoOptical media and other platforms
macOS installer packageNo, a payloadNot applicableInstalling files into system locations
How a DMG differs from similar containers

The distinction matters for backup. A single large DMG changes as a whole when one file inside it changes, so a backup tool such as Time Machine copies the entire image again. A sparse bundle changes only the affected bands, which is why it is the preferred container for network backups and encrypted storage that is synchronized regularly.

Creating and using disk images in practice

Disk images can be created in Disk Utility through the File menu or with hdiutil create in Terminal. A typical distribution workflow builds a writable image, arranges its window layout, then converts it to a compressed read-only format, signs it and submits it for notarization so that Gatekeeper accepts it on other Macs.

The decision table below matches common goals with a suitable configuration.

SituationRecommended choiceReason
Distributing an applicationULFO or UDZO, signed and notarizedSmall download, tamper-evident, accepted by Gatekeeper
Storing confidential documentsSparse bundle with 256-bit AESGrows as needed and backs up efficiently
Archiving a finished projectULMO read-only imageMaximum compression and protection from edits
Cloning a small volumeImage from device in Disk UtilityCaptures structure and metadata in one file
Sharing with Windows or Linux usersZIP or ISO instead of DMGDMG support outside macOS is limited
Choosing a disk image configuration

Useful Terminal commands include hdiutil attach to mount, hdiutil detach to eject, hdiutil convert to change formats and hdiutil resize to adjust a writable image. Running hdiutil verify checks the embedded checksums before an image is trusted for restoration.

Security, integrity and common mistakes with DMG files

A DMG is a frequent delivery vehicle for macOS malware, because users are accustomed to opening downloaded images and dragging an application to the Applications folder. Code signing and notarization by Apple reduce the risk, but only when users heed the Gatekeeper warnings instead of overriding them through System Settings.

Most problems with disk images come from a small set of avoidable errors. The table pairs typical symptoms with their causes and fixes.

SymptomLikely causeFix
Image cannot be modifiedRead-only compressed formatConvert to UDRW, edit, convert back
Image file is far larger than its dataUncompressed format chosenConvert to ULFO or UDZO
Corrupted image error on openingIncomplete download or damaged trailerDownload again and run hdiutil verify
Lost access to encrypted imageForgotten passphraseNo recovery exists without the key
Application runs from the mounted imageApp launched without copyingCopy the app to Applications, then eject
Typical DMG problems and their fixes
  • Running software directly from a mounted DMG can cause update failures and translocation of the app to a temporary path.
  • Storing an encrypted image passphrase only in the keychain of the same Mac defeats the purpose of encryption if that Mac is stolen while unlocked.
  • Treating a DMG as a complete system backup is a mistake on modern Macs, because the signed system volume cannot be restored from a simple image.

In simple terms

A DMG is like a virtual USB stick packed into a single file. When you open it, your Mac treats it as a real drive that has just been plugged in. You can look inside, copy files out and then eject it when you are done.

Software makers use DMG files to deliver apps because the whole package arrives in one neat piece. People also use them to keep private files in a locked, password-protected container. The key point is simple: a DMG is a whole disk in one file, not just a folder of documents.

A practical example

A small software studio prepares a new version of its photo editing application for customers who download it from the studio website. The build engineer creates a writable image of about 400 MB, places the application and a shortcut to the Applications folder inside it, and arranges a custom background that shows users where to drag the icon.

The engineer then converts the image to ULFO format, which shrinks it to roughly 160 MB, signs it with the studio Developer ID certificate and submits it for notarization. After Apple returns a successful result, the ticket is stapled to the image and the file is published.

Customers download the DMG, double-click it, drag the app into Applications and eject the volume. Because the image is signed, notarized and checksummed, Gatekeeper opens it without warnings, and support requests about damaged or blocked installers drop to almost none in the weeks after release.