Your Mac has begun showing signs of trouble. Perhaps you frequently get errors when trying to open or save files. You suspect a problem with the hard drive. Before panic sets in, you want to launch Apple's Disk Utility and select Repair Disk from the First Aid tab. Hopefully, that will remedy the situation. One problem though: Repair Disk is dimmed and you can't select it. Why? Because OS X cannot attempt repairs on an active startup drive. You can still use Repair Permissions, which may help in certain situations. But let's assume it doesn't.
So what do you do instead? That depends on what Macs you own, how you have set them up, and what other precautions you may have taken prior to the start of the trouble.
First things first, if you don't have a recent backup, make one now. But be careful. At this point, you don't want to overwrite an existing backup--lest you replace valid data with corrupted data. Instead, back up to a separate drive. When you're done backing up, here are the things to try. You can try each method until you find one that works:
Boot from the startup drive's Recovery HD partition
The startup drives of Macs formatted with OS X 10.7 (Lion) or 10.8 (Mountain Lion) typically have a hidden partition designed just for moments like this. This 650MB partition is called Recovery HD. Boot your Mac from Recovery HD by holding down Command-R at startup (or by choosing it from within Startup Manager, which you access by holding down Option at startup).
If you are able to boot from Recovery HD, Disk Utility will be one of its four main options. Open Disk Utility and locate the name of your startup drive. You should now be able to select Repair Disk for that drive. From Recovery HD, you can also browse the Web for troubleshooting info using Safari as well as erase your startup drive and restore its contents from a Time Machine backup.
If you are unable to boot Recovery HD via either of these methods, it means there is no Recovery HD partition on your drive or your drive is too damaged to allow successful booting from the partition. In either case, it's time to move on to the next repair attempts.
Boot from your emergency drive
If you previously created an emergency drive (see "Mac troubleshooting: Be prepared for hard-drive failure"), now is the time to use it. Restart while holding down the Option key. From the screen that appears, select the emergency drive. Once booted, things should work nearly identically to starting up from the Recovery HD partition. Launch Disk Utility, choose your startup drive in the list, and select Repair Disk.
Run from a cloned startup drive
If you created a clone of your startup drive, you can boot from the clone and run Disk Utility from there. To do so, restart while holding down the Option key. From the screen that appears, select the cloned drive. When startup is complete, you'll find Disk Utility in the /Applications/Utilities folder, just as it is on your original drive.
You may be wondering: "Does my clone drive include a Recovery HD partition? Could I start up from that partition instead?" Maybe. If you used Shirt Pocket's $28 SuperDuper to make a clone, the clone will likely not have the Recovery HD partition. If you used Bombich Software's $40 Carbon Copy Cloner, it should. However, if you are using a cloned drive, I wouldn't bother with its Recovery HD partition in any case. Instead, boot from the drive directly, as I just described.
Try Safe Boot
To perform a Safe Boot, restart your Mac while holding down the Shift key. According to Apple, a Safe Boot "forces a directory check of the startup volume." This is essentially the same thing as running First Aid's Repair Disk. A downside of this method is that you get no feedback as to whether or not the repair succeeded. Still, if your problems vanish after doing a Safe Boot (and restarting again normally), you can assume that success was likely.
Access your Mac via Target Disk Mode
If you have two or more Macs, you may be able to connect one Mac to the other using Target Disk Mode. To do this, you'll need a cable that can connect the two Macs. For Macs with FireWire ports, that means an appropriate FireWire cable. For Macs with Thunderbolt ports, you'll want a Thunderbolt cable. If one Mac has FireWire and the other has Thunderbolt, you'll need a Thunderbolt to FireWire adapter.
Once connected, boot from the second (properly working) Mac and put the problem Mac in Target mode (by holding down the T key at startup). The Target Mac should now appear as an external drive to the startup Mac. You can now attempt to repair it via Disk Utility.
Boot from Internet Recovery Mode
Internet Recovery mode uses a combination of code stored in your Mac's firmware and a net-boot image stored on Apple's servers to boot your Mac.
To enter Internet Recovery mode, hold down the Command-Option-R keys at startup. Run Disk Utilityfrom there.
I would use this method only if you can't boot from the standard Recovery HD partition. This is because Internet Recovery mode requires that you download the needed software before it kicks into action. Depending on the speed of your Internet connection, this can take anywhere from about 5 minutes to more than 30 minutes. Also, note that Internet Recovery will not work with older Mac models.
Start up in Single User mode
You can do a disk repair attempt by starting up in Single User mode (holding down Command-S at startup) and running Unix's fsck command. This method should almost never be necessary. However, if you find yourself with no other option, an Apple support article details exactly what to do.
You've run Repair Disk. Now what?
You've finally found at least one way to attempt a disk repair with Disk Utility's First Aid or its equivalent. Congratulations. Now what? That depends on the outcome of your attempt:
Your disk is OK: If First Aid reports "the volume appears to be OK," it's time to look elsewhere for the cause of your problem. Ultimately, in a worst-case scenario, a fix could require reformatting your drive, reinstalling a fresh copy of OS X, and restoring your data from a backup. For details on how to do this, see "Should you do a 'clean install' of Lion?" The advice still applies for Mountain Lion.
Your disk has a problem but First Aid repairs it: If First Aid reports a problem and is able to repair it, that's the likely end of the story. Conventional wisdom says to select Repair Disk a second time before quitting Disk Utility, just to be certain that no further repairs are needed. After that, reboot from the repaired drive and hope that all is fine now.
Your disk has a problem that First Aid cannot repair: If First Aid finds a problem but cannot repair it, you can try a third-party repair utility, such as Alsoft's $100 DiskWarrior, which is even compatible with Apple's new Fusion drive. Otherwise, reformatting the drive may help. It's worth a try.
Software utilities and reformatting cannot fix a physical problem with the drive. If your drive is making unusual clicking noises, it's almost certain you have a hardware problem. Assuming you've backed up your data, and given how inexpensive drives are these days, I would replace a drive before wasting too much time trying to resurrect it. If you can't replace the drive yourself (which is likely with recent Mac models, almost all of which Apple has made difficult to pry open), it's time for a trip to an Apple Store or Apple-authorized service provider.