quickemu-project / quickemu

Quickly create and run optimised Windows, macOS and Linux virtual machines
MIT License
9.84k stars 433 forks source link

feat: Saving and restoring VMs #1261

Open alexpaniman opened 1 month ago

alexpaniman commented 1 month ago

I'm trying to save state of a MacOS Sonoma VM like so:

  1. I launch a VM

    quickemu --vm macos-sonoma.conf
  2. And then connect to qemu monitor socket and use savevm:

    nc -U "macos-sonoma/macos-sonoma-monitor.socket"
    (qemu) savevm empty

Which gives me:

Error: Device 'pflash1' is writable but does not support snapshots

As I understand, this is caused by unit=1 drive for EFI_VARS, which uses pflash that doesn't support snapshots, relevant piece of code from generated by quickemu macos-sonoma/macos-sonoma.sh:

-drive if=pflash,format=raw,unit=0,file=macos-sonoma/OVMF_CODE.fd,readonly=on \
-drive if=pflash,format=raw,unit=1,file=macos-sonoma/OVMF_VARS-1920x1080.fd \

As far as I know, this can be solved by either (1) making OVMF_VARS-1920x1080.fd read only or (2) switching image type to .cow2 (which I'm not sure is possible, I mean, why does it use pflash to begin with?)

I tried option (1) — the issue goes away when I add readonly=on, I can save and restore VM after that without any problem:

-drive if=pflash,format=raw,unit=1,file=macos-sonoma/OVMF_VARS-1920x1080.fd,readonly=on

It's probably not a great default option, since it makes changing EFI vars from within a VM impossible, but can there be made a switch to make it read only when I've already set up EFI vars the way I want, let's say an option in config, like mount_efi_vars_readonly or something?

If so, it seems like a very simple patch, I'd be happy to write a PR.

lj3954 commented 4 weeks ago

1269 - Windows VMs additionally cannot be saved due to the CPU flag.