How to fix deep formatting problems with OS X drives

DiskUtilityIconXEven though formatting advances like Journaling in Apple’s filesystem formats help prevent data corruption, problems can still happen that result in a drive not only being unreadable, but also unable to be reformatted.

If this happens, the drive may show up in the Finder sidebar but not show data when clicked, or it may just not show up but be present in Disk Utility; however, if you try to mount it you get a “resource busy” error. Another possible symptom is if you get this error or one claiming the drive cannot be unmounted, when trying to format the drive or running a fix routine on it with Disk Utility.

These errors and behaviors might indicate to you that your drive is malfunctioning and you need a new one; however, before you give up on a $100+ drive, ensure the problem is not simply a very low-level formatting snag that causes the drive to hang when accessed. This is especially true if you do not hear any tell-tale signs of physical failure, such as repeated click, tap, and whirr sounds coming from the drive at regular intervals.

Assuming the drive is just experiencing major low-level corruption, the problem you face now is how to format a drive that apparently cannot be formatted on your Mac? One option is to use another operating system like Windows in Boot Camp, in a Virtual Machine, or on a dedicated PC to manage the drive and attempt to repartition it; however, this may not be feasible in some situations.

Another option that should work in most cases is to use the Terminal to interact with special device files to force an overwrite of the device file representing the drive.

OS X Device files

Device file list in OS X

The /dev folder has a number of different device files that are assigned to system components and peripherals, allowing programs to interact with them using system calls. These devices include disks, consoles, terminals, and standard input and output, among others (click for larger view).

Device files in OS X are a collection of drivers in the hidden “/dev” directory that are assigned to devices, allowing them to be accessed by system calls (open, read, write, close, etc.). These allow programs to interact directly with the device, so for instance you can use a filesystem manager like the “diskutil” command to get information on, or fix a device.

For local storage drives, your boot drive is the first enumerated disk device, so it will be assigned the device file /dev/disk0, and you can get information on it in the Terminal by running the following “diskutil” command:

diskutil info /dev/disk1

In Unix-based systems like OS X, often there are some special device drivers, such as /dev/null, or /dev/random, which instead of providing access to system devices, offer unique services. For /dev/null, this device acts like an instant trash can for any information sent to it, and is useful for scripting and programming. When /dev/random is accessed and read, it will output random data. You can see this by running the following command in the terminal to read through the “random” device file (be ready to press Control-C to stop the torrent of characters that will be output from this command):

cat /dev/random

Fixing your drive

If you have a local storage drive that is malfunctioning, and especially because of a low-level formatting issue, then you can use the random number generator device to force overwriting of the hard disk. This will destroy any partitioning schemes and current formatting, and make the drive appear to the system as a blank storage device. With this effort, the hope is to bypass the corrupted drive logic that is causing the system to hang up when accessing it, but since the drive is captured by the system and held in a “busy” state whenever attached, doing this may require using Terminal commands in special timing:

  1. Open the Terminal utility (Applications > Utilities) and enter “root” mode by running the following command (supply your password when prompted—it will not be shown):
    sudo su
  2. Run the following command to get a list of drives and their corresponding device files:
    diskutil list
  3. Peruse the output of this command and identify the drive by partition name and size, and then note the device file assigned to it (see “A” in the screenshot to the left).
  4. Force-overwriting a drive in OS X

    Running “diskutil list” (A) will show the drives and corresponding partitions. Use the located device file (arrows) repeatedly in the command to overwrite the disk (B) after you have attached it to the system (click image for larger view).

    Run the following command to attempt to overwrite the contents of the device file (which is the contents of the disk). Note that when this command runs successfully, the cursor will drop to an empty line and wait, instead of returning to the command prompt. During this time, the command will be writing to the disk, so you can wait a few moments and then press Control-C to halt the command. While the device “disk1″ is used in this example, be sure to replace it with the device you found in step 2 above:

    cat /dev/random > /dev/disk1

It is likely that this command will initially result in an error claiming the disk resource is busy; however, this does not mean the command won’t work. Instead, it just means you ran the command after the system captured the device and got stuck trying to manage it. If you see this error, then do the following:

  1. Press the Up arrow key in the Terminal to load and prepare the previously entered command.
  2. Unplug your drive and plug it back in.
  3. Immediately press Enter, and if you see the same error, then press the Up arrow key again followed by Enter again.
Blank drive in disktuil

After the command has run for a few moments, if you cancel and then re-run “diskutil list” you will see the drive listed with no partitions on it, indicating it has been wiped (click for larger view).

