3

My company sells an "embedded device" which is implemented as a headless Linux box with ext4 on an internal SSD. Some of our users have a habit of doing a "save current settings" on this box, and then cutting power to the unit as soon as the unit reports that the save completed (ie two seconds later). This was causing occasional corruption of the saved files, as the data wouldn't always get flushed to the SSD before the power went out. So I tweaked my software to run /bin/sync immediately after writing the file (after closing the file handle but before notifying the user that the save completed). This appears to fix the issue, but my coworker says that one call to /bin/sync isn't sufficient, and that to be really safe I ought to run /bin/sync twice in a row.

That sounds like paranoia to me... Perhaps a habit from earlier versions of Linux or unix whose sync utility didn't work reliably. Does his advice have merit, or should one call to /bin/sync suffice?

1

1 Answer 1

8

This link sums it up pretty well -- One call to sync should suffice. Doing it more than once is definitely a holdover (and one I stick to myself), but if you're doing it programmatically you aren't gaining anything - it's the delay it takes you to type out those 5 keystrokes that you were really going for.

Of course the real answer is to officially discourage yanking the power, and instead provide a shutdown feature that users are told to use, but you'll always have to deal with plug-yankers...

1
  • +1 for giving the user a way to gracefully shutting down the system within the UI.
    – mrdenny
    Jan 5, 2011 at 23:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .