To partition and format a disk in OS X, you generally open Disk Utility, select the disk in the tool's sidebar, and click use the Partition tab to select and apply a partition scheme; however, there may be times when this will not work, and Disk Utility will give you an error such as the disk cannot be unmounted, or that the resource is busy.
Sometimes when errors like this occur, it suggests the drive may be failing; however, this is not always the case. At other times, the drive may simply be experiencing some partition table troubles or be used in ways that prevents Disk Utility from modifying the tables.
If when attempting to repartition a disk you are met with "resource busy" or "cannot be unmounted" errors, first try using a different tool than Disk Utility to tackle the job. Sometimes secondary tools and approaches can at least modify the partition table enough to allow Disk Utility to overcome its hangup and work properly.
There are a number of third-party tools out there that can rebuild and otherwise manage a faulty drive, but Apple also supplies tools other than Disk Utility that will work.
The first of these is the "fdisk" tool, which is geared toward managing DOS-formatted drives, but can be used to initialize the drive with an MBR partition table. To do this, open the Terminal and run the following command (be sure to replace "disk1" with the device identifier for your specific disk--this can be looked up using the "diskutil list" command):
fdisk -i -a hfs /dev/disk1
The second option is to use the "gpt" command (for managing GUID partition tables) to destroy the current GUID partition table on the device. To do this, in the Terminal run the following command, again replacing "disk1" with the identifier for your drive:
gpt destroy /dev/disk1
These two command should allow you to overwrite the drive's partition scheme and allow you to set it up again as a raw device in Disk Utility; however, if you still get troubles when managing the drive with these, then there are two more approaches that may work.
The first is to make use of the random number generator device to overwrite the drive's contents. As with most UNIX systems, OS X accesses devices through enumerated node files located in the hidden /dev directory, and for disks these files are called "disk0," "disk1," "disk2," etc., and can be used in commands as seen above. In addition to valid devices, the system contains a number of special nodes, one of which is the classic "/dev/null" device that will accept redirected text output from commands and not save it to the console, allowing for cleaner use of some commands.
In addition to /dev/null, there is the random number generator /dev/random that will write random numbers in a string as long as it's accessed. One way to do this is to use the "cat" concatenation command to output these numbers from this generator, and then redirect these numbers to the problematic drive device, to overwrite it and clear any odd partition schemes it may have. The command to do this is the following:
cat /dev/random > /dev/disk1
Again, be sure to replace "disk0" with the appropriate drive identifier. This approach has been useful for clearing a stubborn CoreStorage setup on a drive (ie, that being used to encrypt it), that otherwise could not be cleared using the diskutil command.
Finally, if the drive is an internal one and especially if you are booted to it (normally, or to Apple's Recovery partition), then you will likely be able to overcome partitioning frustrations by managing it as an external or secondary disk from another OS installation. The options here are to install OS X to an external drive and boot off of that to access your main drive, or start the system in Target Disk mode, and attach it to a second one with a Firewire or Thunderbolt cable. With the drive mounted as a secondary device, you can now likely use Disk Utility to successfully partition and otherwise manage the drive.