Even 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 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):
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:
- 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):
- Run the following command to get a list of drives and their corresponding device files:
- 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).
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:
- Press the Up arrow key in the Terminal to load and prepare the previously entered command.
- Unplug your drive and plug it back in.
- Immediately press Enter, and if you see the same error, then press the Up arrow key again followed by Enter again.
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.