Raspberry Pi SD card corrupted after power failure

Hopefully this is an easy FAQ… But, I just lost my image (again) after a recent power failure at the receiver.

My question is; Is there another storage media that I can use on my Raspberry Pi that would be more robust when it comes to intermittent power fails (without properly shutting down the OS)? This receiver is on a mountain top about 30 minutes away so I can’t get to it right away to rebuild my image. Since we are just going into fire season where the power utility shuts off power on a regular basis when the winds blow, I wanted to make sure that this time it will come back.

In case you were wondering; I had a copy of the CD image sitting right next to the receiver and when it goes down all I need to do is swap it out. But, the most recent power failure came before I had a chance to make another backup (and working image). Somewhere I read about how you can use another media for your OS and the SD card is just a boot device which might help if the power glitch doesn’t hit anything on the SD.

So, thanks in advance for any ideas of how to harden a Raspberry Pi from intermittent power failures.


Buy a UPS and plug the Pi power supply into it. It will give you several minutes of battery power depending on the rating of the UPS, will filter “dirty” power, eliminate spikes and drop-outs, and sound an alarm when the UPS loses power and switches to the battery so you can ssh into the Pi and run sudo shutdown.

A different memory media (USB thumbdrive or external HDD/SDD) won’t help. They’d just get corrupted too.

1 Like

Since the receiver is on a mountain top 30 minutes away, I doubt I would hear the alarm. Also, when the power fails we lose all internet connectivity so I wouldn’t be able to ssh into it. Even if I put the internet modem and router on the UPS too, the feed from the ISP also dies. Unless there is a routine for the Pi that will monitor the USB data port on the UPS and automatically issue a shutdown when the UPS detects a power failure. But, what would turn it back on? if the power failure is for only 5 or 10 minutes, the UPS would never run out of power and the PI wouldn’t reboot.

Thanks for the suggestions…

Avoiding all sd-card writes improves your chances. (or at least that’s the theory)
You could do that for example running the adsbexchange image, i wouldn’t toot that horn here usually but i’m not aware of an out of the box solution that does it as well.
You can install FA on there just fine.
The image will write statistics to the disk once every 24h and is currently set up to reboot every week without any condition (subject to change).
You could disable the graphs but that one write is unlikely to coincide with a power cut (not impossible though).

Which pi and which power supply is it?
I’m sure you’re already using some “industrial” or “high endurance” labeled sd-card?

If you have lots of issues, i’d just consider changing the sd-card as well as the pi if changing the sd-card doesn’t help.

1 Like

That’s the big advantage to using a UPS: the feeder continues to run through short-duration mains failures and even shorter power dropouts (like the ones frequently I get here.) Plus they provide clean power in their output. Electrical Engineering: What is Dirty Power? | TES Engineering

Is the feeder location at a radio repeater site that you have access to? Those often have back-up power solutions that you may be able to connect your Pi or UPS to.

It’s a lot rarer these days for an operating system to become corrupted by sudden hard shutdowns due to sudden power loss, thanks to the advent of journaling file systems. I’ve lost power to my Pi several times due to things like power strips or other cords being accidentally pulled loose from their sockets, either due to something I’m doing (moving things around and reorganizing) or one of my pets, and I have yet to have the SD card become so corrupted that RaspbiOS wouldn’t run, and I’m using bog-standard SanDisk Ultra cards. If you’re getting corrupted cards that often you may have a lot more power issues going on at that site than you’re aware of, which is another reason to use a filtered battery backup UPS between the Pi and the mains power source. (Either that or you have some bad SD cards, Pi or Pi power supply as Wiedehopf suggests.)

I just had another thought: being on a mountaintop the feeder may be susceptible to damage from nearby lightning strikes, surges from which could damage either the Pi or its power supply. I hope the commercial power at the site is well-grounded, which is difficult to do on most mountains due to the thin rocky soil.

A quick search indicates that there are tools out there to do this:

I haven’t tried this, but might be worth investigating - ideally you want something that shuts down the Pi when the UPS gets to low battery rather than as soon as the power fails. A lot of UPS also automatically power up connected devices when mains power comes back on after they have shutdown due to their batteries being exhausted.

Also, if you have a spare Pi, it is with checking that the SD card is the problem and not the Pi. I had a power outage a few weeks ago. When power returned my feeder ran intermittently (10 minutes to 30 minutes before freezing and needing a power cycle), then refused to reboot. I assumed it was a corrupt SD card, but as I had to go to the trouble of removing it from its outside housing, I decided to swap out the Pi as well. Before going to the trouble of putting everything on a new SD card, I tried the “flakey” SD card in the replacement Pi. It booted instantly and handled restarts and shutdowns without issues - the feeder has been running happily with that card ever since.

That’s usually not the issue, my best guess is the sd-card internal stuff gets corrupted if there are writes while power is lost.
The sd-card has wear leveling and stuff which needs a bookkeeping index which can apparently get corrupted.
It could well be that the likelihood of that happening is very different from sd-card to sd-card brand / model.
Replacing the currently used sd-card with a brand new one is the first thing i’d try.

1 Like

I use to have the same issue. Then I switched to SSD drives. Have not had a corruption after power failure since. You can get SSD drives for less than the cost of a good micro SD card. The gripe is you also need 2 extra cables. USB to SSD and USB hub (The connectors on the Pi wont fit 2 SDRs and the cable for the SSD).

I’d recommend this too.

One of my sites now fails about an hour after sunset every day.
It’s solar powered and one of the batteries has lost a cell, so it drops below the LV cutout with monotonous regularity.

but the SD card is working fine.


There actually are a couple versions of a Pi HAT that works as a mini UPS for just the Pi, and automatically shuts it down when it loses power. I don’t recall where I got the ones I used. I see a couple listed on the PiHut dot com website, you might research those a bit. Usually a pretty straightforward install, just make sure your hardware matches the UPS version, and then it’s a simple script that gets added to the Pi monitoring a pin from the HAT that tells it to shut down, so should go through a normal shutdown process. When the power returns it should boot back up on it’s own. I’ve used a couple of them with success.

I made this move some months ago, bought a cheap 128GB SSD connected directly to the Raspi because nothing else is connected (getting the data from the different device and process it).

Beside the stability the performance is a lot better than MicroSD.
There are several docker images running on it, never had an issue, even not with power failures or disconnects.

What about putting the pi os in overlay? (Maybe write protect the boot partition as well but not necessarily). Nothing persists but after initial setup, nothing needs altering except when upgrading software, in which case you disable the overlay and re-apply it after second boot…
Piaware fr24 adsbexchange all keeps stats on their own, no need to have local logs if all is configured well…


This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.