Author Topic: SD card won't write...  (Read 2016 times)

0 Members and 1 Guest are viewing this topic.

Offline westfwTopic starter

  • Super Contributor
  • ***
  • Posts: 4303
  • Country: us
SD card won't write...
« on: September 27, 2020, 09:48:33 am »
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?

 

Offline Twoflower

  • Frequent Contributor
  • **
  • Posts: 742
  • Country: de
Re: SD card won't write...
« Reply #1 on: September 27, 2020, 10:01:04 am »
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).
« Last Edit: September 27, 2020, 10:07:28 am by Twoflower »
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6840
  • Country: fi
    • My home page and email address
Re: SD card won't write...
« Reply #2 on: September 27, 2020, 10:54:52 am »
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.
 

Offline bw2341

  • Regular Contributor
  • *
  • Posts: 163
  • Country: ca
Re: SD card won't write...
« Reply #3 on: September 28, 2020, 02:38:51 am »
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.
« Last Edit: September 28, 2020, 02:41:11 am by bw2341 »
 

Offline wraper

  • Supporter
  • ****
  • Posts: 17581
  • Country: lv
Re: SD card won't write...
« Reply #4 on: September 28, 2020, 03:16:10 am »
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_cards although it's outdated.
Quote
I tried the download from the SD card association, and that didn't help any
That tool simply does usual formatting. To do low level stuff, you need controller vendor specific tool.
« Last Edit: September 28, 2020, 03:53:44 am by wraper »
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2141
  • Country: us
Re: SD card won't write...
« Reply #5 on: September 28, 2020, 03:22:02 am »
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.
« Last Edit: September 28, 2020, 03:42:27 am by Peabody »
 

Offline wraper

  • Supporter
  • ****
  • Posts: 17581
  • Country: lv
Re: SD card won't write...
« Reply #6 on: September 28, 2020, 03:50:56 am »
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.
There 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.
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: SD card won't write...
« Reply #7 on: September 28, 2020, 11:26:49 am »
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).

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2141
  • Country: us
Re: SD card won't write...
« Reply #8 on: September 28, 2020, 01:42:48 pm »
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.
There 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.

I 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.


 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 17113
  • Country: us
  • DavidH
Re: SD card won't write...
« Reply #9 on: September 28, 2020, 10:43:21 pm »
The write endurance might be exhausted.
 

Offline westfwTopic starter

  • Super Contributor
  • ***
  • Posts: 4303
  • Country: us
Re: SD card won't write...
« Reply #10 on: September 29, 2020, 08:28:35 am »
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 :-)
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6840
  • Country: fi
    • My home page and email address
Re: SD card won't write...
« Reply #11 on: September 29, 2020, 09:05:30 am »
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).
 

Offline ucanel

  • Regular Contributor
  • *
  • Posts: 134
  • Country: tr
Re: SD card won't write...
« Reply #12 on: September 29, 2020, 09:28:51 am »
Not the same thing but maybe helps:

I had similar situation with sd card on my phone,
after something i do not know
i start to could not erase anything on sd card
on either using pc or phone itself
but phone itself can write to the card.
I tried format tools, winhex hxd etc. nope.
I had low level understanding about sd cards
i wrote an sd card library for mcu but
i could not solve that problem.

Then one day
i connected the sd card to an another android phone
and at some menu there was something like
 'lock the sd card'
i selected that and sd card turn to a normal state.

 
The following users thanked this post: GlennSprigg


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf