Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

One in a while my laptop crashes/dies because of a bad/empty battery, crappy wifi driver or whatever other reason.

For a while I've wondered if it's possible to force Linux to periodically save the state (like vmware snapshots) to disk so you can restore from that with possibly slightly outdated work but at least with all of your apps open in the same state you've left them.

I don't really see the point in having to boot everything from cratch constantly, although KDE saves your state on logout, that doesn't happen periodically (by default) either. It would make it much nicer to recover from your crashes if your ram was written to disk periodically.

Anyone know if there's a system call to do this without also shutting down the machine? Even a manual button to save the entire state would be nice.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The hibernation interface is accessible via /dev/snapshot, which is described in Documentation/power/userland-swsusp.txt. You could write a program based on uswsusp's s2disk, for example.

But I am not sure if this can work reliably, since hibernation only stores information kept in RAM, but not the current disk/filesystem state. For example, if you saved a hibernation snapshot, modified a few files and reloaded the snapshot, your disk would contain the new data and metadata, but the snapshot might still have the old version in the snapshotted kernel's memory...

To quote Documentation/power/swsusp.txt:

 * BIG FAT WARNING *********************************************************
 *
 * If you touch anything on disk between suspend and resume...
 *              ...kiss your data goodbye.
 *

If your laptop dies due to an empty battery, configure it to automatically hibernate when reaching 1% or so. (If it happens while the laptop is suspended – try out "suspend to both" mode in Linux 3.6-rc1 and newer.)

If your laptop dies due to a driver bug, REPORT THAT BUG so that it could get fixed.

share|improve this answer
    
Thank's for the reply, I'll see if I can write a little tool to do this. I'm mostly worried about write buffering occuring in some locations, having a filesystem that's out of sync with the RAM should be manageable. As for the laptop dying due to an empty battery, I usually put my laptop in standby but that still drains the battery within 48 hours with a full charge. So once in a while I am too late with charging it again. And the driver bug is a rare thing and not reliably reproducible unfortunately, otherwise I would have debugged it myself :( –  Wolph Sep 6 '12 at 9:21
    
@WoLpH: As long as "should be manageable" doesn't descend to stealthy filesystem corruption... Documentation/power/swsusp.txt actually has a "BIG FAT WARNING" about this. –  grawity Sep 6 '12 at 11:01
    
@WoLpH: Also, regarding the battery thing, Linux 3.6 will have "hybrid suspend", which writes a snapshot but still uses suspend mode -- this sounds like it would be useful in your case. –  grawity Sep 6 '12 at 11:04
    
That indeed would fix half of the problems I have, the crashes are rare so I'm not that worried about that. The big fat warning should be acceptable if it would somehow be possible to freeze the state of the disk while writing this file (perhaps btrfs snapshots?). Cause even with suspend to disk you're not guaranteed that the filesystem never changed (i.e. booting another OS in the meantime). –  Wolph Sep 7 '12 at 13:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.