Jayson Wonder
Posts: 46
Joined: Sat Jan 02, 2021 8:02 pm

SD Card Corrupt Again

Sat May 08, 2021 11:02 pm

Hello all,

A couple months ago I bought an RPI4 4gb model. I was really excited. Everything was great until a power outage due to weather in my area. It basically wiped out my first SD Card. I tried a few commands to recover the SD Card (did not really care data) was happy to reinstall a new image.

So the other night I had another power outage and the SD Card is again corrupt. I have tried deleted partitions, reformatting, fsck and all failed.

I have had older Pis and the have recovered from crashes and outages. Why is this Pi4 killing SD cards like this? More importantly, how can I salvage this card. If I have to buy another SD card I would have matched the price of my new pi. What gives?

Any help is appreciated!
Thanks,

LTolledo
Posts: 5321
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: SD Card Corrupt Again

Sat May 08, 2021 11:20 pm

the problem is the power outages....
no matter how many times you buy new microSD cards and flash it... if the sudden power cuts are not mitigated....the problem will just repeat itself

you need to find solution to prevent sudden power cuts to the board so you can do a clean shutdown...

get a UPS...or

get the lousy power company to compensate you for your loss...every time the power is suddenly cut.
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

RonR
Posts: 2150
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: SD Card Corrupt Again

Sat May 08, 2021 11:22 pm

I seriously doubt your Raspberry Pi 4 is 'killing' SD cards such that they can't be reused.

Run imageUSB and zero the SD card (Boot Sector(s) Only) and see if it's usable again.

The best solution to not having SD cards corrupted by unexpected shutdowns (i. e. power failures) is to use a UPS. The next best solution is to do regular backups using image-backup or something similar so that you can quickly recover.

Jayson Wonder
Posts: 46
Joined: Sat Jan 02, 2021 8:02 pm

Re: SD Card Corrupt Again

Sun May 09, 2021 12:44 am

Yes I agree a UPS is the next investment!

The ImageUSB app does not see the drive. Neither does the raspberry pi imager...

RonR
Posts: 2150
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: SD Card Corrupt Again

Sun May 09, 2021 12:54 am

Jayson Wonder wrote:
Sun May 09, 2021 12:44 am
The ImageUSB app does not see the drive. Neither does the raspberry pi imager...

It's still doubtful the Raspberry Pi is destroying SD cards. If it is, it's time to get the Raspberry Pi replaced under warranty.

If the SD card has totally failed, it's probably also under warranty. Some of the name-brand manufacturers (like Samsung, for example) send you a prepaid label for warranty replacements.

User avatar
Gavinmc42
Posts: 5631
Joined: Wed Aug 28, 2013 3:31 am

Re: SD Card Corrupt Again

Sun May 09, 2021 1:20 am

I don't use anything more expensive as 16GB, have a few 32 and 64 and a single 128GB.
I prefer USB sticks and SSDs in the bigger sizes, they tend to be more reliable.
A1 uSD cards are much better too.

Power outages almost never affect my PiCore Linux OS based 24/7 Pi's.
It runs from ram and usually only reads the uSDs.
Some have runs 24/7 for years, without needing a UPS..

If you run Raspberry Pi OS or similar big OS uSD corruption will happen sooner or later.
For really bulletproofed single purpose Pi apps I use baremetal OS made with Ultibo.
Those can get down to just the bootfiles and a single 3+MB kernel.img.
Less files = less chance of corruption.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

RonR
Posts: 2150
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: SD Card Corrupt Again

Sun May 09, 2021 1:33 am

The main reason Raspberry Pi 4B's end up with much more SD card corruption following a power failure is the additional RAM they provide. The additional cache really speeds things up, but it takes a long time to write out 4 or 8 GB to a slow SD card. It's a major filesystem disaster when so much data is lost on a power failure.

User avatar
rpdom
Posts: 18696
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: SD Card Corrupt Again

Sun May 09, 2021 6:26 am

