User Tools

Site Tools


user:mcooper6:rescue_mac

~~TOC~~

The Lab46 Tutorials

Rescue data from a Mac that won't boot

How to save your skin in less than two and a half days

Following the steps in this tutorial will lead you through the process of:

  • Recovering data from a Mac that won't boot after a catastrophic failure
  • Restoring VirtualBox virtual machines to their working state, current to the time of failure

Points to note:

  • This approach uses a USB device for recovering piles of small data where no individual file is larger than 4GB. A second Mac is used in FireWire target mode to recover files larger than 4GB. (I.E. VirtualBox .vdi files)
  • At the very least, you need your VirtualBox vm's machine xml file, the primary hard drive (.vdi file) and the snapshots (.sav files) to successfully restore your VirtualBox vm's. It is best to also have the VirtualBox.xml file as well, however you can probably get by if you don't have it.
  • It *is* possible to re-install Snow Leapord without losing your data. However, this assumes that you're drive is not damaged by whatever mayhem caused your Mac to stop booting in the first place.
  • Your mileage may vary. If your machine catches fire, then you've done something wrong.

Background

This article details my exploits with a virtualized macbook pro running Mac OS X 10.6.3, with a 2.4 GHz Intel Core 2 Duo, and 4GB of RAM. On this machine reside 2 very important Virtual Machines; one Windows XP, and one Ubuntu 10.04. Both of these VM's were created using VirtualBox 3.1, and both had been migrated through several editions, up to 3.2. As you can probably tell by the necessity of this article, this Mac does not happen to have a close relationship with Time Machine, nor have I taken the time to employ any sort of data backup strategy. This is a problem that I now plan to remedy.