Repeat step 3 as fast as you can, until the Terminal cursor drops to a new line without returning to the command prompt (see “B” in the screenshot above). This will indicate the command has captured the device before the system, and is now overwriting it.

Allow the command to continue for a minute or two before pressing Control-C to cancel it. At this point you can open the Disk Utility program and you should see your drive with no storage volumes available. You can then partition and format the drive to prepare it for use in OS X.

58 thoughts on “How to fix deep formatting problems with OS X drives

  1. MaX

    This is what I get for a pendrive:

    /dev/disk4
    #: TYPE NAME SIZE IDENTIFIER
    0: GUID_partition_scheme *32.7 GB disk4
    1: EFI EFI 209.7 MB disk4s1
    2: Apple_HFS LaCieXtremKeyUSB3GUI… 32.4 GB disk4s2
    sh-3.2# cat /dev/random > /dev/disk4
    sh: /dev/disk4: Resource busy
    sh-3.2# cat /dev/random > /dev/disk4
    sh: /dev/disk4: Operation not supported
    sh-3.2# cat /dev/random > /dev/disk4
    sh: /dev/disk4: Operation not supported
    sh-3.2# cat /dev/random > /dev/disk4
    sh: /dev/disk4: Operation not supported
    sh-3.2#

    To cut a long story short, the pendrive is 
LaCie XtremKey USB 3.0
http://www.lacie.com/us/products/product.htm?id=10612

    It broke when automatically unmounted while copying a VMware Fusion disk image.
    Since I cannot repair it (Disk Utility, DiskWarrior, TechTool Pro, DiskTools Pro & SpeedTools Utilities Pro, and Drive Genius on Mac with OS X 10.9.2 Mavericks), I just want to format it, yet I cannot with any tool tested so far.

    Any idea how to repair or format it?
    
Thanks.

    Reply
    1. Topher Kessler Post author

      Repeating the “cat /dev/random > /dev/disk4″ command at the root prompt will require timing. When it says “Operation not supported,” it means the disk4 device file is not yet assigned to the device. If it says “Resource Busy” then it means the device has been assigned but has been captured by other processes and cannot be handled by system calls.

      Try again, repeating the “cat /dev/random > /dev/disk4″ command rapidly by pressing the up arrow, followed by Enter, to capture the disk between the time it is assigned the device to where other processes take it over. It may take a few attempts but it should be doable.

      Alternatively, you can try placing the command in a looping script and then run the script as root, to apply the command as fast as possible:

      1. Open the Terminal and run this command:

      pico formatdrive.sh

      2. Copy and paste the following into the editor that appears:

      #!/bin/bash
      while [ 1 ]; do
      cat /dev/random > /dev/disk4
      done

      3. Press Control-O to save, followed by Control-X to exit.

      4. Run the following command to make the script executable:

      chmod 777 formatdrive.sh

      5. Now switch to root in the Terminal

      sudo su

      6. And finally run the script, immediately followed by attaching your drive to the Mac:

      ./formatdrive.sh

      When you do this, the script will run rapidly and output many “not permitted” or “permission denied” errors, but should halt on one when the drive is mounted. When this happens, wait a few moments as mentioned in the article, and then close the Terminal, confirming to cancel running processes. If you simply press Control-C will cancel the command but the script will start it right up again.

      When this is done, you can then try using Disk Utility to partition and format the disk for use again.

      Reply
      1. MaX

        Many thanks Topher for your comprehensive reply. I have done as you indicate:

        – The “Press Control-O to save” (step 3) did not save the formatdrive.sh file. I had to press the carriage return and then it was saved at “Macintosh HD/Users/~” and the Terminal nano showed [ Wrote 4 lines ].

        – At step 6, I got the following:

        Last login: Mon Apr 7 13:56:43 on ttys001
        [MacOSX-X:~] me% chmod 777 formatdrive.sh
        [MacOSX-X:~] me% sudo su
        Password:
        sh-3.2# ./formatdrive.sh
        ./formatdrive.sh: line 3: /dev/disk4: Operation not supported

        With hundreds of such last line in a row (several each second!). After about 15 minutes waiting, I unplugged and plugged back the pendrive. Then Terminal stopped not showing mure of such last line (no other message shown).

        Then I closed the Terminal window selecting “Shell – Close Window”, and opened Disk Utility, selected the drive on the left and clicked the Partition tab. I named it as LaCie, and selected 1 Partition – Mac OS Extended (Journaled). Options as GUID Partition Table. After clicking Apply, I got:

        Partition failed
        Partition failed with the error:
        Couldn’t unmount disk.

        When I tried again, I got:

        Partition failed
        Partition failed with the error:
        Disk object invalid or unable to serialize.

        An then such last error message for all consecutive trials. I got the same last error when afterwards selecting Options as Apple Partition Map, as well as Master Boot Record.

        What could I do next?
        Thanks again for your great help!

        Reply
        1. Topher Kessler Post author

          This command should overwrite the partition table, but if the drive is working then the system should be able to recognize it as blank media and write another partition table to it. My guess is if wiping the drive like this does not work, then it is likely the drive is beyond repair. However, before giving up, run “diskutil list” and see if there are any partitions listed for the faulty drive (there shouldnt be if the above process was run correctly).

          Reply
  2. MaX

    This is what I get (Mac mini with 1TB Fusion Drive):

    Last login: Tue Apr 8 12:42:54 on console
    [MacOSX-X:~] me% sudo su
    Password:
    sh-3.2# diskutil list
    …/…
    /dev/disk4
    #: TYPE NAME SIZE IDENTIFIER
    0: GUID_partition_scheme *32.7 GB disk4
    1: EFI EFI 209.7 MB disk4s1
    2: Apple_HFS LaCieXtremKeyUSB3GUI… 32.4 GB disk4s2
    sh-3.2#

    The disk4 is the drive (pendrive). Before doing what you explained in the article, Disk Utility showed a single volume (partition) inside the drive. After doing what you said, Disk Utility shows no volumes inside. Yet, I cannot partition the drive. This is what I get when I try to partition it with Disk Utility:

    Partition failed

    Partition failed with the error:
    
