2

I need your help on this :

  • How can I protect my read-only Raspian Raspberry pi not to corrupt SD card sectors ?

  • Why does it ever happen and so frequently in my case ? (I did probably did something wrong)

Context

I am building a video-looper on Raspberry Pi that I can cut with power-off. (I know this is weird use of a computer)

I have an omx-player based video looper app running on Raspian.

To make it robust to power-loss I did put my system in read-only with this script : read-only.sh

Tests and results

System : 2015-02-16-raspbian-wheezy

Mini SD card of 8Gb

Video is read from a read-only mounted USB key

Very frequently (1 times out of 3 on some SDs, 1 time out of 15 on others), I get this error, preventing the system to boot (I can still reboot it and it works fine after) :

mmcblk0: error -110 transferring data, sector 855376, nr 8, cmd response 0X900, card status 0xb00
mmcblk0: retrying using single block read
mmc0: Controller never released inhibit bit(s).
// Dump here that I did removed
mmcblk0: unknown error -5 sending read/write command, card status 0x900
blk_update_request: 22 callbacks suppressed
blk_update_request: I/O error, dev mmcblk0, sector 740480
blk_update_request: I/O error, dev mmcblk0, sector 740488
blk_update_request: I/O error, dev mmcblk0, sector 740496
blk_update_request: I/O error, dev mmcblk0, sector 740504
  • Did I not correctly put my system in read-only mode or does a read-only system not prevent a power-loss to corrupt an SD card ?

Any help appreciated !

  • Is there a display attached to the pi for this? Do you kill the power to the display at the same time, or leave it on? – goldilocks Mar 16 '15 at 17:47
  • NOTE It is NOT possible to make a Linux system RO (without additional storage or RAM disk). – Milliways Mar 16 '15 at 22:08
  • @goldilocks Yes there is a display attached, and the power is killed at the same time, would it be a reason ? – Lyptik Mar 17 '15 at 13:33
  • @Miliways I'm using the RAM for read write (so my logs for example are not persistent) – Lyptik Mar 17 '15 at 13:34
2

If the pi is working properly, SD card corruption should never happen regardless of whether the card is rw or ro (at least until the card is worn out, which would take quite a long time). The exception would be pulling the plug suddenly on a busy system, in which case a rw filesystem will be more vulnerable. Since you have decided to do that regularly, you've opted for a ro filesystem, which should ensure it will not be left in an inconsistent state on boot. The fact that it seems to be anyway narrows things down.

Here's two possibilities:

  1. The errors you are getting do not represent filesystem corruption, but a hardware level I/O problem.

    I have never had this problem on the pi, but other people here have observed that in cases like this insufficient voltage may be the issue. You need to make sure your supply is sufficient for the pi and everything attached to it. Turning everything on and booting creates a very sudden draw -- the processor is 100% active and everything is coming on line. If it browns out because of this something may fail momentarily, such as the SD card reader.

  2. The errors you are getting are due to filesystem corruption, caused by some power fluctuation when you shut down.

    If this is the case, you have a difficult problem unless you can rearrange something. Anecdotely, I'd say the pi's have some extraordinary sensitivities when it comes to power and voltage fluctuations on the circuit they are on. In addition to that linked story, I have a pi with an FM transmitter that will cut out (presumably because it momentarily loses 3.3 V from the pi) when certain other things are (un)plugged on the same household circuit.

One thing you can do is add this to the beginning of /etc/rc.local1:

echo "-y" > /forcefsck

This will cause a forced e2fsck -y /dev/mmcblk0p2 at boot, which will add 10-15 seconds to the boot time, but should fix any filesystem corruption. If it does not work, or the problem occurs before this can happen, it's again not filesystem corruption, it is something more fundamental. You could try a different brand of SD card. If that does not change anything, try using the pi in a different environment and doing something similar (unplugging it suddenly) and seeing if you get the same result. I try to avoid doing this but I do on occasion and am not really afraid of it because nothing bad has ever happened, which implies either:

  • There is something weird about your situation.
  • There is something wrong with your pi. There have been millions of them made, they can't all be perfect -- here's an example from yesterday.

The only way to rule out the last case would be if you have another pi to test under the same circumstances. If it does the same thing, obviously the circumstances are to blame.


1. Obviously that won't work if the fs is read-only. In that case you could just try mounting it rw and adding that file (/forcefsck, which should just be 3 bytes, -y and a newline). In theory this is erased after the fsck, which is why it needs to be replaced every boot, but that may not happen if the fs is ro.

  • I suspect it's because he is cutting power when omx-player is up and displaying the video file. Although file itself is on USB, omx-player is on SD. – geoffmcc Mar 16 '15 at 17:14
  • @geoffmcc The fact that oxm-player is on the SD wouldn't matter, because it would be loaded into memory if running. But I guess that would represent a fairly active state for the processor and gpu plus whatever the USB stick pulls when being read (= greater current draw) which might be a factor in some sudden voltage fluctuation when the power cuts... – goldilocks Mar 16 '15 at 17:46
  • There's also the issue of whatever display is attached. – goldilocks Mar 16 '15 at 17:46
  • @geoffmcc and goldilocks : Here is the additionnal data : video file is read from the usb stick mounted as read-only, omxplayer is of course on the SD with the system. Hardware is a 7" LCD screen with its own power supply and I'm cutting both at the same time. My power supply for the rpi is 1A and is an official Raspberry PI PSU – Lyptik Mar 17 '15 at 13:40
  • @goldilocks Thank you so much for your answer and method, I will apply that and getting back with the result, I have 10 raspberry pi / screens / sd so I should narrow it down to find the solution – Lyptik Mar 17 '15 at 13:45
0

If you have another USB drive, you can move the filesystem to that, using this guide.

This way it will only ever use your SD card for a brief moment on boot (and write firmware updates if you update firmware).

Edit: or you can just put it on your existing drive and then put video file in home (or anywhere else) so you only need the 1 drive, rather than 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.