Linux – Cannot remove Micro SD card’s read-only attribute after Ubuntu image

linuxpartitioningsd cardUbuntuwindows 10

I can't remove the read-only attribute from a Kingston 32 GB Micro SD Card. I want to wipe clean the whole card.

I was given a Raspberry Pi 3 and a 32 GB Micro SD Card and an Echo to play around with. The Micro SD Card was factory fresh when I got it. I downloaded a fresh Ubuntu 16.04 image and formatted the card using Etcher on Windows 10. After I was done, I plugged in everything for the Raspberry to work and noticed that nothing happened. I started to panic a little and thought to myself: "Good job Scrat, you utter moron. Why couldn't you simply wait a little and google a freaking tutorial."

I googled what could possibly have gone wrong and what I should've done, and had to discover that you can't just put any random Ubuntu image on it. It has to be one of the images the creator provides (in my case Ubuntu Mate or Raspbian).

Attempted fixes with Windows

When trying to reformat by right-clicking and reformating via the Windows Explorer, the first thing I encountered that the card was in read-only mode. Trying to access it in the Windows Explorer only showed me the EFI directory, of which I wasn't surprised by.

First thing I found on the internet is about a switch/lock on the card, but my card does not have any lock at all. Neither the card itself, nor the Robson Mini Card Reader I use for reading.

Afterwards I tried to remember how to edit disks.
Mind that I'm still using Windows 10 at that moment, because I would've had to copy my old VM-Ware and system image from my external drive, and I didn't know where that was.

I opened a command line, run diskpart, and list all my disks via

list disk

Which output my 931 GB HDD, my 119 GB SSD (Where Windows is installed on) and the 29 GB Micro SD Card:

Datenträger ###  Status         Größe    Frei     Dyn  GPT  
---------------  -------------  -------  -------  ---  ---   
Datenträger 0    Online          119 GB      0 B        *  
Datenträger 1    Online          931 GB      0 B        *  
Datenträger 2    Online           29 GB    29 GB

Following the information I've got, I knew that Datenträger 2 aka Disk 2 is the card I wanted to edit by doing:

select disk 2

So far so good. Then I wanted to remove the read-only attribute by doing:

attributes disk clear readonly

Which was also successfully executed.

But when I tried to do:

clean

I got a "Hardware Error Message" (In German, thats why I'm not copying it here, but it essentially only said Hardware Error). That error also followed when trying to create primary partition or do other things.

At this point the panic in me started to grow more and more. But I tried to keep calm because I still had a few tricks up my sleeves.

I tried using the programs: EaseUS Partition Master, Etcher (again) and SD Card Formatter which all failed due to the card being protected (read-only, write-protected).

I also tried using the registry edit to change the behaviour of Windows towards storage devices by creating the key (which was not there yet):

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies

and creating a new keyword (DWORD WriteProtect) and setting it to 0, which means no read-only.

Attempted fixes with Linux

That didn't work either and I began losing my nerves with Windows, so I got off my butt and searched for my external drive and installed VM-Ware and ran the Ubuntu 16.04 virtual machine I use for school.

Starting the VM I already noticed that Ubuntu was able to help me way more than Windows (or at least I thought so, because my Linux skills are limited in this aspect). The first thing I see is a linked icon on the Desktop to the card called "Ubuntu 16.04.2 LTS amd64" in it are contained the various stuff Ubuntu needs to work seen in the image here.

But that wouldn't help me. So I went ahead and started a terminal and wrote:

lsblk

Which confirmed that the card is visible (sdb):

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   30G  0 disk 
└─sda1   8:1    0   30G  0 part /
sdb      8:16   1 29,2G  1 disk 
├─sdb1   8:17   1  1,5G  1 part /media/pose/Ubuntu 16.04.2 LTS amd64
└─sdb2   8:18   1  2,4M  1 part 
sr0     11:0    1 1024M  0 rom  

But lsblk wasn't very precise so I also used the command we learned in school:

fdisk -l

Which was a bit more precise:

Disk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa14a8cb2

Device     Boot Start      End  Sectors Size Id Type
/dev/sda1        2048 62914559 62912512  30G 83 Linux


Disk /dev/sdb: 29,2 GiB, 31306285056 bytes, 61145088 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x15e2543d

Device     Boot Start     End Sectors  Size Id Type
/dev/sdb1  *        0 3035519 3035520  1,5G  0 Empty
/dev/sdb2       14432   19295    4864  2,4M ef EFI (FAT-12/16/32)

And I was euphoric because I thought I finally cracked the goddamn Davinci code or something, so I ran

gparted

Which Immediately opened with an error message:

The driver descriptor says the physical block size is 2048 bytes, but Linux says it is 512 bytes.

Which I ignored because I thought it was no biggie, but right after ignoring the previous one the next error message popped up:

Partition(s) 1 on /dev/sdb have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.

So I did what the message told me and rebooted. But that was of no use either, because the same two errors popped up again. I ignored them both this time and the good old trusty gparted window I knew from school opened.

Once I changed to /dev/sdb it became confusing really fast. As you can see here, things are pretty weird, because now sdb is somehow considered my SSD instead of the card, but the image from the card is still mounted. At this point I was too angsty to continue doing anything further in fear of accidentally screwing up my laptop as well.

By the way, I have also tried giving myself permissions to access the disk and try to use the dd command, but with the same error message (Access denied, read-only or something, I'm not exactly sure, but something in this direction).

I have already ordered another 32 GB Micro SD card from Amazon, in case there is no more hope for the old one. But I'm not giving up yet.

(Sorry that some things are in German but I think those things are for the most part self-explanatory.)

Best Answer

Well, your post was certainly entertaining enough. Thanks for that.

I know it's not the answer you are looking for. But, it does look like the SD card is stuck in read-only mode. You've done everything you can. It really isn't that difficult.

It acts like it would if there was a write-protect switch on the card. It sounds like you confirmed it did not, but maybe just double check, one more time? The thought that came to mind was maybe you are using a mini-SD card in a mini-sd to sd adapter. And maybe you looked on the adapter, but not the mini-sd card itself? I don't know, just throwing that out there. If there is an adapter, maybe the adapter itself went bad? I don't remember if you mentioned if you tried a different card reader. Maybe the reader went bad?

Other than that, it's a pretty common failure for something like this to "fail" in a read-only mode. So, my gut tells me the card went bad.

Looks like you are on the right track, just replacing it. Maybe you can get the bad one replaced under warranty being it is new. Let us know what you figure out.

Related Question