22
1
I am developing an application on a Linux embedded board (runs Debian) e.g. Raspberry Pi, Beagle Board/Bone, or olimex. The boards works on an environment that the electricity is cut unexpectedly (it is far complicated to place PSU, etc.) and it would happen every day couple times. I wonder if the unexpected power cuts would cause crash/problem on the Linux Operation System? If it is something that I should worry, what would you suggest to prevent the damages on OS against the unexpected power cuts?
PS. The application needs to writes some data to the storage medium (SD card), I think it would not be suitable to mount it as read-only.
1Stay away from ext2 (use ext3 or higher) on filesystems you modify a lot, and you should be OK for the most part. – LawrenceC – 2013-06-25T16:14:12.597
Unless you are very careful in spec'ing your SD cards, the cards do not guarantee anything if you cut power unexpectedly. The card could be in the middle of a wear-leveling move, leading to weird, unexpected corruption—which could even be in a different partition! – derobert – 2013-06-26T20:25:41.657
I don't know exactly how to do it, but you may want to consider making your key applications transaction based. That way, you can have your current file and a backup. You apply the transactions to your current file and if that fails, you can restore the current file from the backup and reapply the transactions. If you switch between current and backup using symlinks or swapping file names, then that can happen very quickly with much less chance of error than with copying. After a successful update, your current file becomes your backup and the backup becomes the current. – Joe – 2013-07-01T21:07:18.500
Continued. This almost works. The new current file would also need the transactions applied to it necessitating processing the transactions twice, so I'm sure there's a better way. In any case, it may still be a lot faster and safer than copying the whole file if it's big. – Joe – 2013-07-01T21:14:35.410