Prevent SD-Card Corruption


139 posts   Page 1 of 6   1, 2, 3, 4, 5, 6
by drscheme » Sat Mar 09, 2013 1:25 pm
It seems that all people have the same problem: the pesky SD-Card corruption. I read lots about backing up or restoring the card and also trying to fix the card. But I didn't find a thread that describes what we can do to PREVENT SD-Card corruption. I'm sure there must be some "fancy" tweeks that help that the Card's file system don't die so quickly.

What I try now is the following:

1) Check the file system every three reboots:
tune2fs -c 3 /dev/mmcblkp02

2) Allow auto correction:
nano /etc/default/rcS --> FSCKFIX=yes

I have no idea and no experience how good that works. But it is worth a try.

Has anybody else another idea?
Posts: 20
Joined: Thu Feb 14, 2013 8:33 am
by malakai » Sat Mar 09, 2013 1:31 pm
Corruption generally occurs when writing data to the card. The influencing factors are power loss and over clocking.

If you loose power when writing to the SD Card it can corrupt the card. This is typically due to cutting power during shut down, power on, etc.. When the Pi is up and running a lot is happening in memory and no writes are committed so power loss is not a guarantee of corruption when the Pi is running.

Extreme overclocking can corrupt the data as it's being written to the card if you experience corruption with over clocking try backing off or down your overclock settings.

One option is to move everything but the boot off the SD Card however if while writing a file to the other media both examples can still corrupt that file.
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)
User avatar
Posts: 1383
Joined: Sat Sep 15, 2012 10:35 am
by shuckle » Sat Mar 09, 2013 1:33 pm
I think sd corruption is rare. I have only seen those when playing with extreme overclocking. (more than 1000 mhz). After the raspberry is working stable, there should noit be corruptions.
Posts: 433
Joined: Sun Aug 26, 2012 11:49 am
by drscheme » Sat Mar 09, 2013 1:47 pm
shuckle wrote:I think sd corruption is rare. I have only seen those when playing with extreme overclocking. (more than 1000 mhz). After the raspberry is working stable, there should noit be corruptions.


I'd be happy if this would be rare. Mine is not overclocked, I use a SD-Card that is on the list of supported hardware, I have no external USB-devices attached, I shutdown/reboot the device properly, ... But I get errors once a week or, when I work (configure) a lot with the Pi, nearly once a day. So dd got to my best friend meanwhile :lol:
Posts: 20
Joined: Thu Feb 14, 2013 8:33 am
by dom » Sun Mar 10, 2013 7:42 pm
drscheme wrote:I'd be happy if this would be rare. Mine is not overclocked, I use a SD-Card that is on the list of supported hardware, I have no external USB-devices attached, I shutdown/reboot the device properly, ... But I get errors once a week or, when I work (configure) a lot with the Pi, nearly once a day. So dd got to my best friend meanwhile :lol:

Can you try a different sdcard?
(genuine) Sandisk sdcards seem quite resistant to corruption.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4011
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by rspitz » Mon Mar 11, 2013 3:41 pm
I bought a recommended 4GB Sandisk card together with mit Pi. I've been experiencing lockups and freezes of my Pi when updating with rpi-update or apt-get (for kernel updates) increasingly for a couple of months, which seem to be due to SD card corruption. I don't have a Linux PC with SD card reader at hand, so the only way to verify the corruption was to boot from a Live CD and mount the SD card.

I don't believe that there is a reliable way to prevent these corruption issues on a flash memory device, unless a filesystem is used that is optimised for flash. Is there any chance that images will be provided that don't use ext4 for the root partition, but a flash optimized file system?
Posts: 49
Joined: Tue Jul 31, 2012 7:25 pm
by MaxK1 » Mon Mar 11, 2013 4:23 pm
That's the kicker - GENUINE. I have a couple of Sandisk cards where the plastic seems awfully brittle and prone to flaking off and/or cracking - much more so than other cards I've used. (I no longer use them) I suspect the cards are not genuine...
Posts: 477
Joined: Sun Aug 26, 2012 11:34 pm
by obcd » Mon Mar 11, 2013 4:34 pm
filesystems optimised for flash are intended for a flash memory chip, not for an sd card that has a buildin controller taking care of the flash chip housekeeping. I have seen a version for sd cards once, but it wasn't FOSS. The idea was that they stored everything twice on the sd card with an embedded crc check. At boot, the crc checks were verified in the background, and the contents of the block restored by the backup if the crc failed. It used some cpu resources during this process, and it also more then halved the usable capacity of the sd card.
I assume that limiting the writes to the sd card by removing the swap and having the logfiles stored on a ramdisk or usb stick would improve sd card corruption a lot.
Posts: 890
Joined: Sun Jul 29, 2012 9:06 pm
by dom » Mon Mar 11, 2013 6:53 pm
MaxK1 wrote:That's the kicker - GENUINE. I have a couple of Sandisk cards where the plastic seems awfully brittle and prone to flaking off and/or cracking - much more so than other cards I've used. (I no longer use them) I suspect the cards are not genuine...


