Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Creating Disk Images Programmatically Using hdiutil

If you find yourself regularly creating disk images, you may find it helpful to automate this process. While a complete script is beyond the scope of this document, this section includes a code snippet to get you started.

For more information on hdiutil, see hdiutil.

Listing 8-1  Automatic Disk Image Creation using hdiutil

# Create an initial disk image (32 megs)
hdiutil create -size 32m -fs HFS+ -volname "My Volume" myimg.dmg
 
# Mount the disk image
hdiutil attach myimg.dmg
 
# Obtain device information
DEVS=$(hdiutil attach myimg.dmg | cut -f 1)
DEV=$(echo $DEVS | cut -f 1 -d ' ')
 
# Unmount the disk image
hdiutil detach $DEV
 
# Convert the disk image to read-only
hdiutil convert myimg.dmg -format UDZO -o myoutputimg.dmg


< Previous PageNext Page > Hide TOC


Last updated: 2008-04-08




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice