As a sequel to Fix for disk erase failed couldn’t unmount disk, if you really cannot even force unmount a disk, chances are it's being used by some process. I found this tip helpful to locate the process (and then kill it). You may want to give it a try if you can't force unmount a disk the usual way.
For some reason (at least as of this writing), the official Ubuntu documentation on creating a bootable USB of Ubuntu for Macs is now recommending using UNetbootin. I haven't found that to actually work. I dug up a cached copy of the old instructions (which do work), but I wanted to document the old procedure here, just in case the cached copy later becomes inaccessible.
Here are the steps to get a bootable-to-Mac USB of Ubuntu
Launch up /Applications/Utilities/Terminal.app.
In the terminal put in
You may notice that your target.img ends up turning into target.img.dmg, which is totally fine.
Plug the USB stick in and run
Unmount the USB (without unplugging it physically) by running this command
Copy the .img (or .img.dmg) file to your USB using dd:
Then remove the USB drive from your Mac and put it in the Mac you want to boot from. Hold down the option key while booting up, and then select EFI as the drive to boot from.
You know, if your hard drives are set to show as icons on the desktop, you can rename them by selecting them, hitting Enter, and then typing in a new name? If you want to script naming, you can also name from the command line.
For example, if you want to rename the drive you're currently booted to and call it Munki Time, you'd use this command:
Usually, when you add a new partition to a Mac using Disk Utility, you can then just (minus sign) delete the new partition and Disk Utility will automatically expand your first partition to take up the free space.
Occasionally, Macs will act weird and not fill up the free space and, more importantly, not let you manually drag the old partition to fill up the free space. You're just stuck with unusable free space.
There is a relatively simple solution that involves only a couple of terminal commands. (Thanks to the Restore Macintosh HD to its original partition configuration thread on Stack Exchange for the tip.)
Boot up into recovery mode (Cmd-R at startup). If you want to be extra safe, use Disk Utility to back up your first partition in case something goes wrong.
Go to Utilities > Terminal.
Enter in this command:
That's it. Your partition should now be fully expanded.
In older versions of Mac OS X, you could create a special .plist file that auto-mounts disks even when a user isn't logged in. You can see that (no longer working) procedure here. I don't know exactly when support for that ended, but some people have suggested around Mountain Lion. (If you try it in Yosemite, your Mac will get stuck in bootup at Waiting for DSMOS if you run it in verbose mode... or just half a progress bar if you're booting it up in normal mode.)
People still want this feature, though. Here's a recent thread of frustrated people not being able to do it:
10 *still* requires users to be logged in for backup to work.
I'm assuming you already know how to create a script. If you don't, use method #2 in Deleting Mac Keychains in an Active Directory Environment as an example.
Find the UUID of your external drive
There is a universally unique identifier for your drive. Unfortunately, the normal diskutil list command won't show it to you. Instead, when you launch up the Terminal.app, you should run this command (make sure the drive is physically plugged in before you run the command):
Highlight and copy the UUID.
Mount the drive via UUID
To do a quick test of mounting the drive, run a command similar to this:
A visual example
So fire up those launch daemons and go ahead and put that mount command into your script!
If you're trying on a Mac using Disk Utility to erase a hard drive and it won't unmount, giving you an error similar to Disk erase failed. Couldn't unmount disk, then you may have to force an unmount through the terminal.
Launch up Terminal.app (through /Applications/Utilities or through a Spotlight search).
Then paste in the command:
Find the one you want to force unmount. For this example, let's say it's /dev/disk2.
Run a command similar to this one
You should now be able to erase the drive.