How to Use the ‘hdiutil’ Command to Manage Disk Images via Terminal

The Virtual Hard Drive

In macOS, software isn’t distributed as raw executable files like in Windows (.exe). Software is almost exclusively packaged inside Disk Images (.dmg).

When a user double-clicks a .dmg file, macOS treats it exactly like a physical USB drive. It “mounts” it to the Desktop, allowing the user to drag the application into their Applications folder.

If you are an IT administrator writing bash scripts to deploy software across 500 MacBooks silently in the background, you cannot double-click files. You need a way to programmatically mount, extract, and unmount Disk Images entirely from the command line.

This is achieved using the powerful hdiutil (Hardware Disk Image Utility) command.

1. Mounting a Disk Image Silently

Suppose you wrote a script that downloaded Google Chrome (googlechrome.dmg) to a user’s hidden /tmp folder. You now need to crack that image open so the script can access the .app file inside.

hdiutil attach /tmp/googlechrome.dmg -nobrowse -noverify

The Critical Flags:

  • attach: Tells the system to mount the image.
  • -nobrowse: This is vital for silent automation. It prevents the mounted drive from popping up on the user’s graphical Desktop, keeping the process invisible.
  • -noverify: Skips the time-consuming cryptographic verification phase, speeding up script execution drastically.

Once mounted, the contents of the image are accessible in the hidden /Volumes/ directory (e.g., /Volumes/Google\ Chrome/).

2. Copying the Software

Now that the image is mounted and accessible via the file system, your script uses the standard cp (copy) command to drag the software into the actual Applications folder.

sudo cp -R "/Volumes/Google Chrome/Google Chrome.app" /Applications/

(The -R flag is required because macOS .app files are technically just massive folders containing thousands of sub-files).

3. Unmounting (Cleaning Up)

The most common mistake junior administrators make is forgetting to unmount the disk image when the script finishes. Over time, the Mac will accumulate dozens of hidden mounted drives, eating up RAM and causing the operating system to stutter.

Always conclude your deployment scripts by detaching the volume.

hdiutil detach "/Volumes/Google Chrome"

4. Creating Disk Images Programmatically

hdiutil isn’t just for reading images; it can create them.

If you need to securely backup a highly sensitive folder (like the HR department’s payroll files) and send it across the internet, you can bundle the folder into a single, password-protected, 256-bit AES encrypted .dmg file.

hdiutil create -srcfolder /Users/hr/Payroll -encryption AES-256 -format UDRO ~/Desktop/SecureBackup.dmg

The terminal will securely prompt you to type a password, and then it will compile the entire folder into an unbreakable, encrypted vault.

Conclusion

The hdiutil command is the foundation of macOS software deployment. By allowing scripts to silently mount installer images, extract the payloads, and clean up the virtual hardware, it enables truly touchless, automated application provisioning across enterprise fleets.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.