How can I extract the Mountain Lion installer from the recovery partition

Solution 1:

You don't need to worry about having to copy any data, making USB sticks or having the media present. Use Mountain Lion's Internet Recovery procedure, all files is downloaded and installed on the new drive without having any files.

You replace the HDD and start with Command-R...

See OS X Internet Recovery for more info about the procedure, quote:

If you happen to encounter a situation in which you cannot start from the Recovery System, such as your hard drive stopped responding or you installed a new hard drive without OS X installed, new Mac models introduced after public availability of OS X Lion or OS X Mountain Lion, automatically use the OS X Internet Recovery feature if the Recovery System (Command-R method above) doesn't work. OS X Internet Recovery lets you start your Mac directly from Apple's Servers. The system runs a quick test of your memory and hard drive to ensure there are no hardware issues.

OS X Internet Recovery presents a limited interface at first, with only the ability to select your preferred Wi-Fi network and, if needed, enter the WPA passphrase. Next, OS X Internet Recovery will download and start from a Recovery System image. From there, you are offered all the same utilities and functions described above.

Regarding "Where is the [OS X] disk image hidden?", the Recovery Partition is a minimal bootstrap that connects to a wi-fi network to download the complete OS X 10.8 install, that's why it is so small. See here for further info: About OS X Recovery.

Solution 2:

So, here's how I got a Mountain Lion Install DVD from the recovery partition. It's a crazy workaround.

I started with this article (http://hints.macworld.com/article.php?story=20110831105634716&query=lion+usb)

  1. Mount the invisible recovery partition.
  2. Mount the invisible BaseSystem.dmg disk image.
  3. Run the Installer from there, targeting a USB stick with >5gb free space.
  4. When the machine reboots, yank the USB Stick out.
  5. After it boots normally, reinsert the USB stick and look around on it for the InstallESD.dmg
  6. Burn the InstallESD.dmg to a DVD
  7. Replace your hard drive
  8. Install from the DVD.

I do not recommend this procedure; It's persnickity and slow. Also, the only advantages it has over making a bootable USB drive is that you don't have to erase your USB stick, and you get a DVD backup installer in the end.