1

I can hibernate my laptop via pm-hibernate command without any problems. I want to achieve the same results manually. For this to work,

  1. I need to take a snapshot and dump the contents of RAM+swap into a file (or /dev/myswap2), like:

    dd if=/dev/fmem of=path/to/memory.img
    
  2. Resume from that file on the next boot, possibly by setting resume=path/to/memory.img option within GRUB.

How can I take a snapshot of RAM and Swap in order to dump them into a file (or block device) for hibernation purposes?

Intention

I can

  • take a snapshot of my whole filesystem while the system is running
  • send the snapshots to a target disk
  • replace necessary files (like /etc/fstab, /etc/crypttab, /boot/grub/grub.cfg etc.) to make the target bootable

So, when I unplug my USB disk, it's ready to boot my (or similar) computer, which cuts the MTTR down to ~10 minutes in case of a disk failure. (~1 minute to boot and ~9 minutes to reopen my applications, rearrange the windows, etc. after login.)

My intention is that if I could take a snapshot of my RAM in the same way the pm-hibernate does and write it to the target disk's swap area, then I could boot into the exact same state of backup moment (as if my target disk is hibernated) in such a disk failure scenario.

1

You can transition by writing into /sys/power/state one of sleep states contained inside, es.

echo disk > /sys/power/state

Available states are:

  • freeze (Suspend-to-Idle)
  • standby (Power-On Suspend)
  • mem (Suspend-to-RAM)
  • disk (Suspend-to-Disk)

/sys/power/disk controls the operating mode of hibernation (Suspend-to-Disk).

Available options are:

  • `platform' (put the system into sleep using a platform-provided method)
  • shutdown (shut the system down)
  • reboot (reboot the system)
  • suspend (trigger a Suspend-to-RAM transition)
  • test_resume (resume-after-hibernation test mode)

References

Linux kernel documentation

2
  • Writing to /sys/power/state will trigger an actual hibernate, is that correct? If so, I don't want to hibernate my computer during a backup operation, I only want to "simulate" it.
    – ceremcem
    Jan 5 at 14:07
  • Try check ACPI code. From the reference: "the 'platform' option is only available if the platform provides a special mechanism to put the system to sleep after creating a hibernation image (ACPI does that, for example)." Jan 5 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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