One useful feature in OS X is support for disk images. These are container files that commonly end in the .dmg suffix, which represent virtual disks to the operating system when opened. By double-clicking these files, the system will mount them just as if you attached an external drive, and then allow you to copy files to and from them.
While most disk images you encounter will be from a developer or other third-party distributer, you can also create your own using Apple’s Disk Utility program.
To do this, you simply need to select “New Disk Image” from the File > New menu in Disk Utility, and then you will be presented with the following window:
When you create a disk image, this save panel will show with a number of options for your disk image (click for larger view).
This window contains a number of options, which are the following. Note that when considering these options, it is useful to differentiate which apply to the image file, and which apply to the disk represented within the image file:
Save As (at the top)
The name of the disk image file (not the disk when mounted)
Name (under the filesystem browser)
This is the name of the disk that appears when you mount it.
This menu contains pre-set sizes to mirror common image formats (CD, or DVD, etc.), but also a custom option where you can specify a size in Kilobytes, Megabytes, Gigabytes, Terabytes, or raw sectors.
The size you set here is the maximum size of the disk contained within the image, which can be less on disk when you use compressed images or sparse format types (see the Partitions and Format sections below).
These options are the disk formatting options for the disk contained in the image. The options here are supported filesystem formats in OS X, which include both case-sensitive and case insensitive options, with and without journaling support.
Case-sensitive filesystems differentiate between capital and lower case letters in names. For example, a case-sensitive filesystem allows you to keep a file called “Test.txt” and “test.txt” in the same folder because of a simple capitalization difference. Generally keep the default case-sensitive filesystem for your formatting, unless you have specific need otherwise.
Journaling is a feature that caches file writes in a special sector called the journal, before they are written to disk. This helps prevent interruptions in the writing process from causing corruption to the data on disk. For the most part, enabling journaling will help preserve the integrity of data stored on the disk.
In addition to the options for Mac OS Extended, you can choose FAT and ExFAT; however, these may only be useful if you are using the disk image with a virtual machine, since the .dmg format is generally only used with OS X systems, so a Mac-native format is recommended.
This option is for the disk image file, and not the disk contained within the image. When set, the image file will be encrypted at either 128-bit or 256-bit encryption. Selecting these options will require you supply a password for the encryption.
This is where you set whether or not the disk within the image is to have a partition map. This can be used if you plan on doing any work with the image that requires partitioning or special properties of a partitioning scheme. Apple supports a number of options here, including mimicking the partition scheme of a hard disk vs a CD, DVD, Hard Disk, or hard disks with various partitioning standards like Master Boot Record or GUID.
One example here is the use of a disk image as a netboot device, where it will require a GUID partition map.
These options allow you to set the specific format of the disk image file itself. Similar to having a text document be in rtf, rtfd, or txt formats. The main options for the image format are the following:
- read/writeAllows you to add and remove files from the image, which treats it like a standard external disk of a fixed size.
- Read-onlyThis is for creating a disk image from the contents of a folder or another disk, and packages them so they cannot be modified. This is useful for distributing files to groups of people.
- CompressedThis option compresses the image and data on it as much as possible. The image will grow as you add files to it, but at an unpredictable rate since compression efficiency will be different for different files you add.
- CD/DVD masterThis is a full sector-for-sector representation of the disk image, which is useful for making a copy of physical media (such as for optical discs).
- Sparse disk imageThis option has the disk image size on disk be as small as possible, and only increases to accommodate files you add to it. The size increase of the image will be directly proportional to the size of files added to it.
- Sparse BundleThis final option is similar to the Sparse disk image, except the image is actually a folder comprised of multiple 8MB segments called “stripes.” This is useful if you have large disk images that you back up with Time Machine, so when changes occur, only the stripes representing those changes are backed up. Otherwise the entire disk image will have to be backed up.
Updated April 14, 2014 — Correction in discussion of case-sensitive filesystem formatting (thanks to reader “Strod”).