Forum
[IDEA] Auto fix SD card corruption - Printable Version

+- Forum (http://forum.xbian.org)
+-- Forum: Software (/forum-6.html)
+--- Forum: Testing & Experimental (/forum-21.html)
+--- Thread: [IDEA] Auto fix SD card corruption (/thread-421.html)

Pages: 1 2


Auto fix SD card corruption - CurlyMo - 8th Feb, 2013 07:30 PM

Yesterday i stumbled on a message of one of our users about an SD card corruption. This was due to a sudden removal of the power cable. Now and then, i experience the SD card corruption as well. Mostly because i have weeks in which i reboot my RPi like 100+ times to test new features. My idea was to let a script test the state of the SD card before it was mounted as the root partition so we know if we can expect corruption and if so, fix it automatically.

I have several ideas for this, but the one i would like to try first, is also the simplest. So, i'm especially looking for people who experience the SD card corruption a lot (due to filesystem incosistencies), and that like to test something.

The idea is simple. Instead of asking the user to log-in into the rescue kernel to run fsck, i want to force fsck by default, so it fixes the FS without notice. This can be enabled by running this command:
Code:
sudo sed -i 's/#FSCKFIX=no/FSCKFIX=yes/g' /etc/default/rcS && grep "FSCKFIX=yes" /etc/default/rcS | wc -l

The command was successfull if it outputted a 1

Please stress the SD card a little by suddenly removing the power plug and by enabling Turbo Mode etc. Stuff that would normally be a risk of corruption.


RE: Auto fix SD card corruption - raspberry_pd - 10th Feb, 2013 04:06 AM

I was looking into this topic and did not get very far as my skills are not up to it. However it seems crucial until most Pi's have proper power switches and even then, it will still be invaluable. Let's face it, Windows has had something for almost two decades and I've always found the Windows version very handy.

CurlyMo are you generally able to recover your corrupted SD cards or are they 'bricked'. I would like to crank the overclocking up (for the first time) and try to help test your new methods but honestly, I do not want to burn through too many cards. If it's just file systems that get corrupted and not necessarily the actual physical cards, I'm in!


RE: Auto fix SD card corruption - CurlyMo - 10th Feb, 2013 04:11 AM

I can fix my FS most of the times with the rescue kernel. However, only had to do it two or three times.

Also, you just have to run the command to enable the (possible) fix. And yes, it only works if the FS gets corrupt, not when the SD breaks. I can't guaranty that the SD card doesn't break, depends on a lot of factors.


RE: Auto fix SD card corruption - nvd - 10th Feb, 2013 04:48 AM

I had this happen to me recently. Unfortunately, had to reformat the entire thing because I had no access to a linux computer that was able to see the ext4 partition.

Edit: Anyone on osx know of a fuse that gives you read and write support for ext4? I was only able to find one that gave you read support and even then it was shoddy.


RE: Auto fix SD card corruption - Uncle_Tubbie - 10th Feb, 2013 04:55 AM

Thank you very much for this. I have corputed a few SD cards from trying to overclock.


RE: Auto fix SD card corruption - CurlyMo - 10th Feb, 2013 06:03 AM

Don't thanks me yet, just testing...


RE: Auto fix SD card corruption - Scanto - 12th Feb, 2013 06:28 PM

Seems to work for me.
Usualy my card is corrupted every now and then (because my girlfriend just turns of the switch)
But I have to admit that I've ran the command after an update to Alpha5.
So I'm not sure if Alpha5 or the command cures the issue.


RE: Auto fix SD card corruption - CurlyMo - 12th Feb, 2013 07:00 PM

Did you notice your kernel fixes things on boot or that the boot took a little while longer at those times?


RE: Auto fix SD card corruption - Scanto - 12th Feb, 2013 07:08 PM

Sorry no.
I usually run the pi headless as download server.
It's only connected to hdmi when it doesn't boot up or when I want to watch a movie.
On next few boots I'm gonna keep an eye on it.

Is there somwhere a log file where I can see if and when fsck was performed?


RE: Auto fix SD card corruption - CurlyMo - 12th Feb, 2013 07:13 PM

By running
Code:
tune2fs -l /dev/mmcblk0p2 | grep "[0-9]\{1,2\}:[0-9]\{1,2\}:[0-9]\{1,2\}"

I think it's the "Last checked:" you need to look at.


RE: Auto fix SD card corruption - Scanto - 12th Feb, 2013 11:50 PM

hm... it says last checked 07. february.
so the sd card wasn't checked since performing the command.
I'm gonna unplug the pi a few times this evening to see if something happens, though I'm sure it was already unplugged several times since forcing fsck.


RE: Auto fix SD card corruption - namtih - 14th Feb, 2013 04:41 AM

I got a kernel panic today at startup. It can't mount the root partition.
So it seems the command doesn't really help - unfortunately :-(
Would be a great benefit when these annoying filesystem corruptions could be prevented. Strange thing is that I didn't change anything. I just did a reboot from the XBMC menu and....booom...kernel panic - arrrrgh.


RE: Auto fix SD card corruption - CurlyMo - 14th Feb, 2013 05:38 AM

There are two types of corruption. The hard kernel panic or the filesystem inconsistencies. The fix should be for the second one.


RE: Auto fix SD card corruption - Scanto - 14th Feb, 2013 09:28 AM

i had still no corruption after unplugging pi several times.
the only thing I could see during startup was something like:
checking root file system... fsck from util-linux 2.20.1
e2fsck 1.42.5
/dev/mmcblk0p2: clean, 62621/245760 files, 497415/959104 blocks
done

and a few lines later:
checking file systems... fsck from util-linux 2.20.1
dosfsck 3.0.13
/dev/mmcblk0p1: 20 files, 15318/34662 clusters
done


I'm note sure if I get this post with fsckfix set to no.
But no matter if its fsckfix or alpha5, I had no corruption since days even though I've unplugged the pi many times. So either alpha5 or fsckfix works for me Smile


RE: Auto fix SD card corruption - CurlyMo - 14th Feb, 2013 09:34 AM

This indeed means fsck ran automatically in your case. Great!