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?

Ghanima
  • 15,958
  • 17
  • 65
  • 125
Basj
  • 800
  • 3
  • 21
  • 49

4 Answers4

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.

Ghanima
  • 15,958
  • 17
  • 65
  • 125
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.

Milliways
  • 62,573
  • 32
  • 113
  • 225
1

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/

Ronny Nilsson
  • 878
  • 5
  • 13
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).

NULL
  • 2,240
  • 8
  • 28
  • 49