« Packaging with Disk Images
by William Moss
Please note that Mac OS X 10.1 renders this tutorial fairly obsolete. It remains here for various reasons, but please look elsewhere if you intend to use a .dmg file on Mac OS X 10.1 or later.
With the move to Mac OS X, the favored method of distributing software has changed somewhat. The proprietary Stuffit compression scheme is far and away the most popular standard for Mac OS 9. But with the Unix underpinnings of Mac OS X, there are some "under the hood" problems that the Stuffit file format doesn't handle well. So even though you may still want to use stuffit to compress your files, stuffit shouldn't be the innermost "wrapper" surrounding your application.
Another way people would distribute their apps in Mac OS 9 was as a data file that would be used by an installer application. Since Mac OS X has a standard Apple Installer application in every install, it would be logical to pack things up as a data file for this app. But either due to time constraints or to intentionally discourage people from using Apple's installer, Apple hasn't released much information on how to make data files for their installer.
But whatever the reasons, there is a new emerging standard that really makes a lot of sense. Disk Copy images are a straightforward distribution medium that gives you all of the features and flexibility you need. Some Carbon software will need to be installed from Mac OS 9 or X and Disk Copy images can work on both platforms. Additionally, Disk Copy images can be of almost any size that you need; no more needing to segment files unless you want to. One other habit I've observed is that using disk images seems to encourage good back-up practices since many users are already accustomed to dealing with a disk images as a "preservation format".
// Game Plan
Here's a quick outline of what we're going to do:
- The first time we do this we'll make a template disk image
- We'll then start our work by making a copy of the template
- We'll open the template and put our files on it
- We'll eject the virtual disk and change the image to read only
If you're already a Disk Copy whiz, this brief set of steps may be enough for you, but beware that there are a few tricks to doing this with Mac OS X.
// Creating the Template Image
The first step in making a disk image for Mac OS X requires you to use the Disk Copy application that came with Mac OS 9. The version for Mac OS X doesn't have commands to create the disk images (only to mount them) so we have to use Disk Copy 6.3.3 that came with Mac OS 9. Use Sherlock if you have to, but look around on your hard disk and you'll probably find Disk Copy version 6.3.3 or later hiding in your Utilities folder in amongst other Mac OS 9 applications.
Figure 1. The old version of Disk Copy is what we need
Disk Copy 6.3.3 runs on Mac OS X under Classic but it's big "failure" is that it doesn't reliably mount images under Mac OS X since Mac OS X hides the Mac OS 9 desktop. More annoying but probably also harmless is that you will sometimes get a "image creation failed" message that seems to occur on the step where Disk Copy erases the disk image. The image will still mount and appear to work, but because of this I prefer to boot back to Mac OS 9 to create the first disk image which will serve as a template for all which will follow. Everything is probably okay, but why take chances?
Figure 2. You probably want to change some preferences
When you reboot into Mac OS 9.1 and start Disk Copy, I would suggest that you choose "Preferences" from the Edit menu to change some of the default settings. None of these are required, but setting them to be defaults will help keep you from making mistakes down the line. Figure 2 shows a slightly modified version of the Preferences dialog with the settings I use. Specifically, you will want to:
- Uncheck the "mount afterwards" option in the Creating Images section.
The mount afterwards option will help in case we actually do want or need to use Disk Copy 6.3.3 under Mac OS X.
- Change the default format to "Read / Write".
The default format needs to be read / write or we won't be able to use the blank disk image that we create.
- Use the size pop-up menu to select a "Custom image size" of 32 MB.
Choosing Custom from the popup menu will let you specify a custom image size (as in Figure 3). Because we want to format the disk image with HFS+ we need to choose a size that's at least 32 MB. Bigger is fine, but not a single byte less than 32 is acceptable for HFS+. Don't worry too much about the size, all the blank space will be compressed out when we're done.
Figure 3. The custom size dialog lets you specify a 32 MB partition
When you're done setting the preferences remember to click the "Save" button to preserve these settings.
Now it's time to actually create the disk image. Choose "Create New Image" from the Image menu and you'll be presented with a save dialog box with a few items like the one depicted in Figure 4. I do advise zeroing the disk to erase junk data from deleted files on your hard disk from accidentally being saved into the image.
Figure 4. Choose a name, location, and to zero the image
After the disk is created you will be asked how you want the disk to be formatted. From the popup menu, choose Mac OS Extended. This is HFS+ and this format is what is needed to robustly support Mac OS 9 and X and this was the whole reason we made the disk 32 MB in size. If Mac OS Extended is not an option in the popup menu, then you probably made the disk too small. Go back and try again.
Figure 5. Name and specify Mac OS Extended as the format
You will also be asked to give the volume a name. This is what it appears the disk is named. You can name the disk anything you want now, and rename it something more appropriate later, but I would suggest something useful like your web site URL or your name.
If all goes well, you should have a blank 32 MB HFS+ image. You can now boot back to Mac OS X.
// Making the Image
In Mac OS X, make a copy of the blank disk image that you created under Mac OS 9.1. Feel free to rename the disk image file to anything you like. When you're ready, double click on the image file to open it with Mac OS X's version of Disk Copy.
The disk will mount and appear as a white-plastic covered disk drive and an empty white window will appear. If you like, feel free to rename the white disk.
This is your disk that will contain your files so start copying things over to the drive. When you have all of the files copied over to the drive, you should spend some time arranging and making your files logically organized.
Figure 6 shows my suggestion of a very useful layout. The window appears in column view and shows the newly mounted virtual disk along with the top level of content. Additionally, it's easy for the user to drag the information from here to the appropriate filing location.
Figure 6. Column view is a useful arrangement for users
Figure 7 shows a more radical suggestion that gets the user's attention. The background picture and large icon sizes were made by selecting "Show View Options" from the View menu. Then turning off "Use Global Settings" before using a custom picture and bumping up the icon size.
Figure 7. Icon view allows you to create a splashy look
Whether you go for the functional or radical approach (or both), make sure that the window itself is a reasonable size in the upper left hand corner of the screen. Remember that some users of iBooks (*ahem*) don't have huge screens. And since window size and position are preserved, be sure that the window is at a useful position for everyone (not just users of the Cinema display).
When you are done arranging the files, you should unmount this virtual disk by clicking on the white disk icon and choosing "Eject" from the File menu.
// Converting the Image
When you have everything arranged perfectly and you have ejected / unmounted the disk image, you need to convert the read / write image to a read-only, compressed image.
For this last step you need to go back to Disk Copy 6.3.3. You can reboot to Mac OS 9.1 if necessary, but I haven't received error messages doing this portion of the process. I just run Disk Copy 6.3.3 in Classic under Mac OS X. If you get errors or you prefer being extra careful, please feel free to reboot into 9.1 to be on the safe side.
When you have Disk Copy 6.3.3 up and running, choose "Convert Disk" from the Image menu and select the disk image you've created.
In the popup menu, change the format to "read only compressed"
As a last step check to make sure that you know where you are saving it. My version of Disk Copy defaults to saving the read only copy into the virtual disk image. Just double check that the destination is where you want to save it.
When you've saved the file, you're done. You can continue to compress or encode the file if necessary, but the content of your files will be preserved in a format that handles all the weird things that Mac OS 9 and X need.
// Checklist Summary
- Make a template disk image the first time we do this process
- Boot into Mac OS 9.1
- Change the Preferences in Disk Copy to disable mounting
- Create a new image that's 32 MB in size
- Format the disk as Mac OS Extended and give it a name
- Reboot into Mac OS X
- Make a copy of the blank 32 MB HFS+ image and rename it.
- Double click the new file to mount it with the Mac OS X version of Disk Copy
- An empty window will open and you can start copying and arranging files
- Eject the "white" virtual disk (not the disk image file) to unmount it
- Open Disk Copy 6.3.3
- Choose "Convert Image" from the Image menu
- Change the format to "Read Only - Compressed" and save it somewhere