MacOS – Disk Utility cannot erase USB drive (error -69877: couldn’t open device)

catalinadisk-utilityflash-memorymacossd card

Disk Utility (macOS Catalina 10.15.2) fails to erase my USB drive (64GB key, currently formatted in exFAT).

/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *64.1 GB    disk2
   1:                        EFI EFI                     209.7 MB   disk2s1
   2:       Microsoft Basic Data Lexar                   63.9 GB    disk2s2

I've tried a bunch of commands that I've found here and there in the terminal, but none of them worked, like:

➜  ~ diskutil eraseVolume exFAT MyName /dev/disk2
Started erase on disk2
Unmounting disk
Error: -69888: Couldn't unmount disk
➜  ~ diskutil eraseVolume exFAT MyName /dev/disk2s2    
Started erase on disk2s2 Lexar
Unmounting disk
Erasing
Error: -69760: Unable to write to the last block of the device
➜  ~ diskutil eraseDisk FAT32 MYSD MBRFormat /dev/disk2
Started erase on disk2
Unmounting disk
Creating the partition map
Error: -69877: Couldn't open device
➜  ~ diskutil eraseDisk free EMPTY /dev/disk2
Started erase on disk2
Unmounting disk
Creating the partition map
Error: -69877: Couldn't open device

My USB drive appears as read only when i do CMD+I, I tried repairing the permissions but that failed too.

➜  ~ diskutil resetUserPermissions /dev/disk2 `id -u`
Ready to reset user permissions on disk2
Error encountered attempting to reset permissions for user 501 home directory on disk2: Permissions are not enabled on the disk (-69861)

Thx in advance for the help 🙂

Best Answer

This is an attempt to write a canonical QA for this issue, as per the Meta post: Where is the list of canonical questions stored for Ask Different? This answer is based off a number of pre-existing answers expect it to be periodically edited with the goal of becoming a comprehensive information resource. *

Can't Access the Device

If you're having an issue where you can't access the device there are a couple things to check first:

  • Check for write protection.

    • On SD cards, there is a physical "write lock" switch that may become enabled. Make sure it's in the "up" position. If it's write protected on every SD , you may have an issue with the logic board itself.

    • On USB flash drives, there may be a physical switch or it may be write protected from via a write protect bit, or the chip may be modified from the factory.

  • Make sure you have the correct privileges. Sometimes the drive may have had user privileges assigned to them. Using an Admin account will usually get around this.

Fixing the Device

There are a few steps you can take, but all are destructive to the data on the device.

  1. Erase Disk. As the name implies, this does a simple erase of the disk and marks the free space as "empty" with no file system or partition scheme.

    $ diskutil eraseDisk free Empty /dev/diskX 
    
  2. Re-partitition the Disk. I like to force a rewrite of the partition map to something that macOS is familiar with like a GPT partition and HFS+ file system. You can use MS-DOS with MBR as well. use diskutil listfilesystem to get a full list of supported file systems.

    $ diskutil partitionDisk diskX 1 GPT HFS+ Untitled 100%   ← GPT with HFS Format
    
    $ disktuil partitionDisk diskX 1 MBR FAT32 UNTITLED 100%  ← MBR with MS-DOS
    
  3. Zero out the disk. Using this command writes zeros to every block of the raw device, meaning you're bypassing everything and accessing the device itself. This is the nuclear option because it will overwrite every single spot on the device with a zero. Triple check the device name!

    $ diskutil unmountDisk diskX            ← Only if necessary (you get a "Resource Busy")
    
    $ sudo dd if=/dev/zero of=/dev/diskX bs=1m
    

If none of the above works, it's likely the device has failed. On SD cards, this is actually quite common. Ask any photographer and they'll tell you that SD cards fail usually in the middle of paid gig which is one of the reasons they now make D-SLRs with dual memory slots


* Existing Questions/Answers