How do I fix a corrupted USB drive on OS X?

I accidentally bumped the drive while repartitioning it and it unmounted. After that when I tried to repartition with Disk Utility I got Partition Failed with the error: Could not open device

Now I am unable to modify the drive with Disk Utility. I don't really care about what is on the drive.


Step 1

Open Disk Utility (it is in Applications/Utilities) and click New Image with the device you want to fix selected

New image

Step 2

It doesn't matter what you name it but put it on your desktop so you can find it easily. Make sure it is a read/write.

Make Disk Image

Step 3

Find the disk on your desktop and open it. It should be empty.

Disk image

Step 4

Open Terminal (in the same place as Disk Utility) and type in diskutil list and locate your drive. It should have something similar to the name that shows up in disk utility indented under it (in my example it doesn't)

disktutil

Step 5

We are going to use a Terminal utility called DD to copy the contents bit by bit of the disk image we created to the drive. Make sure you do this right because you can seriously damage your hard drive if you don't. Feel free to ask questions.

This is the layout of dd: dd if=<source> of=<target> bs=1m

So type dd if= and then drag the drive (the one I named "Something") into the terminal window. After that copy the /dev/disk# from the diskutil command of your disk. Make sure it is the right one or you will overwrite your hard drive or other connected drive. Adding onto the dd command type of= and paste the /dev/disk#. Now add bs=1m to that.

Now in the dd command you should have something that looks like:

dd if=/Volumes/Something of=/dev/disk1 bs=1m

This is what it would look like for my example.

If everything looks ok then press enter.

This can take a long time and will not tell you what is happening until it is done. It will just be a blank line in the terminal. When you press enter just let it go until it is done. You will know when it is done because it will tell you something like copied something bytes....

Final step

Now that you have done that you should be able to go back into disk utility and repartition your dive under the partition tab. If you don't know how to partition it, just click the plus button near the bottom left, name your partition, and make it Mac OS Extended (Journaled) and click apply.

Remember if you are unsure, something is different in the steps, or something doesn't work, ask questions!