hdiutil is the macOS command-line utility for disk images: it creates, attaches, detaches, converts, compresses, encrypts, verifies and resizes image files such as DMG, sparse image, sparse bundle and ISO. It is the Terminal counterpart of the image functions in Disk Utility and is a standard tool in Terminal & scripting work on the Mac, where administrators and developers use it to package software, build installers and automate storage tasks.
The tool talks to the DiskImages framework and the system disk arbitration service, so an image attached with hdiutil behaves like a physical disk: it receives a device node such as /dev/disk4, its volumes mount under /Volumes, and other utilities such as diskutil can inspect it. Because hdiutil prints machine-readable property lists with the -plist option, it fits naturally into shell scripts and build pipelines.
How hdiutil works with disk images
hdiutil works by translating an image file into a virtual block device that the kernel treats like any other disk. The attach verb opens the file, presents its blocks through a device node and, unless told otherwise, asks disk arbitration to mount every recognized volume inside it. The detach verb reverses the process, unmounting the volumes and releasing the device.
Each operation is expressed as a verb followed by options and a path, for example hdiutil create, hdiutil convert or hdiutil verify. Most verbs accept -quiet for silent scripts, -plist for structured output and -debug or -verbose for troubleshooting. The table below summarizes the verbs that appear most often in daily administration.
| Verb | Purpose | Typical use |
|---|---|---|
| create | Builds a new empty or populated image | Package a folder with -srcfolder |
| attach | Connects an image as a virtual disk | Mount a DMG for inspection |
| detach | Unmounts and releases the device | Clean up after a script |
| convert | Changes the image format | Turn a read-write image into UDZO |
| resize | Grows or shrinks an image | Add space to a sparse image |
| verify | Checks the embedded checksum | Validate a downloaded installer |
| compact | Reclaims unused sparse space | Shrink a sparse bundle after deletions |
| imageinfo | Reports format and properties | Audit an unknown image |
An attached image is not a copy in memory: reads and writes go directly to the backing file. This design keeps memory use low, but it also means that a damaged or partially downloaded file produces input and output errors at the block level, which is why verification before use is a sound habit.
Image formats and when each applies
The format code chosen with `-format` determines whether an image is writable, how much space it occupies and how quickly it opens. Read-write formats suit working copies, while compressed read-only formats suit distribution because they are smaller and tamper-evident through their checksums.
| Format code | Characteristics | Best suited for |
|---|---|---|
| UDRW | Read-write, full allocated size | Temporary working images |
| UDZO | Read-only, zlib compression | Broadly compatible software distribution |
| ULFO | Read-only, LZFSE compression | Faster, smaller images for macOS 10.11 or later |
| ULMO | Read-only, LZMA compression | Maximum compression on macOS 10.15 or later |
| UDSP | Sparse image, grows on demand | Single-file expandable storage |
| UDSB | Sparse bundle, many band files | Encrypted or network-synced storage |
| UDTO | Raw CD or DVD master | Producing ISO-style optical images |
Sparse bundles store data in band files of a fixed size, typically 8 MB, so incremental backups and cloud synchronization copy only the bands that changed. A single-file sparse image is simpler to move but must be copied in full after any change. Both formats need periodic compaction to return freed space to the host volume.
Encryption, verification and security behavior
hdiutil supports AES-128 and AES-256 encryption through the -encryption option at creation time, with the passphrase supplied interactively, through -stdinpass or from the login keychain. An encrypted sparse bundle is a common way to keep sensitive project files protected on shared or removable storage, independent of FileVault.
Read-only images carry a checksum, commonly CRC32, that hdiutil verify recalculates to detect corruption. This check confirms integrity but not authenticity: a modified image can carry a fresh valid checksum. Authenticity on macOS comes from code signing and notarization, applied with codesign and Apple notary tooling, and Gatekeeper evaluates those signatures when a user opens a downloaded DMG.
Since macOS 10.15, downloaded images also carry the quarantine extended attribute, which xattr can display. Attaching such an image triggers Gatekeeper checks, and scripted workflows that handle trusted internal images should document any quarantine removal rather than strip it silently.
hdiutil compared with related command-line tools
hdiutil manages image files, whereas several neighboring tools manage disks, backups or signatures. Understanding the division of labor prevents scripts from using the wrong utility for a task. The comparison below places hdiutil among related Terminal tools on the Mac.
| Tool | Primary scope | Relation to hdiutil |
|---|---|---|
| hdiutil | Disk image files | Creates and attaches the images |
| diskutil | Physical and virtual disks, APFS | Partitions or erases an attached image |
| tmutil | Time Machine backups | Uses sparse bundles on network destinations |
| codesign | Code and DMG signatures | Signs the finished image for distribution |
| asr | Block-level restore | Restores a scanned image onto a volume |
In practice, a release script often chains these tools: hdiutil create builds the image, codesign signs it, notarization tooling submits it, and hdiutil verify runs once more as a final check before upload.
Limitations and common mistakes
Most hdiutil failures come from busy resources, wrong formats or space miscalculation, not from defects in the tool itself. The table below links frequent symptoms to their causes and practical fixes.
| Symptom | Likely cause | Fix |
|---|---|---|
| Resource busy on detach | A process holds open files | Close the files or use -force with care |
| Image larger than its contents | Read-write format kept | Convert to UDZO, ULFO or ULMO |
| Sparse bundle never shrinks | Freed space not reclaimed | Run hdiutil compact while detached |
| Create fails with no space | Source size underestimated | Set -size explicitly with headroom |
| Older Mac cannot open image | LZFSE or LZMA format used | Distribute UDZO for wide compatibility |
The burn verb and some legacy options have been removed in recent macOS releases, so older tutorials may fail on current systems. Scripts should check hdiutil help output on the target version and avoid relying on deprecated verbs.
In plain words
A disk image is a single file that holds a complete virtual disk. hdiutil is the typed command that makes, opens and closes these files.
Think of a sealed shipping box. You pack items into it, close it and send it. The person who receives it opens the box and finds everything in order. hdiutil packs the box, seals it, checks that nothing broke on the way and opens it again. The key point is simple: one file can act like a real drive.
A real-world example
A small software team ships a Mac application every two weeks. Its build server runs a shell script after compilation. The script calls hdiutil create -volname Installer -srcfolder build/App -format UDRW to make a writable staging image, adds a background picture and an Applications shortcut, and then runs hdiutil convert with the ULFO format. The final image shrinks from about 410 MB to roughly 160 MB.
Next, the script signs the image with codesign, submits it for notarization and runs hdiutil verify to confirm the checksum. A final hdiutil attach -nobrowse -readonly mounts it invisibly so an automated test can launch the application from the image. The result is a repeatable, fully scripted release that takes under four minutes and has removed manual packaging errors from the process.