Can't format internal (USB) drive because of Read-Only [duplicate]

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

  • Couldn't open device
  • Disk Utility won't erase my USB flash drive ("Couldn't open device")
  • How can I fix Error: -69877: Couldn't open device after interrupted formatting process?
  • Unable to format USB disk (Error: -69877: Couldn't open device)
  • Disk Utility Cannot erase USB Drive (Error: -69877: Couldn't open device)