This question already has an answer here:

I want to create a stand-alone internet radio device. Therefore I want to use an existing subwoofer box with connected speakers. Inside the subwoofer box there is the electronics for the sound system. There is also a 5V supply wire where I can connect my Raspberry to.

But what if my radio is running and I don't want to listen to it anymore? I can't just plug out the subwoofer box from the socket. This will cause the Raspberry Pi to lose its supply. The filesystem on the SD card will be harmed if such a plug-out is performed when OS is running. I'd like to properly shut it down by recognizing the plug-out and executing sudo halt after that.

What is the best solution for my intention? I have thought of a backup battery for the Raspberry Pi. Just like the battery which is used on motherboards. But will 3.3V be enough? Is there a battery which can provide that much current to run the Raspberry Pi (Note: a HD44780 display and a WLAN dongle is also connected to the Raspberry Pi)? How can I assure the battery is not used when the regular 5V supply is available (to not use battery AND 5V supply at same time).

Any help is appreciated.


marked as duplicate by Olin Lathrop, Dave Tweed, Kaz, Brian Carlton, Anindo Ghosh Apr 19 '13 at 3:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ There are lots of GPIO pins. You can attach a button to it and run a program/script to check for it's state periodically or let for interrupt, which would run halt for you. \$\endgroup\$ – TNW Apr 18 '13 at 18:15
  • 3
    \$\begingroup\$ You could figure out how to run the Pi with all of the filesystems mounted read-only. Then you should have no problems with corrupted filesystems by turning it off. \$\endgroup\$ – Craig Apr 18 '13 at 19:53
  • 1
    \$\begingroup\$ @PhilFrost Isn't Journaling on SD cards pretty much a no-no? Constantly writing to the sd card will kill it quickly. Same with ATime. It's normally recommended to disable journaling and use the noatime mount flag. \$\endgroup\$ – Passerby Apr 18 '13 at 20:42
  • 1
    \$\begingroup\$ @Passerby depends on how much writing you do, how your SD card and software perform wear leveling, whether you are using SLC or MLC flash, what your allowable failure rate is, and so on. Sure it's a failure mode to consider, but I wouldn't say it's a "no-no". \$\endgroup\$ – Phil Frost Apr 18 '13 at 20:47
  • 1
    \$\begingroup\$ @Passerby and the biggest failure mode of resistors is overheating. Does that mean they all need to be liquid cooled? No, you look at the power dissipation of the resistor and size it appropriately. If you are using flash storage, you look at how much writing you do, and the acceptable lifetime, and make appropriate decisions. \$\endgroup\$ – Phil Frost Apr 18 '13 at 21:46