
QEMU for MSYS2/Windows
======================

Path processing
-----

QEMU - if installed to MINGW64 subsystem for example - can be run using the
MINGW64 shell natively. Because of the shell's automatic path conversion to
Windows paths the usage is transparent. QEMU itself doesn't understand
MSYS2-paths. This is the reason why the following command is valid:

```
$ qemu-img create -f qcow2 /tmp/test.qcow2 1G
```

QEMU is native Windows software, but relies on its subsystem's libraries. QEMU
can also be run by an alternative CLI. Cygwin was successfully tested:

```
$ export PATH="/cygdrive/<MSYS2_INST_DIR>/mingw64/bin:$PATH"
$ qemu-img create -f qcow2 $(cygpath -w -m /tmp/test.qcow2) 1G
```

Hardware acceleration
---------------------

Enable WHPX (Windows Hypervisor Platform).
See https://learn.microsoft.com/en-us/dotnet/maui/android/emulator/hardware-acceleration?view=net-maui-10.0#enable-hyper-v-acceleration-in-windows


Tests and examples
------------------

msys2.examples.tests.sh contains several demo use and test cases which can be
executed easily in MINGW64 shell:

```
$ /mingw64/share/doc/qemu/msys2.examples.tests.sh
```

Most demo use cases are VMs taken from QEMU Advent Calendar
https://www.qemu-advent-calendar.org/
which were adjusted to run on MSYS2/Windows as well as on Linux.

Desktop use cases were integrated to show different options how to run a Linux
desktop using SPICE, SDL, GTK and VNC.

All demo use cases can be used to perform a regression test on MSYS2, too:
The script supports comparing two specified versions of qemu by executing the
use cases with both versions consecutively

Hints
-----

* Starting Linux kernel images via QEMU command line

  Absolute paths are converted to windows paths in MINGW64 shell automatically
  and therefore get invalid occasionally, which can be mitigated:

    ```
    $ export MSYS2_ARG_CONV_EXCL='*'
    $ qemu-system-x86_64 -append root=/dev/hda
    $ unset MSYS2_ARG_CONV_EXCL
    ```

  Make sure you do not use any further (absolute) paths in the command, which
  need to be converted

* To use UEFI firmware, either use the delivered files with "-drive if=pflash"
    ```
    $ cp /mingw64/share/qemu/edk2-i386-vars.fd ./ # will be modified
    $ qemu-system-x86_64 -accel whpx \
        -drive file=/mingw64/share/qemu/edk2-x86_64-code.fd,if=pflash,format=raw \
        -drive file=edk2-i386-vars.fd,if=pflash,format=raw
    ```
  or concatenate it and use it with "-bios"

    ```
    $ cat /mingw64/share/qemu/edk2-i386-vars.fd \
        /mingw64/share/qemu/edk2-x86_64-code.fd > edk2-x86_64.fd
    $ qemu-system-x86_64 -accel whpx -bios edk2-x86_64.fd
    ```

