Introduction
I have examined Mac OS X extensively,
and discovered 1) that cloning is possible
from OS X with the utilities that Apple has
provided and 2) that there are a few basic
rules that you need to follow when cloning
a disk with Mac OS X System files in order
to get a bootable clone:
1. File permissions must be preserved.
Many files belong to the root user, so you
cannot simply copy these files from the
Finder. There are other issues with
permissions, such as the setuid bit (in
English, that is a feature of a file that,
when executed, gives the file or
application root power). Copying via the
Finder sets the owner of the new files to
the user that copied them and assigns a
default set of permissions. Many
applications and system files will not
work properly with the default Finder
settings.
2. The invisible Unix system files must be
copied.
Mac OS X is driven by a Unix flavored
operating system called Darwin. Darwin
system files reside at the root level of the
dirve in four folders: /private, /bin, /usr,
and /sbin. These directories hold all the
critical files that allow the computer to
boot up and have basic functionality.
3. Unix-style links must be preserved.
Symbolic links and hard links are different
from the Mac aliases we are familiar with.
Likewise, the way we deal with them will
not be the same. Because there are
some critical symbolic links on a Mac OS
X disk, the integrity of these files must be
preserved by the utility you use to
clone/backup the disk. Some people are
very familiar with the error upon booting
that states "/etc/master.passwd: Not a
directory". This is because the /etc
symbolic link to /private/etc was broken.
4. Some directories are populated by the
System after booting, and are thus
unnecessary to preserve, however,
although empty, they may still have to be
present.
Some directories are populated by the
System. For example, the Volumes
directory is populated with directories
corresponding to the names of Volumes
you have on your system. If you insert a
Zip disk, a new directory in /Volumes is
created with the name of the Zip disk.
These directories are called
"mountpoints", and are created
"on-the-fly" by Apple's autodiskmount
utility. Because these directories do not
contain data on your boot volume, they do
not need to be copied during a clone
operation. The Volumes directory is just a
placeholder (and the OS will recreate the
Volumes directory on bootup, so it is
unnecessary to recreate). The /dev
directory is also a placeholder for system
devices, such as disk drives, output
devices, and communications devices.
The list of devices in this directory is
created each time the computer is booted
up and when new hardware is added, so
it is unnecessary (and a little difficult) to
copy the items in this directory. Because
this is a Unix system directory, however,
you will not have a bootable volume
unless this directory is recreated on the
cloned disk. Creating an empty directory
is sufficient. Likewise, it is important to
backup mach_kernel (the most important
file in the system), but "mach" and
"mach.sym" are destroyed and recreated
each boot by the /etc/rc boot script.
5. Resource forks must be preserved
While Apple is trying to move away from
Resource Forks, there are still many
applications and documents that use
them. Because of this, any backup or
cloning utility must preserve the resource
forks. If you try to clone a Mac OS X disk
without preserving resource forks, many
of your personal documents will be
damaged and the drive will not be
bootable.
The Quick and Dirty instructions for
cloning a disk or backing up your drive:
1. "sudo ditto -rsrc" is the command of
choice
In the Terminal, use ditto to copy each of
the visible directories from your boot
volume to your backup volume. For
example:
* sudo ditto -rsrc /Applications
/Volumes/Backup/Applications
* sudo ditto -rsrc /Developer
/Volumes/Backup/Developer
* sudo ditto -rsrc /Library
/Volumes/Backup/Library
* sudo ditto -rsrc /System
/Volumes/Backup/System
* sudo ditto -rsrc /Users
/Volumes/Backup/Users
6. Next, use ditto to copy your Darwin
system files:
* sudo ditto -rsrc /private
/Volumes/Backup/private
* sudo ditto -rsrc /usr
/Volumes/Backup/usr
* sudo ditto -rsrc /bin
/Volumes/Backup/bin
* sudo ditto -rsrc /sbin
/Volumes/Backup/sbin
* sudo ditto -rsrc /mach_kernel
/Volumes/Backup/mach_kernel
* sudo ditto -rsrc /.hidden
/Volumes/Backup/.hidden
7. Finally, recreate symbolic links and
empty directories:
* cd /Volumes/Backup
* ln -s private/etc etc
* ln -s private/var var
* ln -s private/cores cores
* ln -s private/tmp tmp
* mkdir dev Volumes Network
7. If you'd like to boot from that partition,
be sure to select it in the Startup Disk
Control Panel as it won't be blessed until
that control panel sees it.
That's it! That's the big secret. You
should now have a bootable clone of your
OS X partition.
* Ditto has trouble with locked files. If you
have locked files on your drive, it will stop
when it encounters them. To unlock files
on your drive, type:
sudo chflags -R noschg,nouchg /
in the Terminal to unlock all files on your
hard drive.
** The following is a list of files/folders at
the root level that I believe do not need to
be copied to make a bootable, complete
backup: ".DS_Store, .Trashes, .vol,
automount, Cleanup At Startup, cores,
dev, etc, File Transfer Folder, mach,
mach.sym, Network,
TheFindByContentFolder,
TheVolumeSettingsFolder, tmp, Trash,
var, Volumes"
*** Make sure that the "ignore privileges"
setting for the target volume is not set
(you'll find this setting in the "Show Info"
window for that volume).
The Command-Line-Free version
I have developed a utility that
encapsulates the power of ditto and
performs all the necessary steps to clone
a drive. Carbon Copy Cloner can be
downloaded from its web page.
Using hfspax to create a bootable
backup
hfspax is a modified version of pax, a
common archiving utility for Unix. Credit
goes to Howard Oakley for modifying pax
to work with hfs volumes. hfspax is terrific
because it handles errors very robustly
and it offers the ability to create a
"portable" backup. hfspax also has many
options, including the ability to make
incremental backups and to restore items
from an archive based on patterns (e.g.,
restore only files with a name ending with
".pdf"). I will not cover all the options for
hfspax here, but will introduce a simple
method for making a complete backup of
your entire Mac OS X installation that can
be used to restore a bootable system.
The following scripts can be downloaded
here. I suggest that you download them to
avoid problems with wrapped lines. You
will need to install hfspax before using
these scripts.
#!/bin/tcsh -f
# hfspax backup script
echo -n "Set the backup directory: "
set bkDir = $<
echo -n "Name for archive: "
set name = $<
set segment = "" #"-B 650M" #
Uncomment this line to segment the
archive for burning to CDs
set ignore =
".Trashes|.vol|Network|automount|dev|Vol
umes|mach|mach.sym"
cd / && ls -A / | egrep -v -w "$ignore" |
hfspax -w -f "$bkDir/$name" -x cpio
$segment#!/bin/tcsh -f
# hfspax restore script
echo -n "Path to archive: "
set archive = $<
echo -n "Path to target partition: "
set part = $<
cd $part
hfspax -r -pe -f "$archive"
set iconFiles = `find $part -name "Icon?" |
tr -d '\r' | sed 's/\ /ihatespaces/g'`
# the following works only if the Developer
Tools are installed
foreach icon ($iconFiles)
set dcIcon = "`echo "$icon" | sed
's/ihatespaces/\ /g'`"
/Developer/Tools/SetFile -a C "$dcIcon:h"
end