SD card won't write... - Page 1
Forum section: electronics / general

author: westfw
author_rank: Super Contributor
timestamp: September 27, 2020, 09:48:33 am
content: So I have a micro-SD card that was supposed to go into a Raspberry Pi. It's was re-imaged about twice from a mac with SD card reader, and ... now it doesn't seem to write.(the RPi booted fine with the filesystem; but the first time configuration kept disappearing after re-boots.)This might be due to having the write-lock switch partially closed during some editing?Anyway, nothing actually complains that the card is read-only or anything, but attempted changes to files just disappear. This includes re-formatting the card; everything proceeds as if it's working fine, until the card is re-mounted with what should be a blank filesystem, except all the old partitions are still there!Is there some sort of low-level formatting tool that might fix this? I tried the download from the SD card association, and that didn't help any :-( Is this a known failure mode for uSD cards?

author: Twoflower
author_rank: Frequent Contributor
timestamp: September 27, 2020, 10:01:04 am
content: Normal formatting does not touch the partitions. On a mac you should use the disk-utility to remove the partitions (or the fdisk command line tool).Edit: Disappearing content might be caused by not ejecting the media from the OS before remove the card correctly. If for example writing lots of data to the mount point of the SD card takes only a second or so it is not actually written to the media. The unmount/eject process will take very long time. Depending on the SD card and amount of data more than a minute. So you must be patient until the OS tell you it's OK to remove the media (or shell prompt returns after the umount command).

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 27, 2020, 10:54:52 am
content: It sounds like the OS on the SD card is of "live" type. These deliberately mount the underlying filesystems read-only, then a RAM-backed overlays on top. This way, any changes will only be visible until the next boot. This is by design.I recommend you check what kind of OS image you have on the SD card.

author: bw2341
author_rank: Regular Contributor
timestamp: September 28, 2020, 02:38:51 am
content: I don't have a Mac to confirm, but people have brought me removable disks and the files they wanted to bring me were not on the disk.Invariably, they were using Macs. It looks like Macs use write caching on removable disks. Maybe you forgot to hit eject before removing the card?Windows seem to avoid this problem with write-through caching on removable FAT devices. This makes copying to flash media seem very slow, but the files are fully written to the flash when the copy operation completes.

author: wraper
author_rank: Unknown
timestamp: September 28, 2020, 03:16:10 am
content: Not all SD cards work work Raspberry pi or work well. With many even if it does boot, very soon data will be corrupted, especially at power loss. While with others it will work fine after a hundred of power losses. This compatibility list exists for a good reason:https://elinux.org/RPi_SD_cardsalthough it's outdated.QuoteThat tool simply does usual formatting. To do low level stuff, you need controller vendor specific tool.

author: Peabody
author_rank: Super Contributor
timestamp: September 28, 2020, 03:22:02 am
content: The Arduino SdFat library has an example sketch called SDFormatter.ino. It actually erases the entire card. Of course you would need a microSD module to use that. Another alternative might be if you have a camera that gives you the option of doing a low-level format. I think that is also a full erase format. I think either option may let you get around the limitations of an operating system and card reader.Edit: SdFat only works with SD and SDHC cards. But SdFat-beta (Github) also works with SDXC.

author: wraper
author_rank: Unknown
timestamp: September 28, 2020, 03:50:56 am
content: Quote from: Peabody on September 28, 2020, 03:22:02 amThere is no magical low level format that Arduino or camera could do. I have no knowledge of Mac but on Windows you could use Diskpart clean to delete MBR partition table or Diskpart clean all to do secure erase.

author: andersm
author_rank: Super Contributor
timestamp: September 28, 2020, 11:26:49 am
content: I've seen several SD cards fail with the same symptoms, and never managed to restore any to a working condition. Though frankly I also didn't try that hard, as they were cheap supermarket-checkout type cards (known brands, but still).

author: Peabody
author_rank: Super Contributor
timestamp: September 28, 2020, 01:42:48 pm
content: Quote from: wraper on September 28, 2020, 03:50:56 amI found a description of diskpart's secure erase on winaero.com:> The "clean all" command fills every sector on the disk with> zeroes, so information can't be recovered. It completely> deletes all data stored on the disk, all its partitions,> folders, files etc - everything. The operation usually> takes a lot of time, so be careful and patient.That's the same thing the SD Formatter from the SD Association does on its Overwrite format, and it takes forever. But the Arduino option actually erases the card's flash memory. Diskpart leaves all the sectors flagged as occupied by data (all those zeroes), whereas SdFat leaves them flagged as erased (not needing to be erased before writing data to them). Cameras do the same thing, I presume to maximize write speed for burst mode or video. And the low-level erase goes very quickly.I think the difference is that a computer is dealing with an intermedate SD reader and its controller, and there's no command the computer can give to the SD reader that would cause it to erase the card. My understanding is that even a built-in SD card slot is actually a reader connected to the USB bus. But the Arduino and the camera are directly connected to the SD card, and can send all of the low level commands the card's controller will recognize, including the command to erase blocks of sectors. Erased sectors will read back as either all zeros or all FFs, depending on how the card is designed, and there's even a command to make the card report back which value it uses.Since westfw's problem appears to be that he cannot write to the card, diskpart may work no better than what he's already tried. And I think it's at least possible that a low-level erase (an actual erase, not an overwrite) might work. Of course if the card is just not able to write, then nothing is going to help. But if he has access to a camera with a "low-level" formatting option, it would only take a few seconds to give that a try.

author: David Hess
author_rank: Super Contributor
timestamp: September 28, 2020, 10:43:21 pm
content: The write endurance might be exhausted.

author: westfw
author_rank: Super Contributor
timestamp: September 29, 2020, 08:28:35 am
content: I had tried a couple of these ideas; I used Window's "Disk Management" to try to delete partitions, and I tried a camera that I had that accepted microSD. (and I tried the Raspberry Pi Imager on PC as well as on Mac.)No Luck.I would seem unlikely that I had hit write endurance limits; the card has only been written a couple of times (both by RPi Imaging SW.) I guess it could have been a really dodgy card. :-(At the moment, I seem to have misplaced the card. Perhaps that's for the best :-)

author: Nominal Animal
author_rank: Super Contributor
timestamp: September 29, 2020, 09:05:30 am
content: FWIW, I've had good luck/experience with Sandisk SDHC/microSDHC cards with various SBCs (Odroid C1+, Odroid HC1 (XU4 variant), La Frite, Orange Pi, etc.).I've only broken them thus far physically (bent).

author: ucanel
author_rank: Regular Contributor
timestamp: September 29, 2020, 09:28:51 am
content: Not the same thing but maybe helps:I had similar situation with sd card on my phone,after something i do not knowi start to could not erase anything on sd cardon either using pc or phone itselfbut phone itself can write to the card.I tried format tools, winhex hxd etc. nope.I had low level understanding about sd cardsi wrote an sd card library for mcu buti could not solve that problem.Then one dayi connected the sd card to an another android phoneand at some menu there was something like'lock the sd card'i selected that and sd card turn to a normal state.