If a /dev/diskX can’t be force unmounted…

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.


How to create a bootable Ubuntu USB stick on/for Macs

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

Go to the list of alternative downloads and use a BitTorrent client (e.g., Transmission) to download a .torrent of the desktop version of Ubuntu.

Launch up /Applications/Utilities/

In the terminal put in

hdiutil convert -format UDRW -o /path/to/target.img /path/to/nameofubuntu.iso
but substitute in your actual paths to the names of the files.

You may notice that your target.img ends up turning into target.img.dmg, which is totally fine.


diskutil list
to get a list of the drives/partitions on your Mac.

Plug the USB stick in and run

diskutil list
again to find the new drive name, based on what didn't show up the last time you ran the command. For the sake of this example, we'll assume it's /dev/disk2, but pay careful attention to your actual USB's name, which may be different.

Unmount the USB (without unplugging it physically) by running this command

diskutil unmountDisk /dev/disk2
(being sure to substitute in your actual disk number for disk2).

Copy the .img (or .img.dmg) file to your USB using dd:

sudo dd if=/path/to/target.img of=/dev/rdisk2 bs=1m
Put in your actual disk number, if it's not 2.

If it copied correctly, you should actually get an error message:ejectubuntu Click Eject.

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.


Renaming a Mac hard drive from the command line

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:

diskutil rename / Munki\ Time
The forward slash represents the root (top-level) directory and the backslash just escapes the space, so the terminal knows you're including Time with Munki as one label.


Restoring a Mac partition to its full size

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:

diskutil cs list
and get the Logical Volume UUID of your partition-to-expand.

Then run


You should see the progress of your partition expanding.

Then you'll see it verifying the volume.

That's it. Your partition should now be fully expanded.


Mounting an external drive when users are logged out in Mac OS X


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.

Major Prerequisite

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, you should run this command (make sure the drive is physically plugged in before you run the command):

diskutil list -plist
and that will show you your external drive's UUID.

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:

diskutil mountDisk yourreallylonguniversallyuniqueidentifierfordrive
Whether that drive was already mounted or not, it should (if the command worked) display a message that says Volume(s) mounted successfully.

A visual example

Here you can see an example.

So fire up those launch daemons and go ahead and put that mount command into your script!


Fix for disk erase failed couldn’t unmount disk

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 (through /Applications/Utilities or through a Spotlight search).

Then paste in the command:

diskutil list
to list out the different disks. You should see some disks appear like /dev/disk0, /dev/disk1, /dev/disk2.

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

sudo diskutil unmountDisk force /dev/disk2
If you're prompted for a password, enter it (yes, your account does need to have administrative privileges). You should not physically unplug the drive.

You should now be able to erase the drive.