Contribute  :  Advanced Search  :  Directory  :  Forum  :  FAQ's  :  My Downloads  :  Links  :  Polls  
AFP548 Changing the world one server at a time.
Welcome to AFP548
Friday, July 04 2008 @ 02:08 pm CDT
   

Disk Imaging for Mac OS X Made Easy

ArticlesThey 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.

or

2. 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

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.

Have fun!

Story Options

Advertising

Disk Imaging for Mac OS X Made Easy | 30 comments | Create New Account
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Disk Imaging for Mac OS X Made Easy
Authored by: JohnnyMnemonic on Wednesday, July 28 2004 @ 03:45 pm CDT
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?
Disk Imaging for Mac OS X Made Easy
Authored by: filipp on Wednesday, August 04 2004 @ 04:04 pm CDT
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.
Disk Imaging for Mac OS X Made Easy
Authored by: haxie on Tuesday, August 17 2004 @ 11:21 am CDT
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
  • Got it! - Authored by: Anonymous on Wednesday, January 05 2005 @ 02:25 pm CST
Disk Imaging for Mac OS X Made Easy
Authored by: gkl on Wednesday, December 15 2004 @ 08:51 am CST
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...
Disk Imaging for Mac OS X -- restore failure
Authored by: kathi on Tuesday, February 08 2005 @ 09:22 pm CST
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
Disk Imaging for Mac OS X Made Easy
Authored by: andreasg on Tuesday, May 03 2005 @ 09:58 pm CDT

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.

Wierd problem with Disk Utility Restore
Authored by: dragon34 on Friday, July 08 2005 @ 12:47 pm CDT
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!
Disk Imaging a Mini that dual boots w/NetBSD
Authored by: dingosatemybaby on Wednesday, October 26 2005 @ 08:39 am CDT
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
Disk Imaging for Mac OS X Made Easy
Authored by: Anonymous on Wednesday, August 22 2007 @ 08:32 am CDT
I'm wondering about the deletion commands to get rid of kernel extensions, bootcache.playlist etc. What do each of these files do and why is it important to delete each particular one?

Has Apple automated this step since the article was written? If not, why?

Thanks for the excellent article!
Disk Imaging for Mac OS X Made Easy
Authored by: mfearby on Sunday, December 16 2007 @ 08:10 pm CST
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.