4

I am using qemu emulator for aarch64 and want to create an outside checkpoint (or fast forwarding) to save all I need to restart the system just from the point when I create checkpoint. (In fact, I want to skip the booting step) I only found something on qemu VM snapshot and fast forwarding, but it does not work for the emulator. Is there any checkpoint function for qemu emulator?

Zhang Jiaqi
  • 41
  • 1
  • 2

2 Answers2

2

A savevm snapshot should do what you want. The short answer is that you need to set up a QCOW2 disk for the snapshots to be saved to, and then in the monitor you can use the 'savevm' command to take the snapshot. Then the command line '-loadvm' option will let you resume from there. This all works fine in emulation of AArch64.

https://translatedcode.wordpress.com/2015/07/06/tricks-for-debugging-qemu-savevm-snapshots/ has a more detailed tutorial.

Peter Maydell
  • 9,707
  • 1
  • 19
  • 25
2

Minimal example

Peter's answer just worked for me, but let me provide a fully reproducible example.

I have fully automated everything at: https://github.com/cirosantilli/linux-kernel-module-cheat/tree/1e0f0b492855219351b0bfa2eec4d3a6811fcaaa#snapshot

The key step is to convert the image to qcow2 as explained at: https://docs.openstack.org/image-guide/convert-images.html

cd buildroot/output.x86_64~/images
qemu-img convert -f raw -O qcow2 rootfs.ext2 rootfs.ext2.qcow2

And the final QEMU command used was:

./buildroot/output.x86_64~/host/usr/bin/qemu-system-x86_64 -m 128M -monitor telnet::45454,server,nowait -netdev user,hostfwd=tcp::45455-:45455,id=net0 -smp 1  -M pc -append 'root=/dev/vda nopat nokaslr norandmaps printk.devkmsg=on printk.time=y console=ttyS0' -device edu -device virtio-net-pci,netdev=net0 -drive file=./buildroot/output.x86_64~/images/rootfs.ext2.qcow2,if=virtio,format=qcow2 -kernel ./buildroot/output.x86_64~/images/bzImage  -nographic

To test it out, login into the VM, and run:

i=0; while true; do echo $i; i=$(($i + 1)); sleep 1; done

Then on another shell, open the monitor:

telnet localhost 45454
savevm my_snap_id

The counting continues. Then, if we load the vm:

loadvm my_snap_id

the counting goes back to where we saved. This shows that CPU and memory states were reverted.

We can also verify that the disk state is also reversed. Guest:

echo 0 >f

Monitor:

savevm my_snap_id

Guest:

echo 1 >f

Monitor:

loadvm my_snap_id

Guest:

cat f

And the output is 0.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • I've converted ubuntu-16.04-server-cloudimg-arm64-uefi1.img using the above command, however, when trying to boot the new qcow2 image it ends up in: UEFI Interactive Shell v2.1 EDK II UEFI v2.50 (EDK II, 0x00010000) Mapping table BLK3: Alias(s): VenHw(F9B94AE2-8BA6-409B-9D56-B9B417F53CB3) BLK0: Alias(s): VenHw(8047DB4B-7E9C-4C0C-8EBC-DFBBAACACE8F) BLK1: Alias(s): VenHw(837DCA9E-E874-4D82-B29A-23FE0E23D1E2,003C000A00000000) BLK2: Alias(s): VenHw(837DCA9E-E874-4D82-B29A-23FE0E23D1E2,003E000A00000000) – hayesti Aug 15 '20 at 18:59
  • @hayesti arghh, so changing ext to qcow2 alone generates problems? I recommend this: 1) as a desperate attempt, try to install EFI as shown at https://superuser.com/questions/942657/how-to-test-arm-ubuntu-under-qemu-the-easiest-way and actually provide it to QEMU (not done there) 2) create a new question and CC Peter :-) – Ciro Santilli OurBigBook.com Aug 16 '20 at 05:20