I recently installed a Pi Zero running Pi-hole for my folks. They live in a rural area and only have a 4G Modem with a limited data plan. The issue, is that every now and then there are power outages due to bad weather.

Is there a way I can configure the filesystem so it can handle ungraceful power downs when there's a power outage?

  • 1
    install a UPS that can interface with the RPi either by USB or serial connection ... run a UPS monitoring watchdog program – jsotola Dec 29 '19 at 18:36
  • I also thought about using a power bank with USB ports. Apparently it can channel 1.0A which should be more than enough for the Pi Zero. However, a UPS sounds like a more robust solution. Thanks for the suggestion @jsotola – Juan Marco Dec 29 '19 at 23:18
  • power bank is ok to use, but the RPi needs to detect a power outage so that it can perform a graceful shutdown ... not really sure how it would turn back on though .... i think that there may be some product available to do that – jsotola Dec 29 '19 at 23:50
  • Does their 4G modem continues to function during a power outage? Are you trying to keep their service up, or just concerned about data corruption on the RPi SD card due to power outages? – Seamus Dec 30 '19 at 12:46
  • Currently the 4G Modem is a USB stick that's not attached (yet) to the Pi. This means that if the power's down, there's no Internet. I was planning on connecting the 4G USB stick to the Pi via micro USB adapter, this way they'll have Internet along with ad-blocking capabilities. – Juan Marco Dec 30 '19 at 23:14

The (native) ext4 filesystem is said to be robust with respect to power outages (ref.). I'd guess that file system corruption due to a shortcoming of ext4 is less likely than random corruption of your SD card. If that's true, consider spending a bit more for a high-quality SD card & don't worry too much about tweaking the filesystem. Maintaining a good back-up of your SD card is a wise practice also.

There is at least one technique for making the FS more resistant to corruption: mount the drive using the barrier option (see this Q&A). I'm not sure the barrier option for mounting a drive is available in the Raspbian kernel - or if it's necessary in this case, but this is a possibility if you want to do some more research.

  • 1
    I'm not sure the barrier option is built into the Raspbian Kernel @Seamus. According to the Linux Kernel Archives ext4 enables write barriers by default. I checked fstab as well as the output of mount and did not see any barrier option for the root / filesystem; if it's enabled, I found no way of proving so. They only thing I can report is that at the time of this comment, we had 6 power outages and Pi Zero is running perfectly. – Juan Marco Jan 2 '20 at 16:32
  • 1
    Update: I edited fstab and added the barrier=1 option to /. After rebooting the system and calling mount it didn't show a barrier option. However, running the command dmesg | grep barrier yields that / has been mounted with Opts: barrier=1. So, apparently barrier is indeed built into the kernel 4.19.75+. – Juan Marco Jan 2 '20 at 16:50
  • @JuanMarco: That's very interesting! In the "hidden" comments to the answer I referenced, the author of that answer stated that barrier was built in & enabled by default on ext4. That's consistent with your findings in LKA. The only thing that occurs to me is this: Does dmesg report a default built into the kernel, or does it report the fact that an option has been set in fstab? Ideally, it would do both, but experience suggests this may not be so. I feel this is a question worth of further research :) But it seems almost certain that enabling the option does no harm. – Seamus Jan 2 '20 at 19:11
  • dmesg currently reports that the fs was "re-mounted" with Opts: barrier=1. This appeared after I enabled barrier option from within fstab. Before this, there were no other indications or defaults related to barrier (at least that I could find) from the dmesg output. – Juan Marco Jan 2 '20 at 19:35
  • @JuanMarco: Yes, exactly... all I'm saying is that if barrier is a default in ext4, then dmesg might not report it. – Seamus Jan 2 '20 at 21:28

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.