One good point about my setup: Each VM on my Mac was configured to use the same shared folder on the host machine (put in place using VirtualBox's Vboxsf command), so most of my data was actually stored in a directory on the host. The benefit of this setup is that if there is ever a crash, the data is still somewhere on the HD, and looks like data. As opposed to trapped inside a .vdi file, just hoping to be rescued. The one problem with my setup: The servers running each VM were set up to store their data in their own data directories (local to the VM), and with this data, a lot of really valuable code. In the end, this meant that if the Mac host were to crash, the only hope of getting this data back would be to find a way to start the VM's, and copy the data while they run.

Guess what, the Mac crashed.

Where to start

1. Swear

If you're working in seclusion, it is perfectly acceptable at this point to turn the air blue with profanities so vile that you offend yourself. I do, and so I did.

If you're working somewhere more crowded, try slamming the copier hatch down onto your hand. No one would blame you for cussing.

After you're done with all that:

The Data Rescue Prayer:

Dear Lord,

I know I have woefully ignored all the common sense that you've given me by not backing up my data,
but I pray that you not teach me that lesson right now.  

Thanks.

Your Friend, Matt

2. Salvage the data

There's no point crying in your Cherios. They're just bits, lets get 'em.

Single user mode

While starting your Mac, hold down command-S. Once in single user mode you can use cp to copy streams and stream of data to a USB device. In terms of data recovery and typical user data, this method will get you all you need. Insert said device and type:

~:$ mount -t msdos /dev/disk1s1 /Volumes

This command mounts the USB drive at the mount point Volumes. You can then make a new directory to sort your back up files:

~:$ mkdir /Volumes/mac_bu

From there, initiate the slurp: (I'm copying all the files and folders within the directory named 'Shared')

~:$ cp -r -v /Users/matt/Shared/* /Volumes/mac_bu/

You can easily stream movies, and music, and presentations and all other sorts of bits in this manner. So, if you're only looking to recover these sorts of files, stop reading now. You can stream practically everything out of the home folder, that is, *except* for those .vdi files located in 'Users/<username>/Library/VirtualBox/'. So, if you're after the .vdi files, you'll need to hang in there.

FireWire and Target Mode

I just happened to have a second Mac (10.4.11 ppc) just sitting there, waiting. I got myself a 6 pin (old 800a) to 9 pin (new 800b) FireWire (around $34 from the shack down the street). At this point the non-booting Mac is no stranger to the hard shutdown, but for the purpose of etiquette,

~:$ shutdown -h now

Now, with the second Mac still on, plug in each end of the FireWire to the respective machine. Now, simply hold down the T key as you powerup the Mac that is being targeted until you see the FireWire logo on the screen. Within moments you'll see the targeted Mac's HD appear on the desktop of the host. From here, you'll be able to slurp lots and lots of data from the old HD:

Specifically, to restore those VM's, copy:

  • Users/<username>/Library/VirtualBox/VirtualBox.xml
  • Users/<username>/Library/VirtualBox/VirtualBox-prev.xml
  • Users/<username>/Library/VirtualBox/Machines/<vm name> (get the entire directory for each vm)
  • Users/<username>/Library/VirtualBox/HardDisks/ (get only the Vms you want)

For example, the name of one of the VM that I'm after is WinXP. So, I would copy:

  • Users/matt/Library/VirtualBox/VirtualBox.xml
  • Users/matt/Library/VirtualBox/VirtualBox-prev.xml
  • Users/matt/Library/VirtualBox/Machines/WinXP (get the entire directory)
  • Users/matt/Library/VirtualBox/HardDisks/WinXP.vdi

The Machines directory holds all the snapshot and current state information that is necessary to restore the vm to the state it was in prior to HD failure. The .vdi file is the VM in its (fresh) install state. (I.E. Creating a new VM from this .vdi image would result in a working copy of the virtual machine, at its base state, prior to the first snapshot). Within the Machines directory there is another directory called snapshots that contains all of the snapshots (.vdi files) and saved state information (.sav files). These .sav files are used to store the specific state of the virtual machine between snapshots.

The VirtualBox.xml file is the primary file that VirtualBox reads when it opens, and when it starts a virtual machine. This is the primary configuration file that tells VirtualBox where to find .vdi files.

As previously noted, Snow Leopard may be reinstalled without losing your data, however the drive to be reinstalled needs to have 'Journaling enabled' for this to work. So, while in target mode (and *after* you've copied your data), fire up the Disk Utility and select the HD of the targeted machine. Verify that the disk is in 'Journaled' mode [Mac OS X Extended (Journaled)], and if not, attempt to 'Enable Journaling'. This may save you lots of headaches, and make all this prep work unnecessary.

Other things to try

If the previous approach is not working for you:

  • Try formating SD Card as Mac OS X Extended (journaled) and using the Mac's built in SD card reader/writer
  • Try writing to a DVD
  • Try compressing, then send data to SD, USB or DVD

Restore Mac OS X

Now that you've salvaged all the data you can handle, it's time to re-OS. This might be easy in your case. As previously mentioned, it is possible to restore Mac OS X without losing your data (use 'Install & Archive' in 10.5, 10.6 does this automatically when an existing install is found). However, in the case that your drive is damaged (mine was), you will likely need to reformat the disk before moving forward. Until this point, I have not recommended repairing the disk with Disk Utility, but now's the time. Insert your install CD and select Utilities → Disk Utility. Once open, select the primary HD from the drive, (mount it if it's not already) and click the “Verify” button. This will determine if there are problem with the HD volume. Click “Repair Disk” if problems are found. This is the point where disk journaling comes into account. If the disk is not journaled (according to Apple) the disk utility will not be able to repair it. Further, as will be noted at install time, OS X 10.6 cannot be installed on an HD that is not journaled.

If (like me) your disk happens to not be journaled, a reformat is necessary to make the switch (unless you had previous success switching this while in target mode). Select the 'Erase' tab, select 'Mac OS X Extended (Journaled)' from the selection field and click 'Erase'. This will reformat the disk in journaled mode. It's gone, it's all gone … that is, unless you chose the security tab and selected the “Do not erase” button. In this case, utilities like DiskWarrior will likely be able to retrieve lots and lots of data from your drive even after you've re-OS'd.

Now that you've got a clean disk, hit the installer. I don't recall exactly how many prompts there are, but it's the common, next, next, done routine. Simple, straight-forward.

Restore VM's

This is the point where it becomes a little tricky, but if you follow these steps you should have a good shot of getting it right the first time. Assuming that you've successfully transferred those backed up VirtualBox files back onto the troubled Mac, fire up your browser and go get a copy of VirtualBox 3.1.

If your VM's were created in a different version of VirtualBox, then it is best to get that version. Version 4.0 introduces an entirely new method of VM storage, and therefore, restoring a 3.1 VM in a 4.0 setting will lead to many, many more headaches than this method already entails.

Create a new VM

Once installed, fire up VirtualBox and create a new VM. Make sure it has the same name and operating system as the VM that you're attempting to restore. When you get to the Virtual Hard Disk prompt, select 'Use existing hard disk', and select the primary .vdi file that you previously rescued from /Users/<username>/Library/VirtualBox/HarDisks/. Then the ol' next, next, next. This places your new VM in the state directly after install (if this were Linux, you'd be prior to apt-get update).

Make some snapshots

To make things a bit easier, create the same number of snapshots on the new VM as were available to the VM that you're trying to restore. This will create a new 'Snapshots' directory within the 'Machines' directory, and will cause VirtualBox to author a bit of xml, making the rest of this a bit easier.

Configuration

The Directory

At this point, VirtualBox has created all the necessary files, … except the HardDisks directory. In Finder, navigate to: /Library/VirtualBox/ and make a new directory named 'HardDisks'; move your primary .vdi to this directory.

The snapshots

In Finder, delete the new snapshots that were created by VirtualBox, and replace them with the snapshots restored from the 'Machines/Snapshots' directory of the ailing Mac (place the .sav files in this directory as well).

VM's XML file

Replace the new machine's xml file with the old machine's xml file. This file is found in the 'Machines' directory and is named after your VM. In my case, my VM was named 'WinXP' and so its xml file is named 'WinXP.xml'.

If none of this works, *and* you've rescued your VM's '*-prev.xml' file, rename it to <name>.xml (w/o the '-prev' ), place it in the 'Machines' directory and give it another go.

While you're here, open the VM's .xml file and look for the <StorageController><AttachedDevice type=DVD/></StorageController> elements. These are references to the original VM's source DVD image.

	<AttachedDevice passthrough="false" type="DVD" port="1" device="0">
		<Image uuid="{}"/>
	</AttachedDevice>

	Remove this tag from the VM's xml file.

VirtualBox.xml

Open both the old and the new VirtualBox.xml in whatever editor you wish (you've got a network at this point, so I'm assuming that you've either installed a preferred IDE, or that you're comfortable with text editor). Edit the following:

Find this line in both documents:

	<ExtraDataItem name="GUI/LastVMSelected" value="81f46261-7f23-4d04-a450-34f052220bed"/>

	Replace the value attribute in this tag with the uuid of the VM that you're attempting to restore.

Optionally, add this line to turn off the alerts upon startup:

<ExtraDataItem name="GUI/SuppressMessages" value=",remindAboutAutoCapture,remindAboutMouseIntegrationOn,confirmInputCapture,remindAboutMouseIntegrationOff,confirmGoingFullscreen,remindAboutInaccessibleMedia"/>

Next, in the machine registry,

<MachineEntry uuid="{81f46261-7f23-4d04-a450-34f052220bed}" src="Machines/WinXP/WinXP.xml"/>

Replace the uuid attribute with the uuid of your primary hard disk,
and replace the src attribute with the path to your VM's xml file.
	

Now find the <HardDisks> element, and within it replace the following:

*My VM is named WinXP*

        <HardDisk uuid="{81f46261-7f23-4d04-a450-34f052220bed}" location="/Users/matt/Library/VirtualBox/HardDisks/WinXP.vdi" format="VDI" type="Normal">
          <HardDisk uuid="{kd9bf37e-bb2f-43ec-afb0-39508c5c21e8}" location="/Users/matt/Library/VirtualBox/Machines/WinXP/Snapshots/{kd9bf37e-bb2f-43ec-afb0-39508c5c21e8}.vdi" format="VDI">
            <HardDisk uuid="{7c914534-71d4-450f-aebc-c42cf5a03f0c}" location="/Users/matt/Library/VirtualBox/Machines/WinXP/Snapshots/{7c914534-71d4-450f-aebc-c42cf5a03f0c}.vdi" format="VDI">
              <HardDisk uuid="{a2e38e3d-8ae6-4086-92f7-59187c6bde53}" location="/Users/matt/Library/VirtualBox/Machines/WinXP/Snapshots/{a2e38e3d-8ae6-4086-92f7-59187c6bde53}.vdi" format="VDI">
                <HardDisk uuid="{77331654-8eee-4f32-a1c4-031cd5b5061a}" location="/Users/matt/Library/VirtualBox/Machines/WinXP/Snapshots/{77331654-8eee-4f32-a1c4-031cd5b5061a}.vdi" format="VDI"/>
              </HardDisk>
            </HardDisk>
          </HardDisk>
        </HardDisk>

The first uuid in this element set must be set to the uuid of the primary hard drive.
  The location attribute should be changed to reflect the new location of the .vdi file in the 'HardDisks' directory.

Nested elements are set to each respective snapshot.

Fire it up

After all of this, you should now be able to fire up the VM as if nothing ever happened.

VirtualBox.xml

Below is the resulting VirtualBox.xml:

<?xml version="1.0"?>
<VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.9-macosx">
  <Global>
    <ExtraData>
      <ExtraDataItem name="GUI/LastVMSelected" value="81f46261-7f23-4d04-a450-34f052220bed"/>
      <ExtraDataItem name="GUI/LastWindowPostion" value="239,101,770,550"/>
      <ExtraDataItem name="GUI/SuppressMessages" value=",remindAboutAutoCapture,remindAboutMouseIntegrationOn,confirmInputCapture,remindAboutMouseIntegrationOff,confirmGoingFullscreen,remindAboutInaccessibleMedia"/>
      <ExtraDataItem name="GUI/UpdateCheckCount" value="3"/>
      <ExtraDataItem name="GUI/UpdateDate" value="1 d, 2011-08-12, stable"/>
    </ExtraData>
    <MachineRegistry>
      <MachineEntry uuid="{81f46261-7f23-4d04-a450-34f052220bed}" src="Machines/WinXP/WinXP.xml"/>
    </MachineRegistry>
    <MediaRegistry>
      <HardDisks>
        <HardDisk uuid="{81f46261-7f23-4d04-a450-34f052220bed}" location="/Users/matt/Library/VirtualBox/HardDisks/WinXP.vdi" format="VDI" type="Normal">
          <HardDisk uuid="{kd9bf37e-bb2f-43ec-afb0-39508c5c21e8}" location="/Users/matt/Library/VirtualBox/Machines/WinXP/Snapshots/{kd9bf37e-bb2f-43ec-afb0-39508c5c21e8}.vdi" format="VDI">
            <HardDisk uuid="{7c914534-71d4-450f-aebc-c42cf5a03f0c}" location="/Users/matt/Library/VirtualBox/Machines/WinXP/Snapshots/{7c914534-71d4-450f-aebc-c42cf5a03f0c}.vdi" format="VDI">
              <HardDisk uuid="{a2e38e3d-8ae6-4086-92f7-59187c6bde53}" location="/Users/matt/Library/VirtualBox/Machines/WinXP/Snapshots/{a2e38e3d-8ae6-4086-92f7-59187c6bde53}.vdi" format="VDI">
                <HardDisk uuid="{77331654-8eee-4f32-a1c4-031cd5b5061a}" location="/Users/matt/Library/VirtualBox/Machines/WinXP/Snapshots/{77331654-8eee-4f32-a1c4-031cd5b5061a}.vdi" format="VDI"/>
              </HardDisk>
            </HardDisk>
          </HardDisk>
        </HardDisk>
      </HardDisks>
      <DVDImages/>
      <FloppyImages/>
    </MediaRegistry>
    <NetserviceRegistry>
      <DHCPServers>
        <DHCPServer networkName="HostInterfaceNetworking-vboxnet0" IPAddress="192.168.56.100" networkMask="255.255.255.0" lowerIP="192.168.56.101" upperIP="192.168.56.254" enabled="1"/>
      </DHCPServers>
    </NetserviceRegistry>
    <SystemProperties defaultMachineFolder="Machines" defaultHardDiskFolder="HardDisks" defaultHardDiskFormat="VDI" remoteDisplayAuthLibrary="VRDPAuth" webServiceAuthLibrary="VRDPAuth" LogHistoryCount="3"/>
    <USBDeviceFilters/>
  </Global>
</VirtualBox>
user/mcooper6/rescue_mac.txt · Last modified: 2011/08/11 16:06 by mcooper6