2

Is it true that removing the power cord without doing halt on a normal read-write root filesystem could cause filesystem corruption?

For my embedded project, it's impossible to shutdown with a clean halt, simply because there is no keyboard, no SSH, nothing.

For now, I solved the problem by setting the root filesystem read-only by default, but this can be annoying to have to do mount -o remount,rw / each time you boot and want to modify something.


Question: Is it possible to have both read-write filesystem and no problem when halting the Pi by removing the power cord?

4 Answers 4

3

1) I take it that this embedded project has got an user interface. So despite having no keyboard (in the conventional sense) and no ssh I don't see why it would be impossible to issue halt. After all the system just needs a push button connected to GPIO labeled "push 2 sec to shutdown". Simple script reads the respective GPIO pin and shuts down accordingly.

2) The issue whether RW or RO mounting of the SD card really reduces filesystem corruption has been discussed before, e.g. How can a read-only SD card get corrupted repeatedly? I understand that even for RO mounted filesystems the behavior during brown-out (voltage levels slowly decreasing below safe operational voltage) can corrupt the filesystem.

3) A solution to safely power down the Pi after interrupting power is a UPS (uninterruptible power supply), see How do I build a UPS-like - battery backup - system? and Circuit to safely power-down Pi for some examples. The idea is that the UPS bridges the time between "unplugging the cord" and the Pi running out of juice to issue halt and properly shutting it down.

7
  • 1
    My embedded project aims at being like a normal everyday-life-synthesizer. What happens if I remove the power cord of my Yamaha DX7? It will boot correctly the next time. The same if I remove the power cord of an Akai MPC? It will work without any problem at the next boot. I cannot tell to non-tech-people using my synthesizer "Oh, you unplugged the power cord? Then it's not properly halted, so you have to SSH..."... This project is aimed at musicians and/or people with 0 linux knowledge. That's why i really need a robust solution.
    – Basj
    Jun 2, 2015 at 9:28
  • Even your Yamaha does not shut down immediately when you unplug the cord - electronic devices typically have an RC circuit on the power supply which keeps some power supplied for a few seconds after you unplug the cord. You would have to read up on RC (Resistor/Capacitor) circuits to see how big of a cap and resistor you would need to provide power to the Pi for a few seconds, but that could be enough to do halt.
    – Phil B.
    Jun 2, 2015 at 11:16
  • 1
    Optimistically assuming you'd need 250mA for 10 seconds for a clean shutdown, you could get away with a 2.5F super capacitor (e.g. Gold Cap(TM)) on the 5V power supply to keep the 3.3V line up. - Given you have a way to quickly detect the power failure and issue the halt. - The more C the better.
    – JimmyB
    Jun 2, 2015 at 11:25
  • @HannoBinder, there was a post around here for a product for the PI doing exactly this!
    – Ghanima
    Jun 2, 2015 at 11:58
  • Your Yamaha likely does use read-only storage (but it probably also has an "off" switch, and I presume that's the proper way to turn it off, not yanking the cord). Keep in mind there are hundreds of dollars worth of electronics in a device like that whereas a pi is just a pi. With regard to using an RC circuit, the key to preventing filesystem corruption without a proper shutdown is to call sync, which shouldn't take more than a few seconds. There's also the various init services, which you should investigate to check what problems might occur because they haven't been stopped properly.
    – goldilocks
    Jun 2, 2015 at 14:13
2

No modern computer system with R/W mass storage can safely by powered down by unplugging. Most computers with a soft power button actually run software to ensure a safe shutdown. The Pi has no such circuitry, although you can add your own.

It is NOT possible to run a completely RO Linux system. Systems which use RO media (such as CD) make a R/W system in RAM, which is discarded on power off; obviously this user changes can not be saved. You can make a Pi system to do the same.

The Raspberry Pi will ignore RO flags, because it simply can't work this way, although it is possible to configure a system partition which RO.

2
  • It's a bit confusing to say you can't run a (GNU/)linux (or POSIX) system RO but you can with RO storage and RW partitions in RAM. Isn't that a system with RO storage? Of course RAM is RW, and parts of the root filesystem that require this can be put there (e.g. with tmpfs), but changes to them will not persist across boots. That's a logical limitation of a system which has RO storage, regardless of the hardware or OS. You can do it with the pi or a POSIX OS, I guess the complication is how relatively complex it becomes.
    – goldilocks
    Jun 5, 2015 at 1:19
  • @goldilocks I said "It is NOT possible to run a completely RO Linux system".
    – Milliways
    Jun 5, 2015 at 4:59
0

Even if you do not want a user interface for turning it off as @Ghanima was saying but just want to unplug the cord you could make a bash script that executes sudo halt -h when a power failure is detected(assuming you followed @Phil B. idea of using an RC circuit). Here is an example of a hardware detection system. One of your gpio pins would be connected to the "power fail signal" wire as input. If it went high the bash script would halt the Pi(I have not personally and be careful not to fry GPIO).

0

My project Nard SDK is the remedy for removed power cord problems. It's designed from ground up for embedded systems and use the SD-card only at boot time. Once up and running the filesystem is never used again, you may even hotplug the SD-card...
http://www.arbetsmyra.dyndns.org/nard/

6
  • Waw, nice project! What typical boot time do you get? I worked hard to get my app start ~ 8 seconds after you plug the power cord (see here), I would like to keep this if I switch to your Nard SDK. Do you use systemd or sysvinit?
    – Basj
    Jun 5, 2015 at 6:52
  • System reliability has a higher priority than boot time in Nard and thus it's not as good as your setup. The default example boots in ~ 25 seconds which is good enough considering the intended targets are always-on. However, Nard is designed so you can easily fine-tune the boot process should you need to. One single shellscript runs linearly from top to bottom at boot forking of all daemons. By replacing the default script with a custom you get almighty powers and can potentially prioritize boot speed instead. As of today only model 1 work unfortunately but support for model 2 B is planed. Jun 5, 2015 at 9:11
  • So you don't use systemd nor sysvinit but a custom-written init system?
    – Basj
    Jun 5, 2015 at 9:21
  • Correct. It's a custom minimalistic init system. Everything in Nard tries to be simple and small in size (or it would consume to much of the RAM). Jun 5, 2015 at 9:26
  • With a little bit of work, what boot time (between when you plug power cord and the time your app starts) can we expect? What do you think is achievable?
    – Basj
    Jun 5, 2015 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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