8

A µSD card that was in a security camera suddenly stopped recording:

  • Much of the data is gone (not a problem).
  • The data that is still there is correct and readable.
  • The card now always mounts as read-only, (on Chromebook, Windows, and Ubuntu).

I can't reformat it or do much of anything with it:

$ df
/dev/mmcblk0   vfat          117G   15G      102G  13% /media/ray/xxx

$ sudo fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 116.1 GiB, 124657860608 bytes, 243472384 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: 0x00000000

$ sudo fsck /dev/mmcblk0
fsck from util-linux 2.34
fsck.fat 4.1 (2017-01-24)
open: Read-only file system

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

$ sudo fsck /dev/mmcblk0
fsck from util-linux 2.34
fsck.fat 4.1 (2017-01-24)
open: Read-only file system

$ sudo umount /media/ray/xxx
$ sudo mount  -o rw  /dev/mmcblk0  /media/ray/xxx
mount: /media/ray/xxx: WARNING: device write-protected, mounted read-only.

Note that this is not a full-sized SD card; there is no physical write-protection switch.

Is the card salvageable, or garbage?

2
  • Looks like no partition table, so don't you need to use the "-oloop" on the mount? Did you want to continue using it that way? Save what you want off it, it might still be degrading. Then try dd ifs=/dev/zero of=/dev/mmcblk0 count=10 before putting a filesystem (maybe with a partition table depending upon use) on it.
    – ubfan1
    Commented Jul 24 at 0:21
  • @ubfan1, I don't care about the data, I'm just trying to save the physical device. And like all the other commands: dd: failed to open '/dev/mmcblk0': Read-only file system. Commented Jul 24 at 0:41

5 Answers 5

24

Your SDcard has reached end of life. It will always be read only from now on. This is a protective mechanism when the controller detects the SDcard is not safe to try to write any more data to the card, Due to checksums mismatch. It does this to preserve your existing data. This is permanent.

You need to buy a new SDcard.

From this Source

3
  • 3
    Thanks. Everything else I could find on the topic was suggestions about how to repair it. Given that it was continuously recording 1-minute video files (deleting the oldest ones as needed), end-of-life seems quite reasonable, and I should expect the other cameras to experience the same thing in the near future. Commented Jul 24 at 12:26
  • 3
    @RayButterworth: I wouldn't be surprised if there were ways to manipulate the flash memory in the card to allow writing again for a little while. If certain bits are worn out such that they cannot be set to zero, erasing that block and letting it get written with data where those bits should be ones might momentarily restore the device to operation. The value of doing that, however, may be dubious, since the use of wear leveling in such devices would suggest that if some bits are worn out to the point of failure, many more are probably close to it.
    – supercat
    Commented Jul 25 at 21:21
  • 1
    Now I know why some of my SD cards suddenly stopped working thanks!
    – No-one
    Commented Jul 26 at 14:29
2

Given the cost of a new card, trying to override the EOL lockdown seems like a bad idea. Reusing this card will risk further data loss.

The card went read-only and this allows you to rescue whatever was on the card at the time, which is a great design feature. I had a 16 GB card in a Pi, and I was able to dd the dead card to a new card, which booted up fine after an fsck and the host continued on working.

Additionally, a tool like photorec can scan the disk and potentially read some deleted files too. However video files tend to be large and that decreases the chance of recovery.

Other options might be for you to consider a better way of dealing with this video data. Perhaps stream it off to a NAS or DVR/NVR where it is written to a hard drive? I have network cameras that are read continuously by motion which detects movement via inter-frame differences and saves video where changes are detected.

Depending on the brand of camera, you may have further options about shifting content out of the camera.

Perhaps this camera is solar and has no network, so local storage is your best option. In that case, buy the largest card you can afford so there are more blocks total, and also look at the "industrial" cards which are rated for more resiliency. A "pMLC" card is Pseudo MLC and only uses the top and bottom two cells in a quad cell block, which adds resiliency at the cost of space, and cost.

2
  • While networking the cameras and moving the storage to a central location (or even possibly offsite) is attractive, it's worth noting that it also enables new attack modes, especially if a wireless network is used. Not only is it hard to be sure that the cameras (and the central server) are secure against online intrusion and/or eavesdropping, but with a wireless connection, an intruder with a cheap WiFi jammer might be able to disable all your cameras just by being near them. Of course local storage has its own risks too, but at least compromising it generally requires physical access. Commented Jul 26 at 9:48
  • @IlmariKaronen yep - and sending continuous streams of video over wireless link is going to pollute nearby frequencies too. Best to use wired, whereever possible (which also enables POE)
    – Criggie
    Commented Jul 26 at 11:14
1

I'm not sure that what has been answered here is entirely accurate. There's a lot more functions than can be done on an SD card than what can be done through the file system and block device interface, especially the security operations. The SD Association (the club that you must join to access the specifications and use the SD logo) has a tool called "SD memory card formatter" and that can be used (with most SD card slots) to give commands to the SD card that are not part of the normal block device interface.

I used to work in embedded electronics and I've rescued many locked SD cards with the SD formatter tool. It's available at https://www.sdcard.org/downloads/formatter/

1
  • 5
    That may well be the case. However, in this case it seems that the flash memory in the OP's card has already partially failed and the card has locked itself to prevent further data loss. Even if you somehow manage to convince the controller embedded in the card that everything is all right and that it should be working normally, that still doesn't change the fact that the card is physically at the end of its life and likely to fail again very soon. Commented Jul 25 at 21:35
1

Pretty much possible, using the right tools.

A modern flash storage consists (logically) of a raw storage and a translation/wear levelling layer that exposes addressable R/W blocks to the host while doing a lot of algorithmic magic to the raw storage. The important part is, the raw storage is somewhat bigger than the exposed size (10-20-30% are common).

The important part of the magic is that it controls the health of each block and when some block is not usable anymore, you get less space to do the magic. One needs at least one "erase block" (this is multiple of the read/write block size, e.g. the read/write sector is 512 bytes and the erase block is e.g. 64MB) worth of free space in order to be able to write to the flash at all, and a lot more in order to write to the flash with a consistent write speed.

When you are out of free space in the raw storage layer, you cannot write. On the other hand, you are still able to read from the media.

What is pretty much possible in this case is to declare the usable size to be less than the original. E.g. a 32GB SD card that is out of free healthy blocks (and became read-only) can be reprogrammed to be 20GB or 16GB and have a great deal of extra blocks to work in.

On the other hand, there is no standard interface for doing this.

You need the manufacturer's software tools that are in the general case not freely distributed, but can be found at obscure .cn or .ru websites that are not indexed in the common search engines. In some cases, you also need to alter the card reader as well.

0

Depends on why it's read only.

It may be failing.

Or one of the two designed-in read only bits may have been set. This is a rarely used feature, but with direct access to the card it is possible to set either temporary or irreversible read-only status. There is sample code on GitHub illustrating how to do this. (I've been looking at possibly using it in conjunction with an "immutable" Linux build as a way of getting additional security.)

Note that you can't access these bits through the usual USB card readers/writers

So: if the temporary r/o bit has been set, and if you have suitable hardware, you may be able to reset it. But the odds of that being what happened are pretty darned low.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .