Formatting External Drive

I have been trying to erase a 1TB external drive using Disk Utility but keep getting the following:

“Erasing “HTS54101 0G9AT00 Media” (disk6) and creating “Untitled”
Unmounting disk
The volume on disk6 couldn’t be unmounted because it is in use by process 0 (kernel)
Couldn’t open device. : (-69877)
Operation failed…”

Nothing that I have tried has worked to clear the “process 0.”

Any ideas what I may be doing wrong?

Add the disk to Spotlight Privacy.

In Disk Utility.

Select View > All devices.

Try “Unmount” on Container, Volume group or Volume. (If it is APFS it is some other naming, can not remember right now, but try all levels.) But quit and start Disk Utility between every attempt. Then when unmounted, quit/start and “Erase”.

There’s no such thing as process ID 0. It looks like disk utility is using this as a placeholder to represent kernel-space code, which may be running independently of any user-space processes.

This looks like a fairly common problem. I’m not sure what this particular error code means, but people seem to get it if media is write-protected or if some part of the partition table or a volume is corrupted.

That being said, here are some things to try:

Check for write protection

SD cards have write-protect sliders on them. Some external drives or drive enclosures might also have write-protect switches. Make sure write protection is disabled or you (obviously) won’t be able to erase it.

Check to make sure some process isn’t actually using the device

If some process has open files on the device, or if it just holding the device itself open, that will make it impossible for Disk Utility to unmount it until those processes end or close their handles to the device.

A command like this may help you determine if this is going on:

lsof +c 0 | grep disk6

(replacing disk6 with the device’s actual name). Look in the leftmost column of each output line for the name of a process that has the file open.

It may be that the system is trying to check/repair one of the device’s volumes prior to mounting, and that activity is taking a long time (which might be the case if some corruption was discovered). A telltale of this will be that a process named fsck or something similar (e.g. fsck_apfs or fsck_hfs) will be using the device.

If this, or something similar, is the case, then you should just wait for the background processing to finish. You can repeat the lsof command to see when the process terminates or is no longer using the device. Then give it a try.

Some have suggested booting into Recovery mode and trying to erase it from there. Which might or might not work, depending on what process is holding the device open.

Encrypted volume?

A few links I found in a web search indicate that you may not be able to directly erase a device if there are encrypted volumes on it. But you may be able to use Disk Utility to erase or delete the volumes first, and then erase the device.

Corrupted content?

It is possible that something got truly messed up in the drive’s partition table or one of its volumes such that it can neither be mounted nor unmounted. That’s happened to me on occasion, especially when trying to erase something formerly formatted as NTFS.

In such situations, you can use the dd command to just write zeros over the start of the device (the first few blocks should do it, but I usually overwrite the first MB or so, just to be sure). This will write zeros to the first 10M:

sudo dd if=/dev/zero of=/dev/disk6 bs=1m count=10 status=progress

Or this will write zeros the the entire device (which will probably take a long time):

sudo dd if=/dev/zero of=/dev/disk6 bs=1m status=progress

(The status=progress option isn’t necessary, but without it, the dd command will not show any output until it finishes, making it impossible to tell if it’s working or hung if it’s taking a long time.)

After erasing, disconnect and reconnect the drive. macOS should prompt you to format it when it is reconnected.

But I’d consider this a last resort. And be very very careful with a command like this, because a typo could result in wiping a different device, which will completely ruin your day.

See also:

7 Likes

Thanks. I’ll give that a try. A

Thanks! That gives me a lot of ideas to work on. A

Well I tried those and got similar results. :frowning: Thanks for the ideas though. A

1 Like

Well, that gave me a lot of ideas to try. unfortunately they all ended up with some version of “You Can’t Do That.” Thanks again for the ideas. A

In the worst case, if you have another computer (running Windows or Linux), you can use it to zero-out the device. Then macOS will see a blank device when you connect it.

The dd commands I mentioned above will work on Linux. I’m not sure what tools would be best from Windows, but I’m sure there are some available as well.

Thanks. I’ll give that a try. A

Even if you manage to get the drive working it may have hardware faults that make it unreliable. Given the relatively low cost of hard drives these days, it may not be worth your time persisting with this.

As pointed out by @shaminmo, with terminal commands like sudo dd there is also the risk of erasing the wrong drive when trying to recover an external hard drive.

I don’t agree with a throw-away society but the tech world has certainly gone down that path!

Find the disk identifier (e.g. disk6) in Disk Utility. Open Terminal, and type “diskutil unmountdisk diskn”, where you replace the n with the number, like disk6. What output do you get then?

Thanks Michael. You are correct.
Spending more time on this isn’t worth it, given all the time spent so far and the relatively low cost of a new SSD.
Thanks for injecting some common sense into my thought process.
Regards,
Addison

Yes. I tried that a couple of times. I get "Unmount of disk6 failed: at least one volume could not be unmounted”.
I think at this point I will take Michael’s advice, abandon further attempts and go with a new SSD.
Many thanks,
Addison