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!
2. 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.
3. 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.
4. 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*
5. 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.
6. 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.
2. You can restore via the command line like this:
sudo asr -source imagename -target targetvolume -erase
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.
2. 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.