Articles July 27, 2004 at 9:20 pm

Disk Imaging for Mac OS X Made Easy

They slice! They Dice! Disk images have become an invaluable tool for Mac admins everywhere. Read on to find out more.

(Minor updates for item removal. 4/15/2005)Disk Imaging for Mac OS X Made Easy

One of the greatest things about Mac OS X is that it has brought disk imaging to the fore of your Mac admin toolkit. We had limited access to some disk imaging under Mac OS 9 and earlier, but it was a pale shadow of what we have today. With just the basics under your belt you can:

  1. Easily create and use Apple System Restore (ASR) images. You can use these images for backups, installations, and even migrating to new hardware.

  2. Easily clone drives to other drives. This might not seem like an imaging thing, but it uses asr just the same as if you were using an image as the source.

  3. Use images to archive, compress, encrypt, burn, and otherwise just have a good time with your data.

Previously with Mac OS X we used a number of other utilities to create and use images, most of them from Mike Bombich. These days the only non-Apple imaging tool I use is Mike Bombich’s NetRestore because it makes setting up network ASR deployment stupid-simple. While it may be true that tools like Carbon Copy Cloner (CCC) can make imaging a one-click affair I find that it is often just as easy and faster to make your image by hand.

Having a good image is important
This is probably what most of you are after so I’ll cover it first. It is really easy to create and use ASR images with Mac OS X 10.3. Let’s pretend here that we are going to create an image to setup new Mac in our organization. We can use it to image Macs out of the box or, since we use network home folders, to blast any troublesome Mac away when needed for troubleshooting.

Creating the image:

  1. Setup your ‘perfect’ Mac. Make sure that it has everything on it that you need like a local admin user, drivers, applications, etc…

Watch out here for applications that are single licensed. Those will need to be installed after you restore the image. This might seem like a pain, but if you can cut the time needed to build a new workstation from 4 hours to 30 minutes then you are still way ahead.

Also keep in mind that some settings are what is called ByHost. These preferences are tied to the MAC address of each Mac and won’t work if copied to another machine. Some common ByHost prefs are Classic, iTunes authorizations, display prefs, and screensaver prefs. You can always copy these to the appropriate user folder and fix them up after you restore the image, but that is a different article!

  1. Once you have that perfect Mac setup you need to boot from something else or connect the Mac to another system in FireWire target disk mode. Once you get the volume mounted you need to make absolutely sure you have ownership enabled on the volume!!! Just get info on the volume and then make sure that the “Ignore ownership on this volume” box is not checked. If you fail to do this then your image will not work after you restore it.
  2. Fire up Disk Utility and create a read/write image using the Images > New > From Folder… option to a disk other than the one you are imaging. Why “From Folder…” and not from the device? Using the folder choice is slower but it results in a stretchable, de-fragmented image. What this means is that if you restore the image to a drive that is larger than the source image it can stretch to fill the new volume geometry. Without the ability to stretch you will be forced to use the “file copy” mode of asr, and that will result in a much slower restore.

  3. Once Disk Utility finishes up mounting the image, open a Terminal session. We have a few files that we should remove so we can clone with impunity to other hardware. Do the following:

    sudo rm /Volumes/imageName/var/db/BootCache.playlist
    sudo rm /Volumes/imageName/var/db/volinfo.database
    sudo rm /Volumes/imageName/System/Library/Extensions.kextcache
    sudo rm /Volumes/imageName/System/Library/Extensions.mkext
    sudo rm -r /Volumes/imageName/var/vm/swap*

  4. Un-mount the image and then convert it to a compressed image using Images > Convert… You need to use a read-only or compressed image type or asr won’t scan it in the next step. I would use a compressed image as it will take up less storage space and restore a bit faster.

  5. Now scan the image for restore in Disk Utility via Images > Scan Image for Restore and we are all done with the creation part!

Using your image:

There are two ways to restore your spiffy new image onto another volume.

  1. Drag and drop in Disk Utility’s Restore tab. If you want to make sure that it does a block, and therefore faster, restore you need to check the Erase Destination box. If you don’t use the erase option asr will do a file copy. This can be useful too as a file copy will leave matching items on the drives alone and add the ones that are on the source but not the target.

