A sudden death in the unibody.

A couple of years ago I bought a unibody MacBook Pro, and fairly quickly replaced the hard drive with a fancy flash drive from Crucial. Since then it's been a fine machine: zippy and very quiet.

However recently the flash drive suddenly and completely died. Happily I had a relatively recent disk image, so whatever happened I wouldn't lose too much work. However, given that the machine was hooked up to a second generation Time Capsule.1 I hoped I'd be able to restore the system to the state it was in just hours before the drive died.

I had a spare drive so put that in the MacBook, booted it from DVD and asked it to restore. It found the Time Capsule, but variously couldn't see the right sparseimage or thought it was corrupt. Not only was the process stressful and irritating, there was also a real lack of helpful progress or diagnostic information.

Apple installation DVDs usually have a copy of the Disk Utility on them, which one can use to fix problems like this, but again it was hard to make progress.

A slightly better approach

One of the big problems with running things from the installation DVD is that you're effectively giving up multi-tasking. You can't, for example, fire up a shell to see just what's going on.

Rather than suffer such a limitation, I installed a fairly minimal MacOS system, booted that, then ran the Migration Assistant and Disky Utility from the comfort of MacOS proper.

Disk Utility and Time Capsules

In principle, the Disk Utility application can repair Time Machine backups which are a bit damaged. To do this, mount the Time Capsule in the Finder, then drag the relevant sparseimage to the left-hand pane in Disk Utility.

Having persuaded Disk Utility to look at the data, the most important thing to note is that the Time Capsule is SLOW. I had a 1TB Time Capsule 2 hooked up to a 2009 unibody MacBook Pro over gigabit ethernet. The total time to 'Repair' the disk image was about 15 hours. During this time, the Disk Utility display didn't change at all!

Under the hood the Disk Utility's Repair function appears to call fsck_hfs. This logs information to /var/log/fsck_hfs.log, so if you've got a proper OS you can watch what's going on.

It's hardly the most exciting file to watch: typically you might see a new line every hour or so, but at least you can see that some progress is being made. In practice, I think the drive was fsck'd three times as the image converged to something sensible.

Rather disappointingly the system logs showed that Disk Utility crashed almost immediately after fsck_hfs gave the all clear.

Migration Assistant and Time Capsules

Besides the slowness and lack of meaningful feedback, there also seems to be an issue where the Time Capsule effectively hides an image from the Migration Assistant.

Some combination of waiting and rebooting everything seems to help, but I'm never very sure about rebooting the Time Capsule.

Lessons Learned

At the end of the day, it worked (slowly)!

I suppose it's unfair not to say that the most important observation is that, given some prodding, Time Machine worked as advertised.

On the other hand, where Time Machine and Time Capsule are concerned you probably need to wait a day before concluding that an apparently hung process won't get anywhere.

CLI beats GUI

However, I think it was a mistake to use Apple's GUI tools for the restore: they seem flakey and uninformative.

Next time, I think it would be better to:

  1. mount the image manually with hdiutil;2
  2. repair the image with fsck_hfs.3

If possible, I'd do this from some other Mac rather than the one I was trying to fix.

Once I had a good image, I'd probably try to install it again with the install DVD, before resorting to Migration Assistant. If I did go the latter route though, it would make more sense to create the initial user as some dummy account so that it wouldn't clash.

Avoiding Time Machine

I suspect that the best solution is simply to be more disciplined about using e.g. git4 to push stuff off the machine in near-real time.

Although that wouldn't be trivial for things like system settings, in practice they get pushed to cloud anyway by iSync.