How to create a dynamically resizable disk image in OS X

With a few tweaks, you can make disk images in OS X sized to fit their contents.

DiskImageIconX.png
Disk images in OS X are one mode of packaging files for distribution or storage on external media, and, since they mimic the behaviors of optical discs like DVDs, they are commonly used by developers to distribute downloadable installers for their applications.

While convenient for file distribution, you can also use disk images as containers to store various files on your system, or on a local network server, especially if you use their encryption routines to secure them with a password. By doing this, the image contents will only be accessible by you.

Disk Images can be created in Disk Utility, by clicking the "New Image" button in the Disk Utility toolbar. When this is done, you can set the image size and optional encryption options.

When done, the image will create and mount, allowing you to copy files to it; however, you might notice that by default the image size is the same as it was when you created it, so if you created an image that was 1GB in size, then the image file would be 1GB.

resizableimage.png
After setting the size (arrow), set the image type to "sparse" or "sparsebundle" with "no partition map," or set the image type to "compressed." Screenshot by Topher Kessler/CNET
While this might seem logical, it may not be desired. You may have wanted the image to contain up to 1GB of data, but not always be 1GB on disk and instead start smaller and only grow with the size of items you place in it.

Luckily this can be done, using one of two methods:

  1. Sparse or sparsebundle image with no partition scheme
    Apple's "sparse" and "sparsebundle" image types are dynamically resizable images, and if you create one without a partition scheme then they will start at the size of the files you place in them, and grow as you add more files, up to the maximum size you set when creating the image. Simply select either "sparse" or "sparsebundle" from the "Image Format" menu when creating the image, and then choose "No Partition Map" from the "Partitions" menu.
  2. Use compressed disk images
    Instead of choosing "sparse" or "sparsebundle" for the image type, choose one of the compressed options. This will not only make the image size grow with its contents, but could also potentially make it smaller than the contents you store on it, as they will be compressed. Keep in mind that compression is dependent on the type of file being compressed, so if you have a bunch of zip files or mpeg4 movies that are already highly compressed, then you might not see much benefit; however, if you have only text files, then you may see these become highly compressed.

Questions? Comments? Have a fix? Be sure to check us out on Twitter.

About the author

    Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.

     

    Join the discussion

    Conversation powered by Livefyre

    Show Comments Hide Comments
    Latest Galleries from CNET
    The best and worst quotes of 2014 (pictures)
    A roomy range from LG (pictures)
    This plain GE range has all of the essentials (pictures)
    Sony's 'Interview' heard 'round the world (pictures)
    Google Lunar XPrize: Testing Astrobotic's rover on the rocks (pictures)
    CNET's 15 favorite How Tos of 2014