8

Are there any common or standard ways to make a system more robust against unexpected power loss (I.e., without proper shutdown)? I was using a UPS but the battery is dying and I haven't had a chance to replace it yet.

During the last power loss (when I turned off the UPS to remove it), one of my file systems got thoroughly butchered. It's an ext3 filesystem that was corrupted, and most of my current filesystems are ext3. Are there filesystems that will be more resilient?

Are there any other actions I can take to make the system safer in this regard?

slm
  • 369,824
  • Well, the obvious answer is to find time to replace the battery; even a few minutes runtime on battery will allow a clean shutdown of almost any system. Sudden system shutdowns are always worse than controlled shutdowns, regardless of which file system you're using. – user Aug 14 '13 at 09:43
  • Yes, that's of course the safest way to do it, but in practice I've found that I've had more unexpected power losses with the UPS than without, because when the beeper starts shrieking to tell me that the battery is dying, the only way to silence it is to turn off the output, and I can't stand listening to the beeper long enough to turn on my other computer, connect over SSH, and correctly shutdown the machine. – brianmearns Aug 15 '13 at 02:02
  • You almost certainly don't have more unexpected power losses; if anything, you might have forcefully shut the computer down a few times when without a UPS it would just have died the instant you lost power. If hearing the power outage or replace battery alarm for long enough to shut the computer down properly is a problem, investigate configuring your system so that pressing the power button initiates a clean shutdown -- even if abruptly killing all running processes means you lose any unsaved changes, that's still much better than any unclean shutdown. And of course, replace the battery. – user Aug 15 '13 at 07:18
  • That's a good idea, I will see if I configure it to work that way. As far the power loss, it's just a matter of semantics. From the point of view of the system, if it looses power unexpectedly, it doesn't matter whether it's because of a black out or because I killed the UPS output. My point was that I haven't had any black outs, or even tripped circuits in the entire time I've owned the system, but I have been compelled to cut power without a proper shutdown because of the UPS. – brianmearns Aug 15 '13 at 10:28

2 Answers2

6

I came across this page on the ArchLinux wiki, titled: What is the most error resistant filesystem?. There are a couple of suggestions in this thread:

data=journal

Use ext3 with the data=journal mount option. You can also make it the default with this command:

tune2fs -o journal_data /dev/your_partition

excerpt from tune2fs man page

journal_data
              When  the  filesystem  is mounted with journalling enabled,
              all data (not just metadata) is committed into the journal 
              prior to being written into the main filesystem.

ext3 vs. ext4 disadvantages

Ariel M.
  • 103
slm
  • 369,824
  • And what about the JFS, the Journaled File System? http://en.wikipedia.org/wiki/JFS_%28file_system%29 I post this as a comment and not an answer as I've never actually tried it but its purpose is to make the file system perfectly resilient. – lgeorget Aug 14 '13 at 09:32
  • 1
    @lgeorget From that Wikipedia page, under "Features: Journal": "JFS journals metadata only, which means that metadata will remain consistent but user files may be corrupted after a crash or power loss." Not what the OP is looking for. Metadata journaling is what ext3 does by default, data journaling is the option on ext3 (and is what slm is suggesting). From a quick glance, I don't see anything in that article indicating JFS2 is particularly well-suited to handle sudden power outages. – user Aug 14 '13 at 09:39
  • @MichaelKjörling Ok, thank you for the technical explanation and distinction about metadata and data journaling. – lgeorget Aug 14 '13 at 09:52
  • @MichaelKjörling - thanks for clarifying this! – slm Aug 14 '13 at 14:53
  • 1
    I just took a look at man mount and could not find journal=data option; rather found a data=journal one. Also found data=journal in some related questions: this and this – felipeduque Jul 25 '17 at 14:13
1

You also could consider FreeBSD with zfs as root-fs and of course for data - zfs seems to be really rock solid (copy-on-write) so you might loose the last seconds but the filesystem should always be consistent.

zfsonlinux is maybe still too early.

fgordon
  • 11
  • I think that depends on what you mean by "too early". According to the ZFS On Linux 0.6.1 release announcement, "Over two years of use by real users has convinced us ZoL is ready for wide scale deployment on everything from desktops to super computers." The downside of ZoL is that it'll likely never get quite the same exposure as the file systems included in the kernel, simply because it isn't included in the kernel by virtue of its CDDL license. Still, +1 for ZFS, but remember to scrub thoroughly. – user Aug 14 '13 at 09:47
  • @user, the scrub just checks filesystem (meta)data checksums. If you trust your disk, it is not needed (but recommended). – jiwopene Feb 21 '21 at 13:12