I've done a bit of research and I've heard of the SD card end-of-life behavior (not really sure what else to call it) where SD cards and microSD cards make themselves read-only to avoid data loss. When I first heard of it, I thought it was terribly clever. Now I'm not so sure.

Some background: I had a microSD which lasted 2 years of heavy raspberry pi use before putting itself in write-protect mode. I used dd to move the whole os and filesystem onto my replacement card. Within a few days of usage, I realized that this card had write-protected itself too. I thought I had terrible luck, until my second backup card did the same almost immediately.

This troubled me, so I've since let my raspberry sit off. But I've begun to wonder how the SD card knows to write-protect itself. If it keeps a count of the write-cycles, and I used dd to make an image of the whole disk, then I may have crippled my SD cards by tricking them into thinking they were old. But I can't find the implementation of the end-of-life behavior anywhere. Does anyone know how it works? I'd like to try to undo it but the write-protection seems to be implemented on a very low level. I can't even access the /dev/sdX using sudo.

If I'm right and it keeps some kind of write-cycle tally, this is more than a little frustrating. It means that the SD card hasn't actually died – it's just a precautionary measure. While this is nice, I'd like to use it all the way to actual death, as I'm making regular backups.

With that as my long-winded background, does anyone know how the end-of-life behavior is implemented, and is there any way I can undo an accidental triggering of the behavior?

  • I believe that it is detection of an internal error that prompts reversion to read only mode. These devices were made to be cheap, not reliable. Typically this is non reversible, at least without undocumented drive specific information. – LMiller7 Mar 6 '18 at 5:39
  • 1
    @fixer1234, umm.. no. That kind of information is internal to the drive and not visible to dd. – psusi Mar 6 '18 at 17:13
  • @LMiller7 do the devices check for internal errors each time? The cards themselves are 1 write-cycle from brand new and shouldn't have any error except in the data I wrote to them, which might be data corruption but not internal errors, right? – Sllew Mar 7 '18 at 17:13

The cards are supposed to have some extra space in them to use for wear leveling, but it sounds like maybe the ones you have are dumb and don't have any spare blocks and are going read-only because you have written to every block on the drive. Copying the files instead of using dd, or using e2image -ar to copy an ext[234] filesystem will avoid needlessly writing to every unused block on the disk, which may help.

  • Thanks for the recommendation, but I figured this all out the hard way. My question was whether there's anything that can be done about the cards that are needlessly read-only. – Sllew Mar 7 '18 at 17:16
  • @Sllew, I'm not sure if sdcards support fstrim, but that might help. – psusi Mar 7 '18 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.