Couldn’t unmount disk.

    And when I try to partition again:

    Partition failed

    Partition failed with the error:
    
Couldn’t open device.

    And then (in all subsequent trials):

    Partition failed
    
Partition failed with the error:

    Disk object invalid or unable to serialize.

    Could it be possible to partition/format/erase such pendrive? Thanks again.

    Reply
    1. Topher Kessler Post author

      I’m still leaning towards this drive having some hardware fault, but you can try the above procedure again, but this time wait a very long time for the “cat /dev/random > /dev/disk4″ command to run before canceling it. This will ensure more of the drive is overwritten by the command, and possibly allow you to recover it.

      Reply
      1. MaX

        Thanks for your help. I have done as you said. Terminal was indicating hundreds of the following lines in a row (several per second):

        ./formatdrive.sh: line 3: /dev/disk4: Operation not supported

        And Menu Meters
        http://www.ragingmenace.com/software/menumeters
        showed high CPU activity (the Mac mini fan could be heard also). If then I unplugged and plugged back the pendrive, it stopped showing such message line (and the CPU activity was down and no fan heard). But after eight minutes, it started again. I did that several times.

        I also left such activity running for about four hours (doing nothing else on the Mac). Eventually the Mac rebooted itself (!). I got the message:

        Your computer was restarted because of a problem.

        Now the pendrive shows both the drive and the single volume inside on the left pane of Disk Utility, as did before doing what is indicated in your article above.

        If I run Disk Utility repair for the drive, I get:

        Alert
        Some information was unavailable during an internal lookup.
        Verifying and repairing partition map for “LaCie XtremKey Media”Checking prerequisites
        Problems were encountered during repair of the partition map
        Error: Some information was unavailable during an internal lookup.

        If I try to partition the drive, the Apply button is grayed, so I cannot do it (before today it was possible, as described above).

        Any possibility to format this pendrive. I am lost.

        Thanks again for your kind help!

        Reply
        1. Lloyd

          I also use a 1 TB hybrid drive from Seagate in a MacMini, two LaCie external enclosures and a Pro Book. When trying to use Apple’s Disk Util for adjusting partitions or reformatting, I would end up with a greyed selection or what appeared empty space that could not be recovered. (Using 10.6.x.)

          To look back a bit, I was a fan of LaCie’s SilverLining and used it until OS 10. Much information, along with graphic illustrations of all the partitions on a drive. When I was finally stuck with Apple and 10.6, I looked around and found a program named iPartition. Gives all of the infor SilverLining did, and better control over partitioning. You cannot use it on the same drive you are trying to partition or change partition sizes, attempt to activate, etc., but I assume you are using an external drive you can boot from.

          I’m pretty cautious when it come to running just about any tool on my working, main, drive, but I have never found an issue with this program. Just in case, always back up what you don’t want to lose, but in the few years I have been using it, no problems.

          http://coriolis-systems.com/iPartition/

          Reply
  3. B. 9776Jefferson Le Blanc

    Before reformatting a drive that is reporting mount errors, try restarting your computer. I get this kind of error on occasion and restarting will render the drive usable again. I surmise that, in this case, the problem is not with the drive but with the system which has somehow become constipated, for lack of a better word. Of course if the drive truly is damaged this will not help. My point is that there can be other, less serious, reasons for a drive to become inaccessible or unresponsive and drastic measures should not be the first resort. I sometimes run into mount errors when I’m in the process of testing or repairing a drive with Disk Utility. In my experience, the process of un-mounting and mounting drives and partitions can actually precipitate mount errors which, as I said, can be resolved with a restart.

    In a situation like MaX has encountered, while trying strenuously to save a pen drive may have intellectual value, or provide an interesting challenge to an experienced troubleshooter, on the whole the time and effort you expend in trying to resurrect the drive may be more than the replacement cost of the drive. Given that the procedure Topher describes effectively erases the drive, there will be no data to be salvaged and thus the value of the data is not part of the equation.

    Of course, with a large hard drive this value equation will be different, and a conscientious effort to salvage the drive may be appropriate. Even here, though, one will eventually reach a point of diminishing returns. It’s also worth mentioning that pen/keychain drives are inherently less reliable than hard drives and optical media. For this reason they should be used only for temporary storage.

    In the case of hard drive problems, the best solution is to regularly back up the data on your drives. This way, if the drive truly is broken, at least your data will be safe. Some really conscientious people keep multiple backups and regularly rotate these from older to newer media. Others use mirrored RAIDS to insure data integrity. These are more expensive solutions and their use will depend on the intrinsic value of the data, the budget available for a backup solution – and one’s inherent paranoia or the impact of one’s experience with drive failure and data loss.

    All that said, I will save this article because it offers a solution beyond what most disk utilities offer. Indeed, I have thought before this that such a solution must be available somewhere; I guess it was only a matter of time before Topher uncovered it. Thanks. There really are some problems for which Terminal is the only solution.

    Reply
  4. MaX

    Thanks. I have restarted many times to no avail. Actually, I have been trying to first repair and then format this pendrive for about a year now.

    I think it could be possible to format it, flashing it; reloading the drive’s firmware and performing a low-level formatting. But that does not seem to be an easy procedure, depending on the manufacturer, etc. Somebody knows how to do it for the LaCie XtremKey USB3 pendrrive? Thanks.

    Reply
    1. B. Jefferson Le Blanc

      I checked out those drives on Amazon – I can see why you‘re trying to restore it. They‘re expensive. But all that environmental durability is wasted if the drive itself tends to fail. Have you contacted LaCie about the problem? If anyone knows how to get it working again they should.

      Otherwise, if Topher’s solution doesn’t work, you may have to face the probability that the drive somehow sustained irreparable damage. And, if you replace it, you may want to consider whether you really need such a physically robust keychain drive. You could buy a lot of standard and even security enhanced thumb drives for the price of one of those LaCie XtremKey USB3 pendrrives.

      Sorry I have no better solution to offer.

      Reply
  5. MaX

    Yes, I have contacted LaCie, and they say that they do have the tool to reload the drive’s firmware, but it is only for internal use within LaCie. So, no joy there.

    Reply
    1. B. Jefferson Le Blanc

      Given how stingy they are in supporting a product you paid over $150 for, I’d say you should be sure and buy your next flash drive from someone else. And plaster the web with bad reviews describing the one you have and LaCie’s failure to support it. Their parsimonious and short-sighted behavior deserves all the bad news you can spread about them. As the saying goes, don’t get mad, get even.

      Reply
  6. Hermeskeiler

    That has helped me several times: “Formating USB with Manufacturer Tool.”
    You need the VID und PID of your stick, try ChipEasy.
    The flash utils you can find at http://flashboot.ru/iflash/

    Reply
  7. MaX

    Awesome! I have found it:

    LaCie XtremKey 32 GB
    VID: 059f
    PID: 106c

    But how to flash it? There is no flash utility for LaCie at FlashBoot.

    Topher, an article about this topic would be awesome.

    Thanks.

    Reply
    1. B. Jefferson Le Blanc

      MaX: If you look up ChipEasy on Google or Bing you’ll find links to some software for flashing drives – for which you’ll need the VID an PID numbers you found. But they are Windows apps – you’ll need access to a Windows PC or a virtual machine in Parallels of VMWare Fusion.

      Reply
  8. MaX

    This is what I get when trying to connect the pendrive (LaCie XtremKey USB3 GUID 32GB) to Windows XP SP3 on VMware Fusion 6.0.2 on Mac with OS X 10.9.2 (Mavericks):

    The device “LaCie XtremKey USB 3.0″ was unable to connect to its ideal host controller.
    An attempt will be made to connect this device to the best available host controller. This might result in undefined behavior for this device.

    Therefore, I cannot use
    ChipGenius_v4_00_0027_pre2
    or
    ChipEasy_EN_V1.5.6.6

    But just for the sake of the information, I have connected another WORKING but older pendrive (LaCie XtremKey USB2 GUID 16GB) to see what I can get:

    1. First, ChipGenius_v4_00_0027_pre2
    from
    http://dl.mydigit.net/2010/09/chipgenius.html
    says:
    Description: [F:]USB Mass Storage Device(LaCie XtremKey)
    Device Type: Mass Storage Device
    Protocal Version: USB 2.00
    Current Speed: High Speed
    Max Current: 2mA
    USB Device ID: VID = 059F PID = 1038
    Serial Number: XXX
    Device Vendor: LaCie
    Device Name: XtremKey
    Device Revision: 0100
    Manufacturer: LaCie
    Product Model: XtremKey
    Product Revision: Dev
    Controller Part-Number: Unknown <——————————————————— NO DATA!!!

    2. On the other hand, ChipEasy_EN_V1.5.6.6
    from
    http://flashboot.ru/files/file/361
    says:
    Logical drive : F:\ Capacity: 14.3G
    Device ID : VID = 059F PID = 1038
    Device SN : XXX
    Device version : Dev
    Device vendor : LaCie
    Device model : XtremKey
    Protocol : USB2.0
    Max power : 2mA
    Partition type : HFSJ Device active : no
    Aligned state : 204820 KB, Have been Aligned
    Controller : <———————————————————————————– NO DATA!!!
    Controller model: <——————————————————————————- NO DATA!!!
    Tools :
    OS Version : Microsoft Windows XP Professional Service Pack 3
    Update Status : The current version is the latest version!

    So, no data is shown for the controller.

    I can see the defective LaCie XtremKey USB3 GUID 32GB with Disk Utility on Mac (showing its volume inside on the left pane) but when I try to Erase it, I get:

    Disk Erase failed
    Disk Erase failed with the error:
    Couldn’t unmount disk.

    If I click the Partition tab, I get the spinning color wheel and
    Option Command esc
    shows that Disk Utility is not responding. After a few minutes, it shows the Partition window, but after selecting the Partition Layout (1 Partition), the Apply button is grayed (and I cannot type inside the Name or Size fields).

    Any idea on how to repair or format this defective pendrive will be most appreciated.
    Thanks!

    Reply
    1. B. Jefferson Le Blanc

      MaX: I see one other possibility: You might try using those utilities on a newer version of Windows – on an actual Windows PC. First, XP is very old (as operating systems go) and may not support the necessary drivers for your USB device. There’s also the question, using virtualization, whether you have Fusion set to use the Apple drivers or have loaded the Windows drivers and selected them. You can do either one with both VMWare Fusion and Parallels. The default behavior is to use the Apple drivers to access external devices because, in most cases, that is simpler and more transparent. But you can change that setting. If you do, Windows may direct you to download the drivers you need, which means more rooting around on Windows web sites. If you have access to a Windows PC you might get more reliable results with the utilities in question, and it might ultimately be simpler. If you can access the drive on Windows, go ahead and format it Fat 32. If you can formate the drive on Windows, you can then mount it on your Mac and reformat it HFS+ if you like. Though Fat 32 will work OK on a Mac for data storage, as long as you don’t need to install OS X on it. The advantage of using Fat 32 is that the drive will also be usable on a Windows PC, supposing that necessity ever arises. On a side note, most flash drives are formatted Fat 32 because that is sufficient for the smaller sizes flash drives come in. Also, if you could format a flash drive with the newer NTSF format, if would not work on a Mac without additional software.

      Reply
      1. MaX

        After almost a year, I did it! No way trying to repair the pendrive or format it either on Windows on Fusion (VMware) on Mac, or directly on Windows on a PC.

        The only solution was to flash it on a Windows PC (I used Windows XP SP3). The flashing tool found that it had one bad block (probably the first one, which prevented formatting). After flashing it (which formats it as well), the pendrive works fine. Amazing!

        Surprisingly, the LaCie XtremKey USB3 GUID 32GB previously (before breaking as described above) had a capacity of 32.37 GB (32.26 GB available; LaCie XtremKey media), but after flashing and re-formatting with Apple Disk Utility, it shows a larger capacity of 32.79 GB (32.68 GB available; Innostor Innostor media). So, LaCie flashing takes 42 MB more than the native Innostor (!). No Spotlight Index in all cases.

        Topher, it would be great if you could write an article about it. The procedure involves visiting a Chinese site (to get ChipGenius to reveal the VID, PID and Controller chip part number), and and Russian site to get the flash tool for such specific controller.

        Reply
        1. B. Jefferson Le Blanc

          While Topher’s expertise is remarkable, it was you who solved the problem through incredible persistence (with a nudge here and their from interested parties). While Topher may be able to reconstruct what you did in a general way, you are the one who knows the nitty-gritty details of the project. May I suggest you write it up yourself and then ask Topher to publish it on MacIssues, if not on the main page, then on the forums as a stand-alone topic. The subject certainly begs condensing from the rambling dialog on this thread. And, if you do write it up, I suggest you include links to the sites from which you downloaded the necessary software – the more direct the link, the better. Not everyone will have your skill at sniffing out items on non-english web sites.

          And finally – congratulations! No doubt the time you spent on this was worth far more than the cost of the drive, but nothing can match the satisfaction of solving such a difficult problem. Keep up the good work.

          Reply
        2. Tim

          congratulations! I’ve been digging and reading this string of events hunting for clues on my own quest. many many many parallels.. I am very barely grasping and hanging on to much of what you guys are kicking around.. so please bare with me… but yeah, i’ve got a bad block on a 128 gb toshiba ssd, ( which i think may have been caused by the knucklehead who sold it to me rushing to prove it worked and formatting it in front of me and prematurely yanking the cable out. ) but anyway, was trying the whole terminal fix to hopefully write over as described, but wasn’t able to hit that sweet spot, and catch a break..

          so yeah i’m writing this to congratulate on your successful inhuman perserverance against all odds and in the name of principle and refusing to give in… but also for some assistance, in hopefully finding some how some way to flash this drive and be able to resurrect it.. please don’t leave me danglin. cheers and thanks for your time and consideration

          Reply
  9. Andrei

    Hi,

    I have tried to shrink my external drive in disk utility and the power shut down in the process.
    When I restarted the pc , everything dissapeared. I formated my HDD from hfs to fat. I need to recover all my work. there was my 4 years work and now is gone.
    Can you please give me your advice.

    Thanks a lot.

    Reply
    1. Topher Kessler Post author

      By reformatting your drive you wiped out the indexes that tell it where files are on the drive. Your only option for recovering your files would be to use a file recovery tool like DiskDrill, or Prosoft Data Rescue, to scan the drive for file structures and try to recover them. This will likely not recover everything, but should be able to get at least something. Be sure to not use your drive before doing this, as using it will overwrite the data on the drive and make it impossible to recover.

      Reply
      1. B. Jefferson Le Blanc

        This is just one more sad example of data lost because it wasn’t backed up. The first thing Andrei should have done before trying to shrink his drive was back it up. Adjusting a drive’s partition size is a risky procedure at the best of times. Ignoring the possibility that something might go wrong only compounds the problem.

        Of course, not knowing that reformatting a drive would make the data on it inaccessible is serious technical malpractice. The reformat procedure even warns you that your data will be lost. Apparently Andrei didn’t read, or didn’t heed the warning.

        It’s tempting to scoff at such foolishness, but Andrei has already been severely punished for his lack of foresight. Since I, too, have lost data from time to time, I should follow the prescription that people living in glass houses shouldn’t throw stones.

        Be that as it may, the moral of this story is back anything and everything you don’t want or cannot afford to lose. Ignore this warning at your peril.

        Reply
  10. MaX

    Topher, as I said above, it would be great if you could write an article about it (flashing pendrives). The procedure involves visiting a Chinese site (to get ChipGenius to reveal the VID, PID and Controller chip part number), and and Russian site to get the flash tool for such specific controller.

    Could you do that in the future? Thanks.

    Reply
  11. Jello

    This worked. Someone flipped a breaker during a restore session and I almost cried when I got the error that my encryption made my drive useless. I used this and was able to remount the restore from time capsule, and I almost cried with joy. Almost. Lol. Thanks so much for this.

    Reply
  12. Jerry Krinock

    It worked for me. The additional advice from Topher was also helpful. Plug that baby in, then immediately start hitting ‘enter’ followed by up-arrow until you start getting “^[[A” instead of errors.

    Reply
  13. ali

    i follow the instructions but when i repeat the up key and enter, i got a new error: permission denied.

    what would be the problem in my case?

    Reply
  14. Mansha

    Thank you so Much! I had pretty much given up when I came across your post. A totally radical solution. Handling the terminal scared me but your instructions were great and my disk is formatted. Thanks again!!!

    Reply
  15. Ralph

    I followed your instructions which are well documented and very much appreciated.

    As a FYI, the result I got upon trying to run the ./formatdrive.sh batch file due to the operation not supported or device busy situation caused my Mac to crash when the faulty drive came on line.

    OS X Yosemite 10.10.1 (14B25)

    I then checked (after the Mac finally came back from the white screen) to see if DiskUtility could do anything. Same result there. Could not repair or erase the disk. Not sure if the batch file worked or not but it was exciting to see what happened to the Mac. Glad no other damage was done.

    Reply
  16. xhoenner

    Thanks a lot for that very detailed post, I was about to contact the manufacture (WD, My Passport 2TB).

    I couldn’t get that cat /dev/random > /dev/disk2 to run successfully after unplugging/replugging my hard drive in.

    So what I did was to identify the process that the OS was running using ‘ps aux | grep /dev/disk2′, which gave me:
    root 2505 100.0 12.6 3511284 1053484 ?? R 11:20am 3:15.82 /System/Library/Filesystems/hfs.fs/Contents/Resources/./fsck_hfs -y /dev/disk2s2
    xavierhoenner 2584 0.0 0.0 2432772 640 s002 S+ 11:25am 0:00.00 grep /dev/disk2

    Then I killed this process by ‘sudo kill [process number]’, in my case ‘sudo kill 2505′

    Once that was done, I tried re-running cat /dev/random > /dev/disk2 and it worked beautifully!!

    Reply
    1. Topher Kessler Post author

      Yes it will. This fix is intended for the drive, and not for the data on it. With this fix you can make use of a drive that otherwise cannot be partitioned and formatted.

      Reply
  17. Ninad Desai

    Hi ,
    I am getting error “stdout: Input/output error”; I tried it several times …
    its this error or else “Operation not supported”.

    Reply
  18. Cristian  (@ccontreras)

    Hi ,
    I am getting error “stdout: Input/output error” – I tried Disk Utility but always error message “Unable to write to the last block of the device” please help.

    Reply
  19. Alex

    Hi,

    I am booting my Mac using an external disk. My internal SSD appears as “Virtual Whole Disk” in Disk Utility.
    I get “cat /dev/random > /dev/disk0″ to run successfully and the disk appears fine in Disk Utility, but the partitioning using Disk Utility stucks at 50% and if I reboot the computer the disk appears again as “Virtual Whole Disk”. Any advice? Thanks!

    Reply
    1. Topher Kessler Post author

      You might try leaving the command running for longer, especially if the drive is a relatively large one. You want to ensure all logic is destroyed on the drive, so it can be re-written from scratch, instead of being interpreted by your system.

      Reply
      1. Alex

        Thanks for advice. The disk is 256 Gb SSD. How long should I leave the command running? I left it all night and got the same result.

        Reply
  20. Georgina

    Hi, appreciate your post/help here.

    I was setting up a usb Yosemite boot drive but it hanged (upgrading from Snow Leopard to Yosemite). Had issues reformatting the USB to restart the process. Disk utility is stuck at “erase” or “partitioning.”

    I would get the same message:
    sh-3.2# cat /dev/random > /dev/disk1
    sh: /dev/disk1: Operation not supported
    sh-3.2# cat /dev/random > /dev/disk1
    sh: /dev/disk1: Operation not supported

    And a pop up window saying “The disk you inserted was not readable by this computer: Initialize… Ignore or Eject”.

    I’ve restarted my macbook and went through the instructions but I would end up with same issue. I’ve thrown the USB onto a Windows PC and reformatted as a FAT32 first and it works. However, when I want to reformat it using Disk Utility, i’m getting the same issue again.

    Any advice?

    Reply
  21. MARLON

    Hi! I am having the same message like Cristian.

    “stdout: Input/output error” – I tried Disk Utility but always error message “Unable to write to the last block of the device” please help.

    Thanks for your answer Topher.

    Reply
  22. Santhosh Paramesh

    Hi Topher,

    I had hard disk errors so i ordered a new one. When I booted using the USB boot drive (Mavericks) and run disk utility to partition it, I am getting “unable to write to the last block of the device” and “Unable to erase or partition” error. I read about your solution above, but wondering if it would work on the internal SATA hard drive. I also tried to create a new partition, but it fails too.

    I tried to cat /dev/random and it keeps scrolling and hangs. Cannot run CTRL-C command.

    Really appreciate your help.

    Reply
    1. B. Jefferson Le Blanc

      @ Santhosh Paramesh: From your post it isn’t clear if the disk problems you’re having are with the old disk or the new one. If it’s the new one, it could be bad out of the box. What model and vintage Mac are you working with? Since you can boot from a thumb drive, your computer will apparently work from an external drive. To test whether the problem is with the new drive or perhaps the connections on your computer’s motherboard, you would need to test the new drive using an external connection.

      If you don’t have an external drive enclosure in which you can test the new drive, Otherworld Computing has a NewerTech Universal USB 3 Drive Adapter (http://eshop.macsales.com/item/NewerTech/U3NVSPATA/) on sale for $28. I use one from time to time for testing drives. For a little more ($34) you can get a NewerTech Voyager S3 USB 3 “toaster” (http://eshop.macsales.com/item/NewerTech/U3S3HD/) that’s easier to use. The Voyager Q provides more connection options (FireWire 800 | USB 3.0/2.0 | eSATA) but it’s more expensive (http://eshop.macsales.com/item/NewerTech/VU3ESFW8/) at $72.99. If your Mac only has USB 2, you might want to consider the Q for faster FireWire performance. If you are going to end up getting a new computer, the USB 3 model will be sufficient.

      I suggest you need to know whether it’s the new drive that’s faulty or the motherboard on your computer before returning the drive for a replacement. If your computer is failing no replacement drive is likely to work. If that’s the case, you can milk more life out of it by installing your system on an external drive and running it from there. You can use any of the drive adaptors for this, though an external drive (in a case) is probably a better way to go if you intend to continue using the computer for any length of time.

      Reply
  23. Parshwa

    Hi Topher,

    Thank you for writing this article. I have been using WD My Book Essential (3TB) as time machine. Recently I upgraded to Yosemite. After few successful back-ups, I decided to encrypt back up. Encryption was going on fine, when suddenly on 3rd day, my MCB (mid 2010) started ejecting My Book after few minutes. After this I tried many things and I think I ended up making it worse. Now, when I try to partition my external drive, it sometimes throw:
    POSIX reports: The operation couldn’t be completed. Resource busy (This error came during partition after following the steps )
    or
    Unable to write to the last block of the device.

    I will really appreciate, if you can help me out.

    Best regards

    Reply
  24. Birdeen

    Thank you! Thank you! Thank you! This has helped keep my mental sanity on numerous occasions with corrupted drives.

    Reply
  25. ABC

    Dear TK,

    Thank you. It worked perfectly. I could erase the volume and later reformat the HDD.

    But just one question, how do you come up with such ideas?

    If I would not have read your name on this article, I would have stopped hitting
    cat /dev/random > /dev/diskx after the second time.

    Once, more thanks a lot for Macissues.

    Reply
  26. Micah James

    Hi and good day, im having a similar issue with my pendrive. Its not popping up on my macbook pro desktop, im getting the “initialize, ignore etc” error, but its showing in diskutility. i ran some of the terminals above and got to this point

    Last login: Wed Apr 15 05:33:16 on ttys000
    Micahs-MacBook-Pro:~ MJLive$ sudo su
    Password:
    Sorry, try again.
    Password:
    sh-3.2# cat /dev/random > /dev/disk2
    ^[[A

    where do i go from here ???

    thanks in advance

    Reply
  27. patriksundback

    Brilliant solution!
    Running the script, rebooting and then formatting the external hard drive worked for me.

    Reply
  28. duongel

    Just wanted to say thank you dude! I was really starting to get frustrated, but your instructions worked :-)

    Reply
  29. Brad

    I successfully erased all partitions but when I got to reformat in Disk Utility i get “Partition failed with the error: Couldn’t open device.” info comes up unformatted but the disk is not mounted. I’ll maybe try to mount it in terminal?
    I sure would appreciate any help someone may have. Thank you

    Reply
    1. B. Jefferson Le Blanc

      Hi Brad. Have you restarted your Mac with the drive connected? Often when the system sees a drive it cannot recognize it will offer to format it. Does Disk Utility recognize the disk? If so, will it mount when you click the Mount button in the toolbar?

      Reply
      1. Brad

        Thanks. I’ll try the restart. Disk utility does recognize but will not allow mount. I tried to mount it in terminal. It said it mounded but did not show that in diskutil.

        Reply
    1. Brad

      After doing some research on line I found that the USB flash drive I had purchased was a counterfeit drive. When plugged in it read in disk utility 1TB but would not support the data. It would load the initial folders and the first few would be good, but the rest would be empty.
      Why does disk utility show an incorrect amount of storage and is there a way to ascertain the correct storage other then just dropping data on it?

      Reply

Leave a Reply to ali Cancel reply