Apparently one third of Sandisk branded memory cards are fake.
http://www.petapixel.com/2011/05/20/one ... unterfeit/

rspitz wrote:Is there any chance that images will be provided that don't use ext4 for the root partition, but a flash optimized file system?

f2fs is (potentially) the most suitable file system for sdcards. It is *very* new and is supported by the 3.8 kernel.
The hope is that we will get a working 3.8 kernel with an f2fs sdcard image at some point. It may be more efficient and improve sdcard's lifespan (through fewer writes). Whether it reduces corruption remains to be seen.
Some info here: https://github.com/raspberrypi/linux/issues/225
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4011
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by mdperry » Tue Mar 12, 2013 2:39 am
drscheme wrote:
shuckle wrote:I think sd corruption is rare. I have only seen those when playing with extreme overclocking. (more than 1000 mhz). After the raspberry is working stable, there should noit be corruptions.


I'd be happy if this would be rare. Mine is not overclocked, I use a SD-Card that is on the list of supported hardware, I have no external USB-devices attached, I shutdown/reboot the device properly, ... But I get errors once a week or, when I work (configure) a lot with the Pi, nearly once a day. So dd got to my best friend meanwhile :lol:



Same here. My SD has been corrupted 5 or 6 times in the three months I have had my Pi. I am also careful to shut down properly, no overclocking, etc. Definitely the most frustrating thing about an otherwise remarkable little piece of hardware.
Posts: 13
Joined: Mon Dec 31, 2012 10:18 pm
by Bashster » Tue Mar 12, 2013 7:39 pm
I'm getting terrible problems with corruption as well. It's as if the distro I'm using (Raspian) is like very, very buggy and really not fit for release. Are people having the same problem with the other flavours?
Posts: 41
Joined: Sat Jan 19, 2013 3:00 pm
by pluggy » Tue Mar 12, 2013 7:45 pm
I have a theory, most of the corruption problems are with class 10 cards. Having 4 Pis which get their share of abuse, and never having had a corrupted card in going on 12 months, I must be missing something. Perhaps its because I don't use anything higher than class 4.......

The early images had problems with class 10's, maybe it isn't out of the system yet.
Don't judge Linux by the Pi.......
User avatar
Posts: 2421
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
by Bashster » Tue Mar 12, 2013 11:13 pm
I don't wish to shoot your theory down in flames; after all it's only one result so far, but the card that I've had the worst trouble with is a Transcend class 6 one. I'm just about to give a Kingston class 4 one a try....
Posts: 41
Joined: Sat Jan 19, 2013 3:00 pm
by obcd » Wed Mar 13, 2013 9:25 am
First thing we should be able to figure out is how to check if a sd card is genuine.
Untill now, I haven't had sd card corruptions either. All my cards are also Class 4.
I usually shutdown properly, but sometimes pull the plug when the system hangs.

All this doesn't change the fact that flash technology has a limited number of write cycles.
We don't even know if sd card controllers attempt to do wear levelling, as for the normal use of such a card it simply isn't needed.

We assume corruptions are happening during writes when the sd card controller is performing some background tasks to combine dirty sectors into one page for erasure. Maybe some fake cards corrupt randomly for no explainable cause. The only thing we can assume is that corruption will appear less frequently if we reduce the writes to the card. Something that crosses my mind for that are moving the logfiles to a ramdisk.
Posts: 890
Joined: Sun Jul 29, 2012 9:06 pm
by shuckle » Wed Mar 13, 2013 9:44 am
I have 4 Transcend class 10 cards with zero corrupytion (except when doing high overclock tests).
Posts: 433
Joined: Sun Aug 26, 2012 11:49 am
by rspitz » Thu Mar 14, 2013 8:32 am
MaxK1 wrote:That's the kicker - GENUINE. [...] I suspect the cards are not genuine...

Well, I bought the card together with my Pi directly from RS. I don't really believe they sell fake products.
Posts: 49
Joined: Tue Jul 31, 2012 7:25 pm
by EdVoncken » Sun Mar 17, 2013 5:14 pm
I've been seeing VERY frequent SD-Card corruption, unfortunately.

I can leave my Raspberry on for a few days without logging in, and corruption is virtually guaranteed. Re-image the card, everything is fine. Wait a while, and the mmcblk0 errors appear.

Hardware: Raspberry Pi 256MB (first edition, from RS)
OS: 2013-02-09-wheezy-raspbian.img
Written using Mac OS X (dd)

