jeanrocco
Posts: 9
Joined: Sun Jan 27, 2013 4:11 pm

SD corruption on power outages

Sun Jan 27, 2013 4:26 pm

Hello, I'm very pleased with the RP, I own 2... but is there a way to prevent SD corruption after a power failure or shutdown. This is happening too often and poses a serious concern about the RP reliability. It does not reboot then and the only cure is to reflash the SD... doing so implies you loose all the work you had made, unless you had a backup, or a pair of RPs :-) !

I'm aware I could use a 5 volt battery to power the RP, and a charger on the battery, but is there another simple hardware or software cure for this problem.

Thanks.
jrb. e. Ing.

W. H. Heydt
Posts: 13612
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: SD corruption on power outages

Sun Jan 27, 2013 4:56 pm

If you'd seen as many datacenter problems as I have, you'd be paranoid about making backups, too.

I run the power for my Pis through a UPS *and* I maintain backups (for reflashing if nothing else) on another machine. I haven't gone all the way to off-site backups...yet.

Max

Re: SD corruption on power outages

Sun Jan 27, 2013 7:29 pm

You might want to put your data on an USB stick/drive instead, and only use the SD card to boot.
Despite that the USB controller is not the best either, I had less problems with those than with SD cards.

Rasoul
Posts: 3
Joined: Fri Feb 01, 2013 10:15 pm

Re: SD corruption on power outages

Fri Feb 01, 2013 10:46 pm

I agree that this is really annoying. I have a solution in my mind that I'm going to implement.

1) Using an emergency battery that can power the system at least for a few minutes. (the candidate is a 7.4V/750mA Li-Ion battery [~10 USD]).
2) A step-down DC-DC convertor to get 5V/750mA output from the battery (the candidate is R-78B5.0-1.0 [~12 USD], cheaper solutions are also possible).
3) A custom design circuit that the battery regulated power and the Mini USB power are fed to, and it provides the output power to the PI board. The circuit should be able to detect its input Mini USB power failure to automatically switch to the battery power and report it as a LOW/HIGH active signal to one of GPIOs [~15 USD].
4) A program which starts as the OS and reads the GPIO pin by polling. If a main power failure is detected, the program kills all the process and shutdowns the Pi properly. This should prevent the SD corruption.

I'll glad to have people's opinion about this approach.

User avatar
Jessie
Posts: 1754
Joined: Fri Nov 04, 2011 7:40 pm
Location: C/S CO USA

Re: SD corruption on power outages

Sat Feb 02, 2013 6:12 am

I plug my media player (openelec) into the USB port on the TV set so it powers up and down every time the TV comes on or off. I turn the set on and off, my family turns it on and off, no one even thinks about the Pi connected to it. I almost never halt the system. I have only ever had the SD card need to be reflashed one time because of this in almost one year. There has to be another variable here, like your use case or the card you are using or something like that.

A low end PC UPS could run an R Pi for some time. If it is that important you could look for a used one somewhere. When I used to live in the countryside with spotty power (power flickers and brown outs) I had to have one on every electronic device or they would cut out several times durring use. Often times I could find one for around $35 new, and that worked fine to cover a 1 to 10 sec outage plus many of them had USB ports that would safely shut the PC down after a user set amount of time. You could also make something with a relay that switched between a Li battery and primary power. Would be pretty easy because most relays have both NO and NC contacts after that it would just be a matter of hooking up GPIO to tell the R-Pi to shut off after power has been cut for x number of ns.

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: SD corruption on power outages

Thu Jul 18, 2013 9:28 am

I've been having this issue too... usually it's not an issue because I shut down my Pis or I put them on a battery backup, but recently I connected two of them to two LCD displays and the displays are often powered down by accident.

I was thinking that making the rootfs read-only and then having a scratch file system in a separate partition or in RAM could work ? Every time the machine reboots the scratch partition can be erased or refreshed ? Anyone have any idea how to do this ? This is a similar scheme to a Linux Live-CD or an Android device.
EOF

pjc123
Posts: 921
Joined: Thu Mar 29, 2012 3:37 pm
Contact: Website

Re: SD corruption on power outages

Thu Jul 18, 2013 11:28 am

jeanrocco wrote:Hello, I'm very pleased with the RP, I own 2... but is there a way to prevent SD corruption after a power failure or shutdown.
APC UPS at home, strictly batteries in the field, running 3 pi's (one for a year), and I never had a corrupted SD card, with more power glitches and shutdowns than I can count. You state that you get an SD card corruption even after a shutdown; that should never happen during a proper shutdown unless you didn't wait for it to complete (especially the filesystems being unmounted), you have defective hardware, a faulty OS image or improperly installed software, or you got a power failure/spike/dip at the same time it was shutting down.

EDIT: I just realized that someone replied to a post 6 months old, so ignore.
Last edited by pjc123 on Thu Jul 18, 2013 12:53 pm, edited 1 time in total.
My Raspberry Pi Project Page:

https://www.flaminghellmet.com/launch/

MattF
Posts: 55
Joined: Tue Feb 12, 2013 10:01 am

Re: SD corruption on power outages

Thu Jul 18, 2013 11:43 am

aquarat wrote:I've been having this issue too... usually it's not an issue because I shut down my Pis or I put them on a battery backup, but recently I connected two of them to two LCD displays and the displays are often powered down by accident.

I was thinking that making the rootfs read-only and then having a scratch file system in a separate partition or in RAM could work ? Every time the machine reboots the scratch partition can be erased or refreshed ? Anyone have any idea how to do this ? This is a similar scheme to a Linux Live-CD or an Android device.
Have a look for the aufs root file system thread in power users.

With /boot mounted RO, and / RO with a RW overlay I've found things to improve massively. I need changes to persist, so I use another partition as my RWFS but you could use tmpfs for RW if you can loose changes.

Having /var/log and a few others on tmpfs significantly reduces writes to the SD as well, which can only be good from an integrity perspective.

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: SD corruption on power outages

Thu Jul 18, 2013 11:46 am

Thanks MattF, that's good advice. My devices can lose changes :) .
EOF

Return to “General discussion”