Introduction to hdiutil
The hdiutil
command is one of macOS’s most powerful disk image manipulation tools, providing comprehensive functionality for managing disk images, mounting remote volumes, and performing advanced disk operations. With macOS 15.5 Sequoia, hdiutil continues to be an essential tool for system administrators, developers, and power users who need precise control over disk image operations from the command line.
This comprehensive guide covers everything from basic DMG mounting to advanced HTTP and SMB network mounting operations, making it your complete reference for hdiutil mastery.
Understanding hdiutil Fundamentals
The hdiutil utility uses the DiskImages framework to manipulate disk images and provides functionality that goes far beyond simple mounting and unmounting. Key concepts include:
- Attach vs Mount: Attaching connects the disk image to the system, while mounting makes the filesystem accessible
- UDIF Format: Universal Disk Image Format is macOS’s native disk image format
- Verification: Built-in checksum verification ensures image integrity
- Network Support: Direct HTTP and SMB mounting capabilities
Basic hdiutil Syntax and Common Verbs
The basic syntax for hdiutil follows this pattern:
hdiutil verb [options] arguments
Essential verbs include:
attach
– Mount disk imagesdetach
– Unmount disk imagescreate
– Create new disk imagesconvert
– Convert between image formatsverify
– Verify image integrityinfo
– Display information about attached imagesburn
– Burn images to optical media
DMG File Operations
Mounting DMG Files
The most common hdiutil operation is mounting DMG files. Here are various methods:
# Basic DMG mounting
hdiutil attach /path/to/image.dmg
# Mount without opening Finder window
hdiutil attach -noautoopen /path/to/image.dmg
# Mount with verbose output
hdiutil attach -verbose /path/to/image.dmg
# Mount without verification (faster but less secure)
hdiutil attach -noverify /path/to/image.dmg
Unmounting DMG Files
Several methods exist for unmounting disk images:
# Unmount by device name
hdiutil detach /dev/disk2
# Unmount by volume path
hdiutil detach "/Volumes/Volume Name"
# Force unmount (use with caution)
hdiutil detach -force /dev/disk2
Getting Information About Mounted Images
Use these commands to retrieve information about currently mounted images:
# List all mounted disk images
hdiutil info
# Get detailed information about specific image
hdiutil info -plist
HTTP Mounting with hdiutil
One of hdiutil’s powerful features is the ability to mount disk images directly from HTTP URLs, enabling remote access to disk images without downloading them first.
Basic HTTP Mounting
# Mount disk image from HTTP URL
hdiutil attach http://example.com/path/to/image.dmg
# Mount with authentication
hdiutil attach http://username:[email protected]/image.dmg
# Mount with specific user agent
hdiutil attach -useragent "CustomUserAgent/1.0" http://example.com/image.dmg
HTTPS Mounting with SSL Options
For secure HTTP connections, additional options are available:
# Mount from HTTPS with certificate verification
hdiutil attach https://secure.example.com/image.dmg
# Skip SSL verification (not recommended for production)
hdiutil attach -insecurehttp https://example.com/image.dmg
HTTP Mounting Best Practices
- Always verify SSL certificates when possible
- Use authentication credentials securely
- Consider network bandwidth limitations
- Implement timeout handling for large images
SMB Network Mounting
hdiutil can also mount disk images from SMB shares, providing seamless integration with network storage systems.
SMB Mounting Syntax
# Mount DMG from SMB share
hdiutil attach smb://server.local/share/image.dmg
# Mount with credentials
hdiutil attach smb://username:[email protected]/share/image.dmg
# Mount from Windows share
hdiutil attach smb://windows-server/SharedFolder/image.dmg
Advanced SMB Options
For enterprise environments, additional SMB options are available:
# Mount with specific SMB protocol version
hdiutil attach -smbprotocol SMB2 smb://server/share/image.dmg
# Mount with domain authentication
hdiutil attach smb://DOMAIN\\username:password@server/share/image.dmg
Creating and Converting Disk Images
Creating New Disk Images
hdiutil provides extensive options for creating disk images:
# Create blank disk image
hdiutil create -size 100m -fs HFS+ -volname "MyVolume" blank.dmg
# Create image from folder
hdiutil create -srcfolder /path/to/folder -format UDZO folder.dmg
# Create encrypted disk image
hdiutil create -size 100m -encryption AES-256 -stdinpass secure.dmg
Converting Image Formats
Convert between different image formats as needed:
# Convert DMG to ISO
hdiutil convert input.dmg -format UDTO -o output.iso
# Convert ISO to DMG
hdiutil convert input.iso -format UDZO -o output.dmg
# Convert to compressed format
hdiutil convert input.dmg -format UDZO -o compressed.dmg
Advanced hdiutil Operations
Verification and Integrity Checking
Ensure disk image integrity with verification commands:
# Verify disk image
hdiutil verify image.dmg
# Verify with verbose output
hdiutil verify -verbose image.dmg
# Check image information
hdiutil imageinfo image.dmg
Resizing Disk Images
Modify disk image sizes dynamically:
# Resize to specific size
hdiutil resize -size 200m image.dmg
# Resize to minimum possible size
hdiutil resize -sectors min image.dmg
Partition Operations
Work with partitioned disk images:
# Display partition map
hdiutil pmap image.dmg
# Attach specific partition
hdiutil attach -section 2 image.dmg
Security and Encryption Features
Working with Encrypted Images
Handle encrypted disk images securely:
# Mount encrypted image with password prompt
hdiutil attach encrypted.dmg
# Mount encrypted image with password from stdin
echo "password" | hdiutil attach -stdinpass encrypted.dmg
# Check if image is encrypted
hdiutil isencrypted image.dmg
Changing Passwords
Modify encryption passwords on existing images:
# Change password
hdiutil chpass image.dmg
# Change password non-interactively
hdiutil chpass -oldstdinpass -newstdinpass image.dmg
Performance Optimization and Best Practices
Optimization Flags
Use these flags to optimize performance:
# Disable automatic verification for speed
hdiutil attach -noverify image.dmg
# Quiet mode for scripting
hdiutil attach -quiet image.dmg
# Mount without mounting contained volumes
hdiutil attach -nomount image.dmg
Scripting Best Practices
When using hdiutil in scripts, consider these practices:
- Always check return codes for error handling
- Use absolute paths to avoid ambiguity
- Implement proper cleanup for mounted images
- Consider using plist output for parsing
Troubleshooting Common Issues
Mount Failures
Common solutions for mount failures:
# Force mount with specific filesystem
hdiutil attach -fsargs -o force image.dmg
# Mount with owners disabled
hdiutil attach -owners off image.dmg
# Mount with specific device node
hdiutil attach -drivekey system-image=true image.dmg
Network Mount Issues
Troubleshooting network mounts:
- Verify network connectivity and permissions
- Check firewall settings for SMB and HTTP traffic
- Validate URL formatting and authentication credentials
- Consider DNS resolution issues
Permission Problems
Resolve permission-related issues:
# Mount with specific user permissions
hdiutil attach -owners on image.dmg
# Mount with nobrowse to hide from Finder
hdiutil attach -nobrowse image.dmg
macOS 15.5 Sequoia Updates
macOS 15.5 Sequoia includes several improvements to hdiutil:
- Enhanced APFS support for modern disk operations
- Improved security validation for network mounts
- Better integration with System Integrity Protection
- Enhanced performance for large disk image operations
- Updated encryption algorithms for better security
Integration with Other macOS Tools
Working with diskutil
Combine hdiutil with diskutil for comprehensive disk management:
# Mount image and get disk identifier
DISK=$(hdiutil attach -nomount image.dmg | head -1 | awk '{print $1}')
# Use diskutil to mount filesystem
diskutil mount $DISK
Automation Scripts
Create automated workflows combining multiple tools:
#!/bin/bash
# Automated image mounting script
IMAGE_URL="http://example.com/software.dmg"
MOUNT_POINT="/tmp/mounted_image"
# Mount image
hdiutil attach "$IMAGE_URL" -nobrowse -mountpoint "$MOUNT_POINT"
# Perform operations
cp "$MOUNT_POINT/Application.app" /Applications/
# Cleanup
hdiutil detach "$MOUNT_POINT"
Conclusion
The hdiutil command is an indispensable tool for macOS users who need comprehensive disk image management capabilities. From basic DMG mounting to advanced HTTP and SMB network operations, hdiutil provides the flexibility and power needed for both simple tasks and complex automation workflows.
Whether you’re a system administrator managing enterprise deployments, a developer working with disk image distributions, or a power user seeking greater control over your macOS system, mastering hdiutil will significantly enhance your command-line capabilities.
Remember to always verify image integrity when security is important, use appropriate authentication methods for network mounts, and implement proper error handling in automated scripts. With the knowledge from this guide, you’re well-equipped to leverage hdiutil’s full potential in macOS 15.5 Sequoia and beyond.