A recent shutdown of my Linux computer caused some serious problems. First, the operating system couldn’t find any files or directories. Second, it caused my computer to crash. Third, the programs that I use most often didn’t work at all. Finally, my internet connection was completely lost. These shutdowns are a common occurrence on Linux computers and can be very harmful.


Are unexpected shutdowns as harmful to Linux as they are to other operating systems? Read on as we investigate the effects of catastrophic system shutdowns on Linux file systems.

Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.

The Question

SuperUser reader User208554 is curious about Linux file structures and concerned about an app/installation he’s working on:

So what’s the verdict?

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.

The Answer

SuperUser contributor l0b0 offers some insight into journaling/non-journaling file systems:

Stu suggests separating the operating system and data, as well as adding a battery backup:

whether you’re using a journaling file system and how well the applications are able to handle aborted processing.

Consider for example an application which processes a file and writes the results as they are computed (one output line per input line) to another file. If the power is cut during processing, and the same application is run after restarting, it can’t just restart processing from the start of the input file – that would mean the output file would contain duplicate information.

It could be very difficult to say anything definite about a hypothetical complex system, but most stable Linux software seems to be able to handle crashes quite nicely.

Finally, Jenny D expands on the journaling file system suggestion:

Additionally, most of those boards have very low power requirements, so a battery backup is possible. The “LiPo rider” board for the Raspberry Pi can be used as a basic UPS to provide a clean shutdown on power loss.

Have something to add to the explanation? Sound off in the the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.

As l0b0 wrote, using a journaling file system will help, since it will be able to keep track of what has actually gotten done. In addition to the wikipedia info that l0b0 linked, you may be interested in Do Journaling Filesystems Guarantee Against Corruption After a Power Failure as well.

You as a programmer obviously need to consider carefully how to handle writing to files so that it becomes an atomic process (i.e. it’s either fully done or not done at all, but never ever half done). It’s a fairly complex issue.