Format An Unformattable Flash Drive In OS X

It’s always satisfying to fix something that seems impossibly broken.  I recently fixed a broken flash drive that could not be reformatted.  I first tried to repair the disk using Disk Utility, but that option was completely greyed out (same thing in the Recovery HD).  So then I tried to erase it but was presented with the error “OS X can’t repair the disk “MYDISK”.”


Next, I tried to partition the disk and received the error message “Disk Erase failed: Disk Erase failed with the error: Unable to write to the last block of the device.”


After some searching, I came across this helpful post.  Here are the steps I used to fix it:

Find The Disk Device File Associated With The Drive

First, you need to find the device file that corresponds with your flash drive.  Run this command:

diskutil list

You should see some entries like /dev/disk0 , or /dev/disk1 .  Take note of the one that is assigned to your flash drive.  It will be used in the next steps.

Format The Drive Before The System Completely Grabs Onto It

This is the weird part.  You will be using this command (make sure to substitute your device file if it is different) to write random data to the flash drive (which is essentially what reformatting does anyway):

First, become root:

sudo su

Repeatedly run this command (using the up arrow to access it again), while plugging in your flash drive until the command prompt disappears (meaning it is writing to your flash drive).  If you get the resource busy error.  Unplug the drive and try again.  You just have to get the command to run just as the flash drive is plugged in.

cat /dev/random > /dev/disk1

Take a look here for the full instructions and details as they explain everything very well.

13 Replies to “Format An Unformattable Flash Drive In OS X”

  1. It would be faster to do the wipe using /dev/urandom. Or if you want real fast speed and don’t care about forensics, /dev/zero. I personally use the following.
    # sudo dd if=/dev/zero of=/dev/rdisk1 bs=1m
    “rdisk” is faster then disk

    1. I can surmise that /dev/zero just writes a bunch of zeros to the disk, but what is the difference between /dev/urandom and /dev/random that makes it so much faster?

      1. /dev/random will block after the entropy
        pool is exhausted. It will remain blocked until additional data has
        been collected from the sources of entropy that are available. This can
        slow down random data generation.

        /dev/urandom will not block. Instead it will reuse the internal pool to produce more pseudo-random bits.

        /dev/urandom is best used when:

        -You just want a large file with random data for some kind of testing.

        -You are using the dd command to wipe data off a disk by replacing it with random data.

        -Almost everywhere else where you don’t have a really good reason to use /dev/random instead.

        /dev/random is likely to be the better choice when:

        -Randomness is critical to the security of cryptography in your application – one-time pads, key generation.

  2. guys im young, and i do not understand what all of this complicated stuff means, can someone please explain how avoid this error in an easier way please.

    1. Hmm. I remember when I first did this, it took a while to get the timing just right. But I’m glad you got it to go.

  3. before my computer recognizes the drive, it says “Operation not supported.” So I keep repeating the code hoping I can catch it at that right time. Instead, once my computer recognizes my drive, I get the message “No such file or directory.” What am I doing wrong?

    1. It’s probably a timing issue and there is no guarantee it will work depending on the level of corruption. Try again to run the command at just the right time.

Leave a Reply