Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #26810

Re: Linux embedded: how to avoid corruption on power off

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.arch.embedded
Subject Re: Linux embedded: how to avoid corruption on power off
Date 2017-06-16 13:31 +0200
Organization A noiseless patient Spider
Message-ID <oi0fce$4hu$1@dont-email.me> (permalink)
References <oi0ajn$kae$1@dont-email.me>

Show all headers | View raw


On 16/06/17 12:10, pozz wrote:
> I'm playing with a Raspberry system, however I think my question is
> about Linux embedded in general.
> 
> We all know that the OS (linux or windows or whatever) *should* be
> gracefully powered down with a shutdown procedure (shutdown command in
> Linux). We must avoid cutting the power abruptly.
> 
> If this is possible for desktop systems, IMHO it's impossible to achieve
> in embedded systems.  The user usually switch off a small box by
> pressing an OFF button that usually is connected to the main power
> supply input.  In any case, he could immediately unplug the power cord
> without waiting for the end of the shutdown procedure.
> 
> I'm interesting to know what are the methods to use to reduce the
> probability of corruption.
> 
> For example, I choose to use a sqlite database to save non-volatile user
> configurable settings. sqlite is transaction based, so a power
> interruption in the middle of a transaction shouldn't corrupt the entire
> database. With normal text files this should be more difficult.
> 
> I know the write requests on non-volatile memories (HDD, embedded Flash
> memories) are usually buffered by OS and we don't know when they will be
> really executed by the kernel. Is there a method to force the buffered
> writing requests immediately?
> 
> Other aspects to consider?

Some storage mediums, such as sd cards, are very sensitive to being
corrupted if they are powered off unexpectedly.  There just is no way to
make an sd card storage reliable in the face of unexpected power offs.

In general, using read-only mounts helps enormously.  In finer detail,
some filesystems are more robust for unexpected poweroffs, such as
LogFS, NILFS and FFS.  And some file types are more susceptible to
problems - sqlite databases are notorious for being corrupted if writes
are interrupted.

The only way to be really safe is to have enough capacitance on board to
be able to finish your writes when the supply is cut off.  Keep your
writes short, use kernel parameter tuning (or filesystem mount options)
to minimise the dirty data buffer time, and make sure that as much as
possible is mounted read-only with things like /tmp, /var/lock, etc., on
tmpfs mounts.  And when a power fail occurs, re-mount your r/w
filesystems as read only - that should force writing out buffers as fast
as possible, and block any more writes, and can be perhaps be done early
in the controlled shutdown (if you don't need to write too much log data
on shutdown).

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Linux embedded: how to avoid corruption on power off pozz <pozzugno@gmail.com> - 2017-06-16 12:10 +0200
  Re: Linux embedded: how to avoid corruption on power off Reinhardt Behm <rbehm@hushmail.com> - 2017-06-16 18:45 +0800
    Re: Linux embedded: how to avoid corruption on power off pozz <pozzugno@gmail.com> - 2017-06-16 13:19 +0200
      Re: Linux embedded: how to avoid corruption on power off Reinhardt Behm <rbehm@hushmail.com> - 2017-06-16 21:42 +0800
  Re: Linux embedded: how to avoid corruption on power off Jack <jack4747@gmail.com> - 2017-06-16 04:13 -0700
    Re: Linux embedded: how to avoid corruption on power off upsidedown@downunder.com - 2017-06-16 15:38 +0300
      Re: Linux embedded: how to avoid corruption on power off John Speth <johnspeth@yahoo.com> - 2017-06-16 11:24 -0700
        Re: Linux embedded: how to avoid corruption on power off Don Y <blockedofcourse@foo.invalid> - 2017-06-16 11:39 -0700
        Re: Linux embedded: how to avoid corruption on power off upsidedown@downunder.com - 2017-06-17 17:35 +0300
          Re: Linux embedded: how to avoid corruption on power off lasselangwadtchristensen@gmail.com - 2017-06-18 11:47 -0700
  Re: Linux embedded: how to avoid corruption on power off David Brown <david.brown@hesbynett.no> - 2017-06-16 13:31 +0200
    Re: Linux embedded: how to avoid corruption on power off Reinhardt Behm <rbehm@hushmail.com> - 2017-06-16 21:52 +0800
    Re: Linux embedded: how to avoid corruption on power off pozz <pozzugno@gmail.com> - 2017-06-19 12:47 +0200
      Re: Linux embedded: how to avoid corruption on power off Jack <jack4747@gmail.com> - 2017-06-19 04:27 -0700
        Re: Linux embedded: how to avoid corruption on power off pozz <pozzugno@gmail.com> - 2017-06-20 10:51 +0200
      Re: Linux embedded: how to avoid corruption on power off David Brown <david.brown@hesbynett.no> - 2017-06-19 13:41 +0200
      Re: Linux embedded: how to avoid corruption on power off George Neuner <gneuner2@comcast.net> - 2017-06-19 22:40 -0400
  Re: Linux embedded: how to avoid corruption on power off Don Y <blockedofcourse@foo.invalid> - 2017-06-16 11:26 -0700
    Re: Linux embedded: how to avoid corruption on power off George Neuner <gneuner2@comcast.net> - 2017-06-17 01:33 -0400
      Re: Linux embedded: how to avoid corruption on power off Don Y <blockedofcourse@foo.invalid> - 2017-06-16 23:40 -0700
        Re: Linux embedded: how to avoid corruption on power off George Neuner <gneuner2@comcast.net> - 2017-06-19 21:42 -0400
          Re: Linux embedded: how to avoid corruption on power off Don Y <blockedofcourse@foo.invalid> - 2017-06-19 20:36 -0700
            Re: Linux embedded: how to avoid corruption on power off Don Y <blockedofcourse@foo.invalid> - 2017-06-19 20:47 -0700
          Re: Linux embedded: how to avoid corruption on power off Ed Prochak <edprochak@gmail.com> - 2017-06-20 15:53 -0700
  Re: Linux embedded: how to avoid corruption on power off Joe Chisolm <jchisolm6@earthlink.net> - 2017-06-16 13:30 -0500
  Re: Linux embedded: how to avoid corruption on power off Krzysztof Kajstura <supportDELETETHIS@NOSPAMkristech.eu> - 2017-06-20 09:34 +0200
    Re: Linux embedded: how to avoid corruption on power off pozz <pozzugno@gmail.com> - 2017-06-21 08:57 +0200
      Re: Linux embedded: how to avoid corruption on power off Krzysztof Kajstura <supportDELETETHIS@NOSPAMkristech.eu> - 2017-06-21 13:40 +0200
  Re: Linux embedded: how to avoid corruption on power off Anders.Montonen@kapsi.spam.stop.fi.invalid - 2017-06-22 05:41 +0000

csiph-web