Search code examples
qemusnapshotcheckpoint

QEMU snapshot without an image?


I'm working with VxWorks, a Real Time Operating System for embedded systems. They recently added QEMU support, and I've been trying to figure it out. (I'm fairly new to all these technologies.) I would like to checkpoint and restart the virtual machine, ie save the RAM and processor state and reload it later from exactly that point.

QEMU has some support for this called "snapshots." However, everything I've seen and tried requires a disk image in qcow2 format. But my simulation has no disk, the program is loaded directly into RAM and run.

Here's my QEMU command:

qemu-system-aarch64 -m 4096M -smp 4 -machnie xlnx-zcu102 -device loader,file=~/vxworks_21.03/workspace3/QEMU_helloWorld/default/vxWorks,addr=0x00100000  -nographic  -monitor telnet:127.0.0.1:35163,server,nowait  -serial telnet:127.0.0.1:39251,server  -device loader,file=~/vxworks_21.03/workspace3/vip_xlnx_zynqmp_smp_64/default/xlnx-zcu102-rev-1.1.dtb,addr=0x0f000000 -device loader,addr=0x000ffffc,data=0xd2a1e000,data-len=4 -device loader,addr=0x000ffffc,cpu-num=0   -nic user -nic user -nic user -nic user,id=n0,hostfwd=tcp:127.0.0.1:0-:1534,hostfwd=udp:127.0.0.1:0-:17185

Then I log into the monitor and:

$ telnet 127.0.0.1 35163
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
QEMU 5.2.0 monitor - type 'help' for more information
(qemu) savevm
Error: No block device can accept snapshots

I tried a number of things, like creating an empty disk image, or the snapshot_blkdev command, but no luck so far.

The host is RedHat Linux 8.4 running on an x86 desktop, the guest is ARM64.


Solution

  • It turns out that a disk image is required to do snapshots, but you don't have to hook it up to the guest. To do that you pass qemu -drive argument with with if=none. Like this:

    -drive if=none,format=qcow2,file=dummy.qcow2
    

    So here is the whole sequence that worked:

    $ qemu-img create -f qcow2 dummy.qcow2 32M
    $ qemu-system-aarch64 -m 4096M -smp 4 -machnie xlnx-zcu102 -device loader,file=vxWorks,addr=0x00100000  -nographic  -monitor telnet:127.0.0.1:35163,server,nowait  -serial telnet:127.0.0.1:39251,server  -device loader,file=xlnx-zcu102-rev-1.1.dtb,addr=0x0f000000 -device loader,addr=0x000ffffc,data=0xd2a1e000,data-len=4 -device loader,addr=0x000ffffc,cpu-num=0   -nic user -nic user -nic user -nic user,id=n0,hostfwd=tcp:127.0.0.1:0-:1534,hostfwd=udp:127.0.0.1:0-:17185 -snapshot -drive if=none,format=qcow2,file=dummy.qcow2
    

    Then in the monitor terminal savevm and loadvm work:

    $ telnet 127.0.0.1 35163
    Trying 127.0.0.1...
    Connected to 127.0.0.1.
    Escape character is '^]'.
    QEMU 5.2.0 monitor - type 'help' for more information
    (qemu) savevm save1
    (qemu) info snapshots
    List of snapshots present on all disks:
    ID        TAG               VM SIZE                DATE     VM CLOCK     ICOUNT
    --        save1             44.3 MiB 2021-06-28 10:08:28 00:00:05.952
    (qemu) loadvm save1
    

    This information came thanks to Peter Maydell and his blog post: https://translatedcode.wordpress.com/2015/07/06/tricks-for-debugging-qemu-savevm-snapshots/