How can I reformat the internal drive and install Mountain Lion from an external drive? I have a very weird problem - I messed up with the partions when I installed Bootcamp. 

I want to upgrade my 10.7.5 to 10.8.5. I have bought the 10.8.5 from Apple Store. I downloaded it and when tried installing it, it failed because there was no Apple-formatted disk.

So I guess I have to reformat the whole drive. I have backed up all my data (I don't have enough hard drive space to make a Time Machine backup). I have just saved necessary files and also the installer for OS X 10.8.5 that I just downloaded from Apple.

Now, how can I reformat and install OS X from the installer placed in the external hard drive?
You don't need any external drive. You can erase the drive and reinstall OS X using the recovery system:


Start up from the recovery partition by holding command-R.
Open Disk Utility, select the drive (not the Macintosh HD volume), open the erase tab, set the format to Mac OS Extended (Journaled), and press the erase button. It also erases the hidden recovery and EFI partitions.
Reinstall OS X. When I did this with my MacBook Air, I restarted it after I had erased the drive, so I don't know if it is possible to reinstall OS X from the recovery partition without relying on Internet Recovery mode. But if you restart the Mac, it will start up in Internet Recovery mode, which means that it downloads a disk image of the recovery system from Apple's servers, and you can then install OS X on the empty drive.


Some older Macs support a recovery partition but not Internet Recovery mode. See http://support.apple.com/kb/ht4904. If you have one of those Macs, you erase the whole drive from the recovery partition, and it is not in fact possible to reinstall OS X without starting up in Internet Recovery mode after that, you can probably use Recovery Disk Assistant instead.

If others search for how to do a normal erase and reinstall, erase the main OS X partition (like Macintosh HD) instead of the whole drive:


Start up from the recovery partition by holding command-R.
Open Disk Utility, select the Macintosh HD volume, open the erase tab, and press the erase button.
Quit Disk Utility and choose Install OS X.


See https://support.apple.com/kb/ph11273.

If your Mac came with Lion, the Install OS X option will download and install the latest minor version of Lion. You can upgrade to Mountain Lion or Mavericks from App Store after that.