RonR wrote:
Sun May 09, 2021 1:33 am
The main reason Raspberry Pi 4B's end up with much more SD card corruption following a power failure is the additional RAM they provide. The additional cache really speeds things up, but it takes a long time to write out 4 or 8 GB to a slow SD card. It's a major filesystem disaster when so much data is lost on a power failure.
Very unlikely. You'd have to be writing a huge amount of data very quickly for it to fill that much cache and not to be written out to the card. Also that is likely to result in some filesystem corruption and data loss - not a dead SD card.
Unreadable squiggle

RonR
Posts: 2150
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: SD Card Corrupt Again

Sun May 09, 2021 7:27 am

rpdom wrote:
Sun May 09, 2021 6:26 am
Very unlikely. You'd have to be writing a huge amount of data very quickly for it to fill that much cache and not to be written out to the card.

The whole reason for having a cache is that RAM is immensely faster than media. Time a sync command immediately after doing major update on an SD card and you'll see that it takes a huge amount of time to flush the cache on an RPi 4B/4G.
rpdom wrote:
Sun May 09, 2021 6:26 am
Also that is likely to result in some filesystem corruption and data loss - not a dead SD card.

If you read the posts above, you'll see that I don't believe the Raspberry Pi has anything to do with a dead SD card.

User avatar
rpdom
Posts: 18696
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: SD Card Corrupt Again

Sun May 09, 2021 10:41 am

RonR wrote:
Sun May 09, 2021 7:27 am
The whole reason for having a cache is that RAM is immensely faster than media.
I know what the cache is for.

It is still unlikely that you will be caching GBs of writes. Data will be cached for reading, of course.
Unreadable squiggle

Jayson Wonder
Posts: 46
Joined: Sat Jan 02, 2021 8:02 pm

Re: SD Card Corrupt Again

Sun May 09, 2021 11:27 am

RonR wrote:
Sun May 09, 2021 12:54 am
Jayson Wonder wrote:
Sun May 09, 2021 12:44 am
The ImageUSB app does not see the drive. Neither does the raspberry pi imager...

It's still doubtful the Raspberry Pi is destroying SD cards. If it is, it's time to get the Raspberry Pi replaced under warranty.

If the SD card has totally failed, it's probably also under warranty. Some of the name-brand manufacturers (like Samsung, for example) send you a prepaid label for warranty replacements.
I tend to agree that is should not be trashing the card beyond repair. So after trying the obvious, are there any solutions for repairing the SDcard? I am able to see it in another Linux system but cant seem to do anything with it.

I am open to any solutions that will allow me to repair.

Thank for all the good info.

drtechno
Posts: 230
Joined: Fri Apr 09, 2021 6:33 pm

Re: SD Card Corrupt Again

Sun May 09, 2021 4:07 pm

Jayson Wonder wrote:
Sun May 09, 2021 11:27 am

I tend to agree that is should not be trashing the card beyond repair. So after trying the obvious, are there any solutions for repairing the SDcard? I am able to see it in another Linux system but cant seem to do anything with it.

I am open to any solutions that will allow me to repair.

Thank for all the good info.
Well, when an sd card or usb drive messes up, I use Gparted.

RonR
Posts: 2150
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: SD Card Corrupt Again

Sun May 09, 2021 8:55 pm

Jayson Wonder wrote:
Sun May 09, 2021 11:27 am
I am able to see it in another Linux system but cant seem to do anything with it.

I am open to any solutions that will allow me to repair.

What happens if your run?:

Code: Select all

dd if=/dev/zero of=/dev/sdX count=1000
sync

!!! Make sure /dev/sdX is the SD card !!!

Does it now behave like an unpartitioned/unformatted SD card? Can you write a Raspberry Pi OS image to it and boot it?

User avatar
butchkemper
Posts: 83
Joined: Sat Jul 22, 2017 8:03 pm
Location: Sachse, Texas USA

Re: SD Card Corrupt Again

Sun May 09, 2021 8:57 pm

Jayson Wonder wrote:
Sun May 09, 2021 11:27 am
RonR wrote:
Sun May 09, 2021 12:54 am
Jayson Wonder wrote:
Sun May 09, 2021 12:44 am
The ImageUSB app does not see the drive. Neither does the raspberry pi imager...