or

  1. You can restore via the command line like this:
    sudo asr -source imagename -target targetvolume -erase

That’s it!

I think we’re a clone now…

Here is a use for asr that you might not think of right away: cloning from drive to drive. Recently I moved my company’s server into a new G5 Xserve. I simply booted the old server from an external drive, put the XServe into target mode and then cloned the volumes across to the new Mac. The steps are basically the same as restoring an image to a volume.

  1. You can drag and drop in Disk Utility’s Restore tab. I did this the other day when I put a new boot drive in my B&W G4. I simply installed a new drive booted from a 10.3 installer CD, cloned the old boot volume to the new one, then set the startup disk and restarted.

or

  1. You can clone via the command line like this:
    sudo asr -source sourcevolume -target targetvolume

Stupid image tricks…

OK, so what else can you do with a disk image? More than you might think!

  1. Disk images are a great way to archive data. I know you can just right-click on a folder in the Finder and zip it up (You did know that right?) but my options are pretty limited as to how that zip archive is made. Instead of control-clicking on a folder to zip it you could create a compressed disk image with Disk Utility. By doing this you also have the option of securing it with AES-128 encryption it at the same time. When you are done you have a small, secure archive that you can mount and read, burn to a CD as a volume, restore onto another volume, or convert it back to read/write and add more data to it.
  2. Along those same lines you can use a mounted, encrypted image just like it is a drive. You can save and open documents from it and when you logout they are locked up safe and sound. If you are planning on doing this I would not put the image password in your Keychain as it sorta defeats the whole point of the encrypted image. If you’ve ever wondered how FileVault works, now you know!

  3. Using Disk Utility and images you can burn multi-session CD-Rs. First simply create an image from the folder that contains the info to burn. Then click the Burn button in the toolbar and select the image. In the options window that appears select the “Leave Disk Appendable” checkbox. Now you can add another image as a session later. See Apple KB# 160588 for more details.

  4. Have you ever come up with a situation –like building some strange software– where you need a volume that is formatted in some funky format like UFS or HFS+ Case Sensitive? Rather than wipe a drive you can just make an image, formatted as needed, and use that as your workspace. When you are done you can trash the image and reclaim your disk space.

Wrapping up, and one last example…

That’s about it for a quick Mac OS X imaging overview. There is lots more to explore such as network based asr imaging and we will visit that in a future article.

I’ll leave you with one last example that I picked up from The Leader. (Na, na, na, na, na, na, na, na, Leader!)

Install Mac OS X or Mac OS X Server on a disk. Don’t boot up off of the volume when prompted but rather create an ASR image of the virgin system. Now you have a really quick way to install Mac OS X or Mac OS X Server whenever you need to. Every now and then you can convert the image to read/write, apply any new OS updates that have come out since you made the image, and then reconvert to compressed and re-scan for asr. It might take a bit of time every now and then to maintain the install images, but you will make that time up by using it to install.

Have fun!

