Can I take a snapshot of a physical machine and revert to that stage every time the machine boots?

This can be done with virtual machines, but I want to do it for a physical machine.


I have an old laptop that powers off randomly. The disk is fine and the RAM is fine, so it is some other problems. I would like to use this for very basic surf+video watching. I can live with the random power off, but it takes too long to boot it and open the relevant applications. If, however, it could simply boot into the same snapshot every time, it would be fine.

Given that you can suspend to disk and that you can make snapshots of file systems, I am thinking that this might be doable - and maybe someone has already done this.

Idea 1

A system that is suspended-to-disk is in the perfect condition for this to work. So all we need to do is to make sure the disk is reverted back to this state before next boot.

This might be doable by first booting a minimal GNU/Linux system that sets this up and which then execs a new kernel booting on the reverted disk.

Imagine this setup:

  • /dev/sda - minimal boot system
  • /dev/sdb - swapspace with suspended RAM/CPU image + filesystem
  • /dev/sdc - device for overlay

When the system boots on /dev/sda, then /dev/sdc is used as a new overlay device on top of /dev/sdb giving /dev/overlay (similar to: https://raid.wiki.kernel.org/index.php/Recovering_a_damaged_RAID). After this is setup, the kernel is exec'ed using kexec to boot on /dev/overlay.

Now the question is whether kexec will accept an overlayed device as boot device.

Idea 2

When booting run:

 swapon /dev/sda2
 swapoff /dev/sda1
 dd if=/dev/sda3 /dev/sda1
 (where /dev/sda3 is a copy of the suspend-to-disk image.)

and use /dev/sda1 as suspend-to-disk device in grub.

Mount /dev/sdb1 on / readonly, then add /dev/sdc overlay to /dev/sdb and mount /dev/overlay as / read-write.

Idea 3

  • /dev/sda - /boot with initrd
  • /dev/sdb - swapspace with suspended RAM/CPU image + filesystem
  • /dev/sdc - device for overlay

In initrd setup /dev/overlay. Swap on /dev/overlay1, filesystem on /dev/overlay2, /dev/overlay3. Then do this to read back the suspended image:

echo /dev/overlay1 > /sys/power/resume

If you want to "record" a state, merge /dev/overlay onto /dev/sdb and:

echo disk > /sys/power/state

Instead of /dev/sd* we should probably use LVM: https://www.kernel.org/doc/Documentation/device-mapper/snapshot.txt

  • I don't believe this is easily doable, but I'm intrigued if any one else knows how to do this. Upvoted! – xrobau Jul 25 '17 at 14:01
  • Two ideas: Overlay filesystem (changes are not written do disk), or filesystems that support snapshots (like ZFS or btrfs) - but that may be not available at "old laptop". – ridgy Jul 25 '17 at 21:35
  • dmsetup snapshot can also be used for the file-system. So the filesystem is probably the easy part. How can the suspend-to-disk of the RAM be reused? – Ole Tange Jul 25 '17 at 22:26

Your Answer

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

Browse other questions tagged or ask your own question.