It's still doubtful the Raspberry Pi is destroying SD cards. If it is, it's time to get the Raspberry Pi replaced under warranty.

If the SD card has totally failed, it's probably also under warranty. Some of the name-brand manufacturers (like Samsung, for example) send you a prepaid label for warranty replacements.
I tend to agree that is should not be trashing the card beyond repair. So after trying the obvious, are there any solutions for repairing the SDcard? I am able to see it in another Linux system but cant seem to do anything with it.

I am open to any solutions that will allow me to repair.

Thank for all the good info.
Some time back, I experienced a problem where I could not write a SDcard - what I did to cause the problem and the resulting symptoms, I do not remember. However, I used the program "SD Card Formatter 5.0.1" to repair the SDcard and make it usable again. A google search on the program name will reveal the location for downloading the program.

Butch

User avatar
Imperf3kt
Posts: 4460
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia
Contact: Twitter

Re: SD Card Corrupt Again

Sun May 09, 2021 9:20 pm

It's possible the SD card itself was destroyed by the power outage, why is everybody pointing fingers at only file corruption?
55:55:44:44:4C
52:4C:52:42:41

Rose tinted glasses are difficult to see through.

RonR
Posts: 2150
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: SD Card Corrupt Again

Sun May 09, 2021 10:14 pm

rpdom wrote:
Sun May 09, 2021 10:41 am
It is still unlikely that you will be caching GBs of writes. Data will be cached for reading, of course.

Run the following test:

Code: Select all

#!/bin/bash

rm /tmp/test.dat &> /dev/null
sync
echo 3 > /proc/sys/vm/drop_caches
dd bs=4M if=/dev/zero of=/tmp/test.dat count=1024
time sync
rm /tmp/test.dat &> /dev/null

On a Raspberry Pi 3B+ (1 GB RAM):

Code: Select all

root@raspberrypi:~# ./test
1024+0 records in
1024+0 records out
4294967296 bytes (4.3 GB, 4.0 GiB) copied, 583.742 s, 7.4 MB/s

real    0m4.865s
user    0m0.000s
sys     0m0.017s

On a Raspberry Pi 4B (4 GB RAM):

Code: Select all

root@raspberrypi:~# ./test
1024+0 records in
1024+0 records out
4294967296 bytes (4.3 GB, 4.0 GiB) copied, 508.99 s, 7.8 MB/s

real    0m53.321s
user    0m0.009s
sys     0m0.064s

The Raspberry Pi 4B writes the 4 GB test file 75 seconds faster than the Raspberry Pi 3B+ but takes 10 times longer to write out the cache.

RonR
Posts: 2150
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: SD Card Corrupt Again

Sun May 09, 2021 10:30 pm

Imperf3kt wrote:
Sun May 09, 2021 9:20 pm
It's possible the SD card itself was destroyed by the power outage, why is everybody pointing fingers at only file corruption?

There's really two discussions going on here.

1. I agree with you that if the SD card is destroyed, it's probably unrelated to a Raspberry Pi and would have occurred when powered down and back up in any device.

2. The OP (and other topics) have speculated that Raspberry Pi 4B's are more susceptible to SD card corruption. I also think they are and feel it's due to significantly increased caching as a result of having much more onboard RAM available. USB 3 flash drives and SSD's are so much faster than SD cards that the cache is flushed much more quickly, reducing the window of vulnerability considerably

Jayson Wonder
Posts: 46
Joined: Sat Jan 02, 2021 8:02 pm

Re: SD Card Corrupt Again

Mon May 10, 2021 12:06 am

RonR wrote:
Sun May 09, 2021 8:55 pm
Jayson Wonder wrote:
Sun May 09, 2021 11:27 am
I am able to see it in another Linux system but cant seem to do anything with it.

I am open to any solutions that will allow me to repair.

What happens if your run?:

Code: Select all

dd if=/dev/zero of=/dev/sdX count=1000
sync
This is what I get:

Code: Select all

1000+0 records in
1000+0 records out
512000 bytes (512 kB, 500 KiB) copied, 0.00660096 s, 77.6 MB/s
Does it now behave like an unpartitioned/unformatted SD card? Can you write a Raspberry Pi OS image to it and boot it?
Still unable to write an image at least with Raspberry Pi Imager 1.6.1

I will try another program just case.

Thanks,

RonR
Posts: 2150
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: SD Card Corrupt Again

Mon May 10, 2021 12:10 am

Jayson Wonder wrote:
Mon May 10, 2021 12:06 am
Still unable to write an image at least with Raspberry Pi Imager 1.6.1

I will try another program just case.

I'm not a fan of Raspberry Pi Imager. I've never had a problem using Etcher.

Jayson Wonder
Posts: 46
Joined: Sat Jan 02, 2021 8:02 pm

Re: SD Card Corrupt Again

Mon May 10, 2021 12:19 am

RonR wrote:
Mon May 10, 2021 12:10 am
Jayson Wonder wrote:
Mon May 10, 2021 12:06 am
Still unable to write an image at least with Raspberry Pi Imager 1.6.1

I will try another program just case.

I'm not a fan of Raspberry Pi Imager. I've never had a problem using Etcher.
I have not had any luck so far with:
Raspberry Pi Imager 1.6.1
ImageUSB
Etcher

But I can at least see the card again so it indeed may be destroyed. Is there a method to fully erase the sdcard and corrupt files or make a new image strictly from a CLI on a headless machine? That is all I have at my disposal and a Win10 box..

Thanks,

RonR
Posts: 2150
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: SD Card Corrupt Again

Mon May 10, 2021 12:28 am

Jayson Wonder wrote:
Mon May 10, 2021 12:19 am
Is there a method to fully erase the sdcard and corrupt files or make a new image strictly from a CLI on a headless machine?

write-image

Jayson Wonder
Posts: 46
Joined: Sat Jan 02, 2021 8:02 pm

Re: SD Card Corrupt Again

Mon May 10, 2021 12:48 am

RonR wrote:
Mon May 10, 2021 12:28 am
Jayson Wonder wrote:
Mon May 10, 2021 12:19 am
Is there a method to fully erase the sdcard and corrupt files or make a new image strictly from a CLI on a headless machine?

write-image
Thanks for that, still no cigar. I get this reply:

Code: Select all

Invalid device: /dev/sdb

Usage: ./write-image file device

RonR
Posts: 2150
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

Re: SD Card Corrupt Again

Mon May 10, 2021 12:54 am

Jayson Wonder wrote:
Mon May 10, 2021 12:48 am
RonR wrote:
Mon May 10, 2021 12:28 am
Jayson Wonder wrote:
Mon May 10, 2021 12:19 am
Is there a method to fully erase the sdcard and corrupt files or make a new image strictly from a CLI on a headless machine?

write-image
Thanks for that, still no cigar. I get this reply:

Code: Select all

Invalid device: /dev/sdb

Usage: ./write-image file device

Does lsblk show a /dev/sdb? If write-image (which simply uses dd) can't write it, it's probably not salvageable.

It''s beginning to look like that SD card has simply failed (albeit in a rather strange way). If other SD cards work, I would attempt to get the faulty one replaced under warranty if possible or toss it in the trash and get on to better things.

Jayson Wonder
Posts: 46
Joined: Sat Jan 02, 2021 8:02 pm

Re: SD Card Corrupt Again

Mon May 10, 2021 1:10 am

RonR wrote:
Mon May 10, 2021 12:54 am
Jayson Wonder wrote:
Mon May 10, 2021 12:48 am
RonR wrote:
Mon May 10, 2021 12:28 am


write-image
Thanks for that, still no cigar. I get this reply:

Code: Select all

Invalid device: /dev/sdb

Usage: ./write-image file device

Does lsblk show a /dev/sdb? If write-image (which simply uses dd) can't write it, it's probably not salvageable.

It''s beginning to look like that SD card has simply failed (albeit in a rather strange way). If other SD cards work, I would attempt to get the faulty one replaced under warranty if possible or toss it in the trash and get on to better things.
Yes, I think I will agree with you. I really appreciate all the help from you and the forum!
Cheers

Return to “Troubleshooting”