No Comments

  • I had some problems with this when I tried to do anything but the exact steps
    listed above (which when I followed to the letter worked perfectly, however.)
    But since my testing environment was a little different, I don’t quite
    understand why my assumptions failed.

    The goal: to duplicate the boot environment on one Xserve HD to another HD
    on the same Xserve. Booting off of a third HD for the process. So, MAC
    address remains the same.

    Knowing that these would be the same size drive, I tried making a "device"
    image first, as I wouldn’t need to expand it later–the drive size of the source
    would the be the same as the target.

    –However, that apparently failed when the imaging process wanted to create
    an image of the same size, blank space and all, of the source drive.
    Apparently to do that, you need free space for the image equal to the entire
    size of the source HD, including empty space. Or do you actually need even
    double the space–one for the temp space and one for the image? In any
    event, I wouldn’t try doing an image of an 80GB device with any less than
    160GB of free space on the working drive.

    Second, I tried to create a read-only image directly, instead of a rw first and
    then convert it to a r-only later, as I assumed that you’re removing the MAC
    identifiers when you mount the rw image–and since my MAC would stay the
    same that this wouldn’t be an issue. However, it would error on scanning
    the image if I tried this.

    Finally, I was storing my image on the third (empty) HD, working from one,
    and imaging the second. I found that until I moved the image from the empty
    drive to the boot HD, the ASR scan would fail. The same image on an empty
    drive can not be scanned successfully, whereas it succeeds when scanned and
    housed on a boot drive? I dunno why this is, but I assume it’s something to
    do with the boot magic.

    However, as I said, when I followed the directions as above, it restored in
    good time and I verified it’s bootable. But I wonder if anyone can help tell me
    where my assumptions went wrong?

    • I had some problems with this when I tried to do anything but the exact
      steps listed above (which when I followed to the letter worked perfectly,
      however.) But since my testing environment was a little different, I don’t quite
      understand why my assumptions failed.

      Glad I could help!

      The goal: to duplicate the boot environment on one Xserve HD to another
      HD on the same Xserve. Booting off of a third HD for the process. So, MAC
      address remains the same.

      I think that I would of followed the second method here unless you
      wanted an image for a backup. That said, backups are good to have. Very
      good.

      Knowing that these would be the same size drive, I tried making a
      “device” image first, as I wouldn’t need to expand it later–the drive size of
      the source would the be the same as the target.

      –However, that apparently failed when the imaging process wanted to create
      an image of the same size, blank space and all, of the source drive.
      Apparently to do that, you need free space for the image equal to the entire
      size of the source HD, including empty space. Or do you actually need even
      double the space–one for the temp space and one for the image? In any
      event, I wouldn’t try doing an image of an 80GB device with any less than
      160GB of free space on the working drive.

      The space requirement is something I didn’t hit on. When you image
      from a device you do just that, make an image of the device, free space and
      all. When you make a r/w image from folder you will need roughly twice the
      space that is occupied by data on the source. So to image an 80GB drive with
      4GB of data on it would you would only need 8GB of space to create the
      image.

      Second, I tried to create a read-only image directly, instead of a rw first
      and then convert it to a r-only later, as I assumed that you’re removing the
      MAC identifiers when you mount the rw image–and since my MAC would
      stay the same that this wouldn’t be an issue. However, it would error on
      scanning the image if I tried this.

      We really aren’t removing any MAC info when you chop those files out.
      The first one is really more of a 10.2 thing, but we do it anyway for good
      measure. (Check out KB#107111 for more info.) The second file contains
      info about the volumes that are attached to the Mac and the third are just the
      VM swap files.

      I think your scanning problems come from somewhere else, although I’m not
      really sure what without watching you make the image!

      Finally, I was storing my image on the third (empty) HD, working from
      one, and imaging the second. I found that until I moved the image from the
      empty drive to the boot HD, the ASR scan would fail. The same image on an
      empty drive can not be scanned successfully, whereas it succeeds when
      scanned and housed on a boot drive? I dunno why this is, but I assume it’s
      something to do with the boot magic.

      I’m not sure about this one either! I always create my image on a second
      drive and scan it in the same place.

      However, as I said, when I followed the directions as above, it restored in
      good time and I verified it’s bootable. But I wonder if anyone can help tell me
      where my assumptions went wrong?

      Well, I’m glad that the article helped out. If you want more info on how all
      of this works, as well as the instructions that I follow every time I make an
      image, you should check out man asr.

      Josh

      • Thanks for the reply!

        I worked some more with it today, and found that I could create an image, r-
        only, from a folder, that I could use to restore to another HD–without even
        asr scanning the image first. I didn’t mount the image, and didn’t edit any
        files, even. I created the image on a non-boot drive.

        It restored normally and booted, so it appears to be working fine. "changeip"
        later and it looks good to go into another node.

        Why I had trouble the first time I dunno, but it appears that it just didn’t like
        that first image very much.

        Thanks for the help!

  • Immense thanks for this great guide!
    I just set up a Mac class of 8 machines using this method.

    Some statistics in case anyone’s interested – creating the 4,57 GB
    image took a. 40 min, conversion (to compressed) 15, ASR scan 15 mins.

    Restoring took only an amazing 5 minutes (no checksum, erasing destination)
    on a 1 Ghz G4 on a FireWire disk. Restoring onto a 400 Mhz G4 took 7
    minutes.

    Regarding preferences, keyboard layouts were lost on the clones (probably
    because com.apple.HIToolbox.plist is "ByHost". Photoshop lost its
    color settings, and Office X required re-registration.

    • Glad it helped you out! It is always amazing how fast the images restore onto
      a drive.

      I’ve not seen Office loose its registration info from a clone before. I wonder
      what happened there. Office stores the reg info in some fiddley little hidden
      files. That’s why you have to use the Remove Office tool if you ever need to
      change the serialization.

      You’ll be really happy once I show you how to do this via the network in an
      upcoming article… 🙂

    • Since you turned off (or didn’t use) the checksum feature, you also didn’t
      need to scan the image with asr. That can save you a few minutes in the
      future. However, if you don’t checksum the volume, then you will miss if
      there were any errors in the copy process. For example, bad blocks on the
      hard drive or bad RAM will slip right past you.


      ACTC 10.3, ACHDS, ACDT, ACPT for hire!
      See my Bio for more info

  • Great Article…

    I use images all of the time to setup my machines, but one of the projects I
    have been trying to get rolled out you touch on slightly at the end of the
    article.

    I want to make it stupid simple for my admins to install images to our
    systems, so I used disk utility to image the OS X install disk directly to a
    firewire drive. This works great, I can boot off of the firewire drive directly
    into the Install application and run an install like I would off of the CD/DVD,
    except much faster. My problem is — I would like to add my own packages
    and system updates to this drive. That way, I can hand the image off to my
    admins and send them on there way with a setup that requires them to
    simply boot from the FW disk and the click ok and continue a few times.

    I have tried adding packages, but no dice, and trying to update the OS on the
    disk results in a kernel panic on startup. Is there a way to hack this setup
    and add my own information, or am I stuck with whatever Apple has setup on
    their install disks?

    thx

    haxie

    • Instead of imaging the OS X install disk, you really should set up your
      ‘perfect’ mac like he talks about at the beginning. You will create a disk
      image from this and copy it to your firewire drive as a file. You will need a
      different OS installed on the firewire drive.

      To make this stupid simple, you will configure autologin on this drive and
      autolaunch NetRestore, available from: http://www.bombich.com/software/
      netrestore.html Then, you will configure NetRestore to already be aware of
      where the image file is located so that they can just click ‘go’ (or whatever the
      button is labled).

      Another option is that you can create a netboot image with NetRestore helper
      and your "helpers" could just hold down the ‘n’ key to netboot the machines.


      ACTC 10.3, ACHDS, ACDT, ACPT for hire!
      See my Bio for more info

      • Hmm…

        Maybe it’s time for me to write my follow-up article on netboot based
        imaging.


        Breaking my server to save yours.

        Josh Wisenbaker
        http://www.afp548.com

        • I never could get Apple’s network install stuff to work correctly. I could
          get it to run, but I always got errors halfway through. This includes
          creating the nifty cool network install from an OS install CD and a
          network install from a customer configured drive. I could get the clients
          to boot, and I could get the install to run, and I could get the files to
          copy, but it always ended with an error.

          Recently, though, I did discover that my server’s hard drive was failing.
          I haven’t put much effort into this since this summer, though.


          ACSA 10.3, ACTC 10.3, ACHDS 10.3, ACDT, ACPT

  • Does anyone think it might be useful to delete /System/Library/Extensions.mkext before imaging aswell? It seems to me that forcing a re-build of the kernel extensions cache when the image boots on (potentially) different hardware could be a good idea…

  • Yeah. I always do that actually. I just forgot to put the step in the article. I
    always empty /System/Library/Caches as well.

    I’ll update the article.

    Thanks,
    Josh


    Breaking my server to save yours.

    Josh Wisenbaker
    http://www.afp548.com

  • The "geniuses" at the Apple Store made a disk image of my hard drive. Then
    the PowerBook was sent to Apple repair, and the drive was replaced. When I
    try to restore it from the image, using the erase option, I get failure errors:
    Restore Failure
    An error(2) occurred while copying

    If I retry it’s error(16), then error(19).

    I assume the geniuses would have correctly scanned the image for restore.
    Can these errors be the result of any other condition that I can fix?
    Thanks,
    Kathi

    • Scanning only effects restore speed not the ability to restore.

      Are you able to mount the dmg by itself? Have you formatted the target
      volume?


      Changing the world, one server at a time.

      Joel Rennich
      http://www.afp548.com

      • Are you able to mount the dmg by itself? Yes

        Have you formatted the target volume? It had OS X loaded by Apple repair. Now that I’ve gotten the restore error, it no longer has a bootable system.

  • Install Mac OS X or Mac OS X Server on a disk. Don’t boot up off of
    the volume when prompted but rather create an ASR image of the virgin
    system. Now you have a really quick way to install Mac OS X or Mac OS X
    Server whenever you need to. Every now and then you can convert the
    image to read/write, apply any new OS updates that have come out since
    you made the image, and then reconvert to compressed and re-scan for
    asr.

    This approach sounded very attractive. I tried a variant of it: install
    10.3.3 from the Power Mac G5 install DVD on a FireWire disk on a G5 1.6
    GHz. Avoid booting into it by selecting the internal disk via Open Firmware.
    Install 10.3.8 Combined. Select the FireWire disk as startup and restart.

    Unfortunately, that didn’t work and the G5 got stuck on restart with
    the fan running higher and higher. After a few minutes, I restarted,
    reinstalled 10.3.3, restarted into it and set up the system, and then updated
    to 10.3.8. The latter approach worked.

  • I just ran into a wierd thing. After doing a restore, the hard drive availability is being reported incorrectly. (47 gigs available on a 20 gig drive) I wish! Has anyone ever seen this before or know how to fix it? Other then it being annoying and misleading everything seems to be running properly. Any ideas?
    Thanks!

    • I had a problem that I then realized: I was trying to do a Disk image (backup) of a mac mini I needed to part with. However, my work G5 was running 10.3.9 and my Mini was up to 10.4.2. Volume filled error would show up on the drive I was saving the image to.
      Even booting from the Tiger DVD (10.4), would not allow me to create an image file.
      So I bit the bullet and updated my G5 to 10.4.2.
      This outline helped greatly. I now have an ASR image of a computer I will need to restore to another drive, in the future.

  • There is a bug in 10.3.9-10.4.1 that prevents the creation of large disk images.


    Breaking my server to save yours.

    Josh Wisenbaker
    http://www.afp548.com

  • OK I managed to get NetBSD installed on a MacMini, and even put KDE on it. Its all good.

    If I boot it up without touching any keys, it boots into OSX. If I press the Apple+O+F keys, I go into openFirmware and can enter the NetBSD boot command. The disk is sliced up with an OSX partition as well as 3-4 partitions for NetBSD.

    This took – FOREVER to get right, and now that I have a working mini, I need to/want to clone it for software development/embedded systems work and blast it down onto new mini’s out of the box for our developers to use.

    My question is, what is the best way to do this? Will the article on imaging apply here?

    THANKS!!
    ./Dingo

  • Yeah if you do a create from folder it will scrub the needed files off the image as it creates it.

    Actually it’s all the the asr man page now…


    Breaking my server to save yours.

    Josh Wisenbaker
    http://www.afp548.com

  • 3. Fire up Disk Utility and create a read/write image using the Images > New > From Folder… option

    I’m not sure why you recommend the creation of a read/write image because asr won’t let me restore such an image. I had to convert it to a compressed image and then run an imagescan with checksums before it would restore. Disk Utility wouldn’t play ball with a read/write image, either. I’m not much of a Mac person so perhaps I’m missing something but this is what I had to do to get the image to restore.

    • I always discover these things right after I post stupid comments. Seems I skipped steps 5 and 6. Maybe a “(don’t forget steps 5 and 6)” after mentioning the read/write image might help fools such as me 🙂

  • I just noticed when this was posted and maybe that’s why it’s not working for Leopard. When I attempt to do the Terminal session “cleanup” it doesn’t find anything in the place indicated. I tried doing a ls on the path and none of these files seem to be there anymore. Could this be updated for Leopard or am I totally missing something here? Thanks!

Leave a reply

You must be logged in to post a comment.