Problem occurs with all SD Cards I tried:
* 1x Kingston 8GB Class 4 SD-Card (new)
* 2x Kingston 8GB Class 4 micro-SD with adapter (new)

Edit: forgot to mention; NO overclocking or modifications whatsoever...
Posts: 5
Joined: Sun Mar 17, 2013 5:00 pm
by obcd » Mon Mar 18, 2013 8:07 am
What is connected to your Pi that corrupts the sd cards? Maybe some usb device is causing a massive creation of log files? Just a wild guess. Your TP1 TP2 voltage is interesting to know as well.
Posts: 890
Joined: Sun Jul 29, 2012 9:06 pm
by TheQuestor » Mon Mar 18, 2013 8:47 am
I'd personally try a different power supply or usb cable. I TORTURE my raspi and it has only corrupted the card one time and that was when I had it overclocked to over 900mhz. When I had a really cheap PSU and cable it happened a few times, but after I changed both out I never have a corruption issue. Though I do keep the OC to 900 just in case :)
Posts: 69
Joined: Wed Nov 28, 2012 9:15 am
by EdVoncken » Mon Mar 18, 2013 9:37 pm
obcd wrote:What is connected to your Pi that corrupts the sd cards? Maybe some usb device is causing a massive creation of log files? Just a wild guess. Your TP1 TP2 voltage is interesting to know as well.

I have no peripherals attached to the Pi - just the RS-supplied USB power supply and a network cable. It doesn't seem like the partitions are filling up. The Pi is just idling along, until the storage starts failing.

TheQuestor wrote:I'd personally try a different power supply or usb cable.

I'm running a stock Pi, 256 MB, no overclocking or anything. The power supply came in the set from RS, so I'm assuming it's a quality PSU.

For more testing, I have ordered two different brands of SD Card, Sandisk 4GB Class 2 and a Transcend 4GB Class 4. Perhaps this will make a difference...

Thanks for thinking along!
Posts: 5
Joined: Sun Mar 17, 2013 5:00 pm
by obcd » Mon Mar 18, 2013 10:46 pm
I also use the RS power adapters. They seem to produce a stable voltage and the wire connected to them doesn't has a high voltage drop. I did notice that the Pi polyfuse had a 0.12V voltage drop. I soldered an additional 1 Amp polyfuse over the one already present. It increased my TP1 - TP2 voltage from 4.84V to 4.95V.
In your case, trying another sd card sems like a good thing to try out. If that doesn't help, you could check your TP1 - TP2 voltage, as I know some of the boards had a bad Polyfuse to start with.
If that seems fine as well, you could consider another Pi. You might request an RMA to exchange it under warranty.
Posts: 890
Joined: Sun Jul 29, 2012 9:06 pm
by poing » Mon Mar 18, 2013 10:58 pm
And what about mains voltage? I can imagine that fluctuating voltages or sequences in the mains supply cause problems?
Posts: 1097
Joined: Thu Mar 08, 2012 3:32 pm
by pudding » Mon Mar 18, 2013 11:09 pm
EdVoncken wrote:I've been seeing VERY frequent SD-Card corruption, unfortunately.
Written using Mac OS X (dd)


I've had that when using Mac and the dd command. Try using the Windows official diskimage writer, which works perfectly for me on the same SD card.
(aka squid). Author of MAME4ALL for Pi, PiSNES, PiFBA & PiMenu
Posts: 89
Joined: Sat Jan 12, 2013 3:55 pm
Location: UK
by dan_fritz » Tue Mar 19, 2013 9:34 am
I also have a lot of SD card corruption problems, I don't overclock, have a decent power supply and shut down the PI correctly. For some reason the raspberry pi corrupts the SD card at random and I need to restore a backup every week in order for it not to corrupt.

I've tried 4 different brands and sizes of SD cards and it still the same problem. So now I'm moving everything over to a USB, hope this will work...
Created of the ArduinoPi, a PHP/Python API for controlling an Arduino with the Raspberry Pi.
More info: http://www.fritz-hut.com/all-projects/arduinopi/
Posts: 13
Joined: Tue Jul 31, 2012 3:36 pm
Location: Belgium
by obcd » Tue Mar 19, 2013 12:14 pm
The Pi power adapter should produce a stable 5V output voltage, even if the mains voltage is fluctuating. Some have an input voltage of 100V - 240V. That's a lot of fluctuation.

I really don't see how a mac dd would produce a worse sd card than the windows diskimager. Both programs work by copying raw sectors over to the sd card. An sd card has a digital interface.
It's not like a cd-r that some devices can't read depending upon the device and speed it was used to burn.
Posts: 890
Joined: Sun Jul 29, 2012 9:06 pm