SD card read only - how to make it writeable?

I was flashing osmc (Linux OS for KODI, Rasberri Pi3 version) on SD card and noticed a problem. EVERY SD CARD WHICH I FLASHED OSMC becomes locked and writable only. So when I want to flash another OS or do anything with that card, I can’t.

The physical Lock switcher on SD card is off (set to unlock) if case you wonder.

Here is some info I got from the SD (lossly translated into English)"

sudo e2fsck -b 8193 /dev/mmcblk0                                                                                            
e2fsck 1.46.5 (30-Dec-2021)                                                                                                                                                          
e2fsck: File system read only during read attempt on /dev/mmcblk0
Disc is save protected. You use option -n to check.
Device in read-only mode.

So I used this -n option and it gave me:

sudo fsck -n /dev/mmcblk0
fsck from package util-linux 2.38                                                                                                                                                       
e2fsck 1.46.5 (30-Dec-2021)
ext2fs_open2: Incorrect magical count in superblock
fsck.ext2: Incorrect superblock, attmept to use reserve blocks...
fsck.ext2: Incorrect magical count in superblock during oopening attemt of /dev/mmcblk0

superblok can't be read or doesn't describe the correct file system ext2/ext3/ext4. If the device is real and really contain file system ext2/ext3/ext4 (it's not a swap, ufs or anything else),
tthen superblok is corrupt - you can try to open e2fsck with other superblock
e2fsck -b 8193 <device>
or
e2fsck -b 32768 <device>

/dev/mmcblk0 zawiera dane `DOS/MBR boot sector; partition 1 : ID=0xc, start-CHS (0x40,0,1), end-CHS (0x3ff,3,32), startsector 8192, 647168 sectors; partition 2 : ID=0x83, start-CHS
(0x140,0,1), end-CHS (0x3ff,63,32), startsector 655360, 61194240 sectors'

When I tried opening with other superblock, it gave me the same message as the first one above.

I remeber having the same issue in the past and I found some solution back then, but I don’t remeber it and can’t find it in my notices. All I can rember is that the solution needed more steps and didn’t cleary explain what was wrong.

I can’t use dd, because it always complain about the device being read-only. Again, in the past I specially bought a new SD card to bypass the problem and after flashing it with the OSMC system, it also became read-only… Of course OSMC folks have no idea what is causing it.

If you want to flash the same card with something else and you know that the data will be lost, you first have to delete all partitions on the SD card and then flash it with another image, repartition it, and then use it as normal.

For that you need to know the Device Identifier. For example /dev/sdc or /dev/mmcblk0.

You can use fdisk to manage the partitions:

man fdisk

Hope this helps!

I already know it’s /dev/mmcblk0 and yes, I want to wipe out everything and flash another OS on this SD card. The problem is, there is no tool that could do anything with this lock.

This is what I get with fdisk:

fdisk: can't open /dev/mmcblk0: File system read-only

And other similar programs show the same: dd, gparted, various image flash/write apps, fdisk, fsck and so on.

Because this is not a physical lock, there has to be software solution to unlock it and yet, all tools behave as if there was no possibility. So what? After using the SD card once should I just throw it to trash? That is ridiculous.

Have you done it with sudo?

sudo fdisk /dev/mmcblk0

Yes, the same reaction. System read-only.

OK, then I don’t know what it can be and I’ll look further. But I just spotted this page, where the answer is rather mundane:

Finally I found the solution

MicroSD adapter has a “lock” feature. When I inserted the adapter, the lock always triggered to locked state. So I fixed it in unlocked state using the ducktape

So just make sure it’s not something like that.

I already wrote in the first post that the SD is not physically locked. This was the first thing I tried.

I know you wrote it, I was merely pointing out that it was the only thing I can find about it. But I have since found this page where one answer states:

Such read-only issues happen to me all the time when I use iso-images.

What I do to fix such problems:

Note that <yoursdcard> is a device and not a partition, so for example sdc

  1. Boot some kind of linux
  2. Open a terminal
  3. Find out what device your sd card is and verify it by using sudo fdisk /dev/<yoursdcard> -l or to get the device name too you could also use sudo parted /dev/<yoursdcard> -l

WARNING: The following command will destroy all data on /dev/<yoursdcard> so make sure that <yoursdcard> is the right device!!!

  1. Execute sudo dd if=/dev/zero of=/dev/<yoursdcard> bs=1000000 count=50
  2. Execute sudo fdisk /dev/<yoursdcard>
  3. Now use the command o to create a new MSDOS partition table on your sdcard, then use the n command to add a new partition and use w to write the changes to your sdcard and exit fdisk
  4. Now use sudo mkfs -t <filesystem you want> /dev/<yoursdcard>1 to format your partition
  5. Now your sdcard should work again

If that doesn’t work:

  1. Open terminal
  2. Find out what device <yoursdcard> is
  3. Execute sudo su
  4. Execute echo "0" > /sys/block/<yoursdcard>/ro

Hope this helps.

Onfortunatellty, this isn’t the solution. The device is locked and the above dd commands don’t work, as already stated in the first post. This is why I started this case. Low level tools cannot do anything so what can I do?

Identyfying device is not a problem, it works:

michaldybczak  alienware-PC  ~  sudo fdisk /dev/mmcblk0 -l
Dysk /dev/mmcblk0: 29,49 GiB, bajtów: 31666995200, sektorów: 61849600
Jednostki: sektorów, czyli 1 * 512 = 512 bajtów
Rozmiar sektora (logiczny/fizyczny) w bajtach: 512 / 512
Rozmiar we/wy (minimalny/optymalny) w bajtach: 512 / 512
Typ etykiety dysku: dos
Identyfikator dysku: 0x78b2475d

If I use ANY dd command, it only shows “Cannot access. Read-only”. If the dd was the solution, there would be no need for this topic. Fsck, fdisk, also aren’t helping much. If there anything more aggressive, more basic than dd?

michaldybczak  alienware-PC  ~  sudo parted /dev/mmcblk0 -l                                                                                                                      
[sudo] hasło użytkownika michaldybczak:                                                                                                                                              
Model: ATA HGST HTS721010A9 (scsi)                                                                                                                                                   
Dysk /dev/sda: 1000GB                                                                                                                                                                
Rozmiar sektora (logiczny/fizyczny): 512B/4096B                                                                                                                                      
Tablica partycji: gpt                                                                                                                                                                
Flagi dysku:                                                                                                                                                                         
                                                                                                                                                                                    
Numer  Początek  Koniec  Rozmiar  System plików  Nazwa                         Flaga                                                                                                 
1     1049kB    525MB   524MB    fat32          EFI system partition          ładowalna, esp                                                                                        
2     525MB     660MB   134MB                   Microsoft reserved partition  msftres
3     660MB     270GB   269GB    ntfs           Basic data partition          msftdata
4     270GB     989GB   720GB    ext4           home-hdd
5     989GB     990GB   885MB    ntfs                                         ukryta, diag
6     990GB     1000GB  10,2GB   ntfs                                         ukryta, diag

Model: KINGSTON SKC2500M82000G (nvme)
Dysk /dev/nvme0n1: 2000GB
Rozmiar sektora (logiczny/fizyczny): 512B/512B
Tablica partycji: gpt
Flagi dysku:

Numer  Początek  Koniec  Rozmiar  System plików  Nazwa  Flaga
3     1049kB    211MB   210MB    fat32                 ładowalna, esp
4     211MB     108GB   108GB    ext4
2     108GB     2000GB  1892GB   ext4

Ostrzeżenie: Nie można otworzyć /dev/mmcblk0 jednocześnie w trybie do odczytu i
zapisu (System plików wyłącznie do odczytu). /dev/mmcblk0 został otwarty tylko w
trybie do odczytu.
Model: SD SD (sd/mmc)
Dysk /dev/mmcblk0: 31,7GB
Rozmiar sektora (logiczny/fizyczny): 512B/512B
Tablica partycji: msdos
Flagi dysku:

Numer  Początek  Koniec  Rozmiar  Typ      System plików  Flaga
1     4194kB    336MB   331MB    primary  fat32          lba
2     336MB     31,7GB  31,3GB   primary  ext4

Model: Nieznane (unknown)
Dysk /dev/zram0: 1639MB
Rozmiar sektora (logiczny/fizyczny): 4096B/4096B
Tablica partycji: loop
Flagi dysku:

Numer  Początek  Koniec  Rozmiar  System plików   Flaga
1     0,00B     1639MB  1639MB   linux-swap(v1)

Try this:

Followed by trying again from the beginning.

[root@alienware-PC michaldybczak]# "0" > /sys/block/mmcblk0/ro      
bash: /sys/block/mmcblk0/ro: Access denied

You forgot echo

So to confirm, this consistently happens with different SD cards?

Have you tried these SD cards in another physical computer?

May be it’s possible to read a lock status of the card:

sudo hdparm -r /dev/mmcblk0

Only if the card is blocked, (readonly =1) then try

sudo hdparm -r 0 /dev/mmcblk0

2 Likes
echo "0" > /sys/block/mmcblk0/ro                                                                                                                 
bash: /sys/block/mmcblk0/ro: Access denied

Not quite. It happens twice, but for the second time, I was able to unlock it eventually. I don’t remember how. However, the thing is this:

I flashed OSMC system on them and then run it in Rasberry Pi3 to finish the installation. When installing Widevine, I got some error, system restarted and then got total boot failure. Since then, this SD card is locked, and I wasn’t able to fix it.

The second SD card, also, was locked at some point, but there was no such system crash and error.

I would be hard to replicate those events.

No, but the Pi shows a boot failure and in my laptop, both Linux and Windows can’t do anything about that SD card, it’s locked for good. It is possible, the SD became permanently broken. Note, that other SD cards are read fine by my laptop, so it’s not like my laptop has issues with SD cards. If they are new and untampered, they work all fine ;).

sudo hdparm -r /dev/mmcblk0
/dev/mmcblk0:
 readonly      =  1 (on)
sudo hdparm -r 0 /dev/mmcblk0
/dev/mmcblk0:
 setting readonly to 0 (off)
 readonly      =  1 (on)

When I check the first command, it still says 1 (readonly).

Let`s go,: sudo hdparm -r 0 /dev/mmcblk0
But I don’t have high hopes that it will work with an SD card.
Edit: After this action, the computer should be shut down and restarted by you. Then let’s see…

As the root user? (Not simply with sudo, which is not sufficient.)


This is possible. It’s also possible that the “write-lock switch” physically remained in the “lock” position (inside, which you cannot visibly see), even if the slider appears fine (on the outside.) For example, a tiny sliver of metal creating a “short”.

This might be plausible with SD card slots that are a bit “tight” when inserting cards.


Since you haven’t tried these SD cards in a different computer, it still doesn’t rule out certain possibilities.

Yes, as a root user.

You may be on to something. I used a different SD adapter and there is already a difference. Only ext4, the biggest partition is now read only, the rest is accessible. This shows that the partition is broken somehow and even Gparted can do anything about it.

Ah, I think I remember now how I fixed the similar issue in the past. I also got a small partition that was available. I flashed OSMC there, put into Raspberry Pi. When it started, some automatic process of system installation took care of that blocked partition and re-used it. I can try the same now.

So there was no clear solution or a tool to unlock it, but the installation script was able to handle that somehow.