Friday, February 23, 2007

How to un-destroy your hard drive

So, a few days ago I was performing a highly unauthorized, extremely warranty-voiding, amazingly license-violating installation of Mac OS X on my very non-Mac desktop, primarily because I could. I have a rather complex partition structure, involving three primary partitions and four logical ones, to allow me to keep my old Windows partitions around and upgrade my Ubuntu Linux installation safely.

Now, Mac OS and Windows have something in common: they're both attention-seeking brats. Whereas Linux is a good citizen and allows itself to be installed onto any partition, both Mac OS and Windows insist on having primary partitions. (To be fair, Linux has its own flaw--its partitioning tools tend to produce labyrinth partition tables that confuse other operating systems.) As a result, I had to shuffle my partitions around to free up hda2, where my home directory had been, for Mac OS. I used my Ubuntu Live CD to rearrange things, then booted into the Mac OS installer, used the Disk Utility to format the primary partition I had vacated, and installed Mac OS, which went smoothly. I tried to boot my new operating system, but got an error almost immediately:

"GRUB Error 22"

I looked it up on my laptop. Error 22 means that the partition GRUB was on has vanished into thin air.

Uh-oh.

Booted the Live CD again and, sure enough, my root directory and secondary Linux data partitions were gone; Disk Utility had truncated my whole extended partition. Apparently the drivers for my chipset weren't so hot. Fortunately, there's a simple trick to deal with this problem.

A partition table is basically just a table of contents for a disk. When a partition disappears, it hasn't really been deleted; only its entry in the partition table has. If you can recreate the partition table precisely as it once was, you can restore the partitions. Since I had just rearranged everything, and since I always size partitions in multiples of 1 GB (I'm anal), I knew exactly how the disk was laid out, so I put it back to rights, being careful to keep gparted from formatting the "new" partitions. I fsck'd the partitions, which fixed a few errors, and then rebooted.

No Error 17. I booted into Linux--no problem there; it hummed along as if nothing had happened.

I rebooted into Mac OS and got a black screen with only a cursor. It wasn't very happy with my graphics card.

Oh well. There's no such thing as a panacea.

2 comments:

William said...

Yeah got to love that. I had repartitioned a machine once to install linux on it and I messed up the install and the Windows side wouldn't boot at all. Before I wrote any data to any of the partitions I reset the partition table back the way it was before and everything was golden. It turned out that the distribution and version of linux I was using had a messed up copy of fdisk included with it. By the way have you had any luck with PearPC? I have heard that it can be used to load OS X on a PC not sure if it is VM or if it just allows it to run on non-Apple hardware.

Dax said...

I used PearPC once--it's a PowerPC emulator. It works, but it's very slow.

What I installed this time was a hacked copy of the legit x86 version of Mac OS used in MacBooks and such. It runs at normal speed (well, almost, because I don't have the SSE3 instructions that some programs use).