2

Since a fresh booting of the guest OS is very slow, or it is laborious to arrive at a particular machine state, what I want is something like Windows' hibernation: Qemu saves the current state of the guest to the hard drive, and restores directly back into this state in the future without a fresh booting.

I think Qemu should have this function. I had thought the Qemu monitor has this function, but I did not find it. I searched google but all the solutions are nearly 10 years ago which is medieval in computer industry. So I ask this question here again: how to make a snapshot while qemu is running, assuming every software involved is latest in 2021?

1

1 Answer 1

3

You can take an internal snapshot by using the HMP command:

(qemu) savevm your_snapshot_1

QEMU will create snapshots on all disks with the same name your_snapshot_1, and also save the CPU and memory states to the first writable qcow2 disk. Your virtual machine will freeze for a while during that time. Thus it is not wise to use such function on a production server.

To restore the snapshot, use the HMP command:

(qemu) loadvm your_snapshot_1

External snapshotting when the VM is still running is not mentioned anywhere in QEMU documentations. It seems external snapshots belong to qemu-img instead. Maybe you can do that with libvirt or virsh -- I only use pure QEMU so I can't give you answers for these wrapper programs.

8
  • Thanks, and +1. Could you please shortly explain how you get at that qemu prompt ((qemu) in your examples)? That is, if I have started some VMs using the qemu command with appropriate parameters, and if I am now at a bash prompt, what commands exactly do I need to issue to get to the (qemu) prompt where I can give the savevm and loadvm commands? Like you, I don't use virsh or libvirt for certain reasons ...
    – Binarus
    Commented Apr 7, 2023 at 17:08
  • 1
    @Binarus, you can create a monitoring socket and connect to it via socat or similar, to send these commands (more elaborate answer: superuser.com/a/1785127/912095 )
    – nyov
    Commented May 21, 2023 at 1:39
  • 1
    @nyov I think you are confused between HMP (Human Monitor Protocol?) and QMP (QEMU Monitor Protocol). The QMP socket is to interact with the virtual machine using JSON command. @Binarus We are using standard human command, so to add it: -chardev stdio,id="chardev-stdio",mux=on,signal=off -mon "chardev-stdio",mode=readline. It is a little complicated to explain why there are so many options and what each of them does. Try to study each of them in the QEMU PDF manual first. At least now you have the hint. :)
    – Livy
    Commented May 22, 2023 at 10:31
  • 1
    @Binarus Learning QEMU command line interface (CLI) is a long and painful path. Not many people choose that path, and you won't get a lot of answers about QEMU CLI on StackExchange -- I've tried that when I started learning QEMU.
    – Livy
    Commented May 27, 2023 at 5:54
  • 1
    @nyov No, HMP commands are not legacy. They are meant to be used by human to interact with virtual machines using a command line interface. QMP commands are designed to be used by other programs (or scripts) to interact with virtual machines via sockets.
    – Livy
    Commented May 31, 2023 at 14:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .