14.2. A Sample Bare-Metal RecoveryThis example uses diskutil, pdisk, mount, nvram, ditto, and bless to back up and recover a complete Mac OS X system on an Apple iBook, using an iPod as the backup medium. Some alternate examples will also be provided throughout the sample procedure. All volumes are formatted as HFS+. 14.2.1. Perform the BackupFirst, attach the backup disk to the system. The disk volume is automatically mounted by diskarbitrationd; for this example, we assume it's mounted under /Volumes/iPod.
Now save the important metadata. Use diskutil to get partition names and sizes, as well as the root disk device name (usually /dev/disk0). With this in hand, run pdisk to get exact partition sizes in blocks, and mount to take note of the root partition and any special partitioning options (such as journaling or case-sensitivity), as shown in the following example: % mkdir /Volumes/iPod/Backup % diskutil list | tee /Volumes/iPod/Backup/diskutil.txt /dev/disk0 #: type name size identifier 0: Apple_partition_scheme *18.6 GB disk0 1: Apple_partition_map 31.5 KB disk0s1 2: Apple_HFS Mac OS X 7.9 GB disk0s3 3: Apple_HFS Mac OS X Alt 7.9 GB disk0s5 4: Apple_HFS Local 2.5 GB disk0s7 /dev/disk1 #: type name size identifier 0: Apple_partition_scheme *18.6 GB disk1 1: Apple_partition_map 31.0 KB disk1s1 2: Apple_MDFW 32.0 MB disk1s2 3: Apple_HFS iPod 18.6 GB disk1s3 % sudo pdisk /dev/disk0 -dump | tee /Volumes/iPod/Backup/pdisk.txt Partition map (with 512 byte blocks) on '/dev/disk0' #: type name length base ( size ) 1: Apple_partition_map Apple 63 @ 1 2: Apple_Free 262144 @ 64 (128.0M) 3: Apple_HFS Apple_HFS_Untitled_1 16515072 @ 262208 ( 7.9G) 4: Apple_Free 262144 @ 16777280 (128.0M) 5: Apple_HFS Apple_HFS_Untitled_2 16515072 @ 17039424 ( 7.9G) 6: Apple_Free 262144 @ 33554496 (128.0M) 7: Apple_HFS Apple_HFS_Untitled_3 5253424 @ 33816640 ( 2.5G) 8: Apple_Free 16 @ 39070064 Device block size=512, Number of Blocks=39070080 (18.6G) DeviceType=0x0, DeviceId=0x0 % mount t hfs | tee /Volumes/iPod/Backup/mount.txt /dev/disk0s3 on / (local, journaled) /dev/disk0s5 on /Volumes/Mac OS X Alt (local, journaled) /dev/disk0s7 on /Volumes/Local (local, journaled) /dev/disk1s3 on /Volumes/iPod (local, nodev, nosuid)
Now save your Open Firmware variables with the nvram command: % sudo nvram p > /Volumes/iPod/Backup/nvram.txt As mentioned earlier, at this point you can also save information from System Profiler. Now it's time to back up the data. With the system in a quiescent state to avoid filesystem inconsistency, back up each partition on the root disk: % cd "/Volumes/Mac OS X" % sudo ditto c k rsrc X . "/Volumes/iPod/Backup/Mac OS X.zip" % cd "/Volumes/Mac OS X Alt" % sudo ditto c k rsrc X . "/Volumes/iPod/Backup/Mac OS X Alt.zip" % cd /Volumes/Local % sudo ditto c k rsrc X . /Volumes/iPod/Backup/Local.zip These commands create a ZIP archive for each partition you're backing up. All resource forks and file metadata are retained in the archive files.
Detach the backup disk and keep it somewhere safe. (If you're using NFS, you only need to unmount it.) 14.2.2. Recover the SystemYou have a Mac OS X system with a nonfunctional root disk. If you followed the procedure covered earlier, the recovery should be straightforward. First, turn on power to the system. While the system is starting up, hold down the Option key until the machine presents a graphical list of devices from which to boot. Insert a Mac OS X installation CD or DVD (disc 1 if it's a multidisc set), and click on the reload button to make it show up in the list of boot devices. Select the installation disc, and proceed with the boot. After booting up and selecting the language to use, you reach a welcome message, and the menu bar shows up at the top of the screen. From the Utilities menu, launch Terminal to get a command line. Now attach the backup disk. As with the backup procedure, diskarbitrationd handles the mounting. When this is done, you have the following storage devices attached: an optical drive with a Mac OS X install disc mounted on /, an external backup disk mounted on /Volumes/iPod, and a new internal hard disk with nothing mounted. (If for some reason there are partitions mounted from the internal disk, unmount them at this point with diskutil unmountDisk disk0.)
Refer to /Volumes/iPod/Backup/diskutil.txt and /Volumes/iPod/Backup/pdisk.txt so that you can partition the new disk. The diskutil output provides the partition names. To determine the size of each partition, use the pdisk output to add up the partition's block size with that of the free area listed before it, then divide by two to convert 512-byte blocks to kilobytes. For example, the sizes of the first two partitions in this example are (16,515,072 + 262,144) / 2 = 8,388,608, and the size of the last partition is (5,253,424 + 262,144) / 2 = 2,757,784.
Use diskutil to partition the disk: # diskutil partitionDisk disk0 3 JournaledHFS+ "Mac OS X" 8388608K \ JournaledHFS+ "Mac OS X Alt" 8388608K JournaledHFS+ Local 2757784K Started partitioning on disk disk0 Creating Partition Map 5% .. Formatting Disk 32% .. Formatting Disk 54% .. Formatting Disk 100% .. Finished partitioning on disk disk0 /dev/disk0 #: type name size identifier 0: Apple_partition_scheme *18.6 GB disk0 1: Apple_partition_map 31.5 KB disk0s1 2: Apple_HFS Mac OS X 7.9 GB disk0s3 3: Apple_HFS Mac OS X Alt 7.9 GB disk0s5 4: Apple_HFS Local 2.5 GB disk0s7 See the diskutil manpage for more details on the command syntax and options. One thing to note is that if you'll be running Classic for Mac OS 9 support on this system, you should add the OS9Drivers parameter after the argument specifying the number of partitions. You can tell if your old disk had OS 9 drivers installed by the presence of several additional Apple_Driver partitions in diskutil.txt. After you partition the disk, the new partitions are mounted automatically. Now you're ready to restore the filesystem data. If need be, you can also reset the Open Firmware variables: # ditto x k rsrc "/Volumes/iPod/Backup/Mac OS X.zip" "/Volumes/Mac OS X" # ditto x k rsrc "/Volumes/iPod/Backup/Mac OS X Alt.zip" "/Volumes/Mac OS X Alt" # ditto x k rsrc /Volumes/iPod/Backup/Local.zip /Volumes/Local # nvram f /Volumes/iPod/Backup/nvram.txt The last step of recovery is to prepare the new disk for booting. The following bless command enters the designated folder's directory ID (an HFS+ identifier analogous to a UFS inode number) into the disk's Master Directory Block, and sets the boot-device Open Firmware variable so that the system boots from the new disk the next time it comes up: # bless -folder "/Volumes/Mac OS X/System/Library/CoreServices" -setBoot
Again, if you need Mac OS 9 support on this system, you need to add something to the command line, like this: # bless -folder "/Volumes/Mac OS X/System/Library/CoreServices" -setBoot \ -folder9 "/Volumes/Mac OS 9/System Folder" \ -bootBlockFile /usr/share/misc/bootblockdata See the bless manpage for more information. Finally, reboot the system and get back to work (or play, as the case may be).
|