hdiutil

On this page 7

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.

VerbPurposeTypical use
createBuilds a new empty or populated imagePackage a folder with -srcfolder
attachConnects an image as a virtual diskMount a DMG for inspection
detachUnmounts and releases the deviceClean up after a script
convertChanges the image formatTurn a read-write image into UDZO
resizeGrows or shrinks an imageAdd space to a sparse image
verifyChecks the embedded checksumValidate a downloaded installer
compactReclaims unused sparse spaceShrink a sparse bundle after deletions
imageinfoReports format and propertiesAudit an unknown image
Frequently used hdiutil verbs

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 codeCharacteristicsBest suited for
UDRWRead-write, full allocated sizeTemporary working images
UDZORead-only, zlib compressionBroadly compatible software distribution
ULFORead-only, LZFSE compressionFaster, smaller images for macOS 10.11 or later
ULMORead-only, LZMA compressionMaximum compression on macOS 10.15 or later
UDSPSparse image, grows on demandSingle-file expandable storage
UDSBSparse bundle, many band filesEncrypted or network-synced storage
UDTORaw CD or DVD masterProducing ISO-style optical images
Common disk image formats in macOS

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 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.

ToolPrimary scopeRelation to hdiutil
hdiutilDisk image filesCreates and attaches the images
diskutilPhysical and virtual disks, APFSPartitions or erases an attached image
tmutilTime Machine backupsUses sparse bundles on network destinations
codesignCode and DMG signaturesSigns the finished image for distribution
asrBlock-level restoreRestores a scanned image onto a volume
hdiutil and neighboring macOS utilities

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.

SymptomLikely causeFix
Resource busy on detachA process holds open filesClose the files or use -force with care
Image larger than its contentsRead-write format keptConvert to UDZO, ULFO or ULMO
Sparse bundle never shrinksFreed space not reclaimedRun hdiutil compact while detached
Create fails with no spaceSource size underestimatedSet -size explicitly with headroom
Older Mac cannot open imageLZFSE or LZMA format usedDistribute UDZO for wide compatibility
Typical hdiutil problems and remedies

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.