QEMU command in Win v.s. macOS host

Anything about Mac emulation that does not belong in the above categories.

Moderators: Cat_7, Ronald P. Regensburg

Post Reply
User avatar
mabam
Master Emulator
Posts: 498
Joined: Wed Apr 10, 2013 9:32 am

QEMU command in Win v.s. macOS host

Post by mabam »

This is not actually about emulation, but about virtualisation. However, it shouldn't make a difference for this matter.

I have the following command line successfully starting QEMU and booting the VM on a macOS x86_64 host:

Code: Select all

#!/bin/bash
cd "$(dirname "$0")"

port=45002

qemu-system-x86_64 \
-L /usr/local/share/qemu \
-nodefaults \
-vga none \
-device e1000,mac=0A:AD:47:06:D2:2C,netdev=net0 \
-netdev user,id=net0 \
-device vmware-svga \
-cpu Penryn,+sse4.1,+sse4.2,+ssse3 \
-smp cpus=1,sockets=1,cores=1,threads=1 \
-machine q35,vmport=off,i8042=off,hpet=off \
-accel hvf \
-global ICH9-LPC.disable_s3=1 \
-drive if=pflash,format=raw,unit=0,file.filename=/usr/local/share/qemu/edk2-x86_64-code.fd,file.locking=off,readonly=on \
-drive "if=pflash,unit=1,file=./Drives/efi_vars.fd" \
-m 4096 \
-usb \
-device usb-tablet,bus=usb-bus.0 \
-device usb-mouse,bus=usb-bus.0 \
-device usb-kbd,bus=usb-bus.0 \
-device nec-usb-xhci,id=usb-controller-0 \
-device ide-hd,bus=ide.0,drive=EFI,bootindex=0 \
-drive "if=none,media=disk,id=EFI,file=./Drives/efi.qcow2,discard=unmap,detect-zeroes=unmap" \
-device ide-hd,bus=ide.1,drive=SLHD,bootindex=1 \
-drive "if=none,media=disk,id=SLHD,file=./Drives/Snow Leopard.qcow2,discard=unmap,detect-zeroes=unmap" \
-name "- Snow Leopard - Port $port" \
-monitor tcp:localhost:$port,server,nowait \
-uuid AE26E2AD-E73B-482E-BD6B-AD01BAA3BFFC \
-device virtio-rng-pci

Now I've installed QEMU on a Windows host and copied the folder with the QEMU command and a subfolder "Drives" with "Snow Leopard.qcow2", "efi.qcow2", and "efi_vars.fd" in it onto the Windows machine. I've amended the QEMU command as follows to hopefully meet the required syntax and different paths on the Windows host:

Code: Select all

"C:\Program Files\qemu\qemu-system-x86_64.exe" ^
-L "C:\Program Files\qemu\share" ^
-nodefaults ^
-vga none ^
-device e1000,mac=0A:AD:47:06:D2:2C,netdev=net0 ^
-netdev user,id=net0 ^
-device vmware-svga ^
-cpu Penryn,+sse4.1,+sse4.2,+ssse3 ^
-smp cpus=1,sockets=1,cores=1,threads=1 ^
-machine q35,vmport=off,i8042=off,hpet=off ^
-accel whpx ^
-global ICH9-LPC.disable_s3=1 ^
-drive if=pflash,format=raw,unit=0,file.filename="C:\Program Files\qemu\share\edk2-x86_64-code.fd",file.locking=off,readonly=on ^
-drive "if=pflash,unit=1,file=C:\Users\boe\Documents\mabam\Drives\efi_vars.fd" ^
-m 4096 ^
-usb ^
-device usb-tablet,bus=usb-bus.0 ^
-device usb-mouse,bus=usb-bus.0 ^
-device usb-kbd,bus=usb-bus.0 ^
-device nec-usb-xhci,id=usb-controller-0 ^
-device ide-hd,bus=ide.0,drive=EFI,bootindex=0 ^
-drive "if=none,media=disk,id=EFI,file=C:\Users\boe\Documents\mabam\Drives\efi.qcow2,discard=unmap,detect-zeroes=unmap" ^
-device ide-hd,bus=ide.1,drive=SLHD,bootindex=1 ^
-drive "if=none,media=disk,id=SLHD,file=C:\Users\boe\Documents\mabam\Drives\Snow Leopard.qcow2,discard=unmap,detect-zeroes=unmap" ^
-name "- Snow Leopard - Port 45002" ^
-monitor tcp:localhost:45002,server,nowait ^
-uuid AE26E2AD-E73B-482E-BD6B-AD01BAA3BFFC ^
-device virtio-rng-pci
However, when starting the .bat file, a shell window opens for a split second and nothing more seems to happen.

I'm sure something is wrong with the command in my .bat file. But I'm not very familar with Windows systems so I'd appreciate any help on this.
User avatar
Cat_7
Expert User
Posts: 6176
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: QEMU command in Win v.s. macOS host

Post by Cat_7 »

I wouldn't know what might be wrong in that command line.
However, if you first start a command window and then execute the bat file from the command prompt, qemu will tell you what's wrong.

Best,
Cat_7
User avatar
mabam
Master Emulator
Posts: 498
Joined: Wed Apr 10, 2013 9:32 am

Re: QEMU command in Win v.s. macOS host

Post by mabam »

Thanks to your tip to execute the bat file from a command window, I got an error message saying:

Code: Select all

qemu-system-x86_64: WHPX: No accelerator found, hr=00000000
qemu-system-x86_64: failed to initialize whpx: No space left on device
I could fix that by activating the windows features "VM platform" and "Windows Hypervisor Platform".

However, there are new errors popping up now:

Code: Select all

(qemu:5008): Gtk-WARNING **: 10:09:49.583: Could not load a pixbuf from icon theme.
This may indicate that pixbuf loaders or the mime database could not be found.
qemu: WHPX: Failed to emulate MMIO access with EmulatorReturnStatus: 2
qemu: WHPX: Failed to exec a virtual processor
I can probably ignore the GTK warning. But googling didn't bring up a solution for the WHPX errors. Are there any suggestions?

:oops: Seems I was wrong with this:
mabam wrote: Mon Nov 13, 2023 9:48 pm This is not actually about emulation, but about virtualisation. However, it shouldn't make a difference for this matter.
User avatar
Cat_7
Expert User
Posts: 6176
Joined: Fri Feb 13, 2004 8:59 am
Location: Sittard, The Netherlands

Re: QEMU command in Win v.s. macOS host

Post by Cat_7 »

The gtk warning seems to be about missing window decorations.
Does qemu run when you remove the -accel whpx ^

Best,
Cat_7
User avatar
mabam
Master Emulator
Posts: 498
Joined: Wed Apr 10, 2013 9:32 am

Re: QEMU command in Win v.s. macOS host

Post by mabam »

Yeah, it's just slow.
User avatar
adespoton
Forum All-Star
Posts: 4285
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: QEMU command in Win v.s. macOS host

Post by adespoton »

mabam wrote: Tue Nov 14, 2023 3:07 pm Yeah, it's just slow.
Are you able to run a similar image using the built-in Hyper-V? https://techcommunity.microsoft.com/t5/ ... -p/3745905

It seems like something may still be disabled that the hypervisor requires.
User avatar
mabam
Master Emulator
Posts: 498
Joined: Wed Apr 10, 2013 9:32 am

Re: QEMU command in Win v.s. macOS host

Post by mabam »

That link looks promising, thank you!

I’ll follow-up in the end of next week, which is when I’ll be back at the windows machine.
User avatar
mabam
Master Emulator
Posts: 498
Joined: Wed Apr 10, 2013 9:32 am

Re: QEMU command in Win v.s. macOS host

Post by mabam »

It took a bit longer but I've just set up an Ubuntu 20.04 LTS instance in Hyper-V. It boots succesfully.

But for WHPX acceleration of my QEMU VM, does anyone have an idea how to look further for the source of these errors:

Code: Select all

qemu: WHPX: Failed to emulate MMIO access with EmulatorReturnStatus: 2
qemu: WHPX: Failed to exec a virtual processor
User avatar
adespoton
Forum All-Star
Posts: 4285
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: QEMU command in Win v.s. macOS host

Post by adespoton »

mabam wrote: Sun Dec 03, 2023 3:19 pm It took a bit longer but I've just set up an Ubuntu 20.04 LTS instance in Hyper-V. It boots succesfully.

But for WHPX acceleration of my QEMU VM, does anyone have an idea how to look further for the source of these errors:

Code: Select all

qemu: WHPX: Failed to emulate MMIO access with EmulatorReturnStatus: 2
qemu: WHPX: Failed to exec a virtual processor

I don't, but that seems to suggest that WHPX still doesn't have all the permissions it needs; something's blocking the MMIO passthrough, with that something likely being a security configuration on the host.
User avatar
mabam
Master Emulator
Posts: 498
Joined: Wed Apr 10, 2013 9:32 am

Re: QEMU command in Win v.s. macOS host

Post by mabam »

Giving this another shot, I found this thread:
https://www.reddit.com/r/VFIO/comments/ ... t/h0bdxib/

The comment there says:
The last QEMU Windows build which works with WHPX is (qemu-w64-setup-20210208.exe). After that version I found that it breaks starting with (qemu-w64-setup-20210407.exe).

See the history on the [QEMU Binaries for Windows (64 bit)] page for more info.

I reverted to qemu-w64-setup-20210208.exe (which is QEMU 5.2) on the Windows machine to see whether that would fix it (though another comment in the above mentioned thread says that it’s very slow).
QEMU 5.2 has a slightly different syntax (due to different quoting and folder structure), so my .bat file now says (amended lines prepended by “•”):

Code: Select all

"C:\Program Files\qemu\qemu-system-x86_64.exe" ^
• -L "C:\Program Files\qemu" ^
-nodefaults ^
-vga none ^
-device e1000,mac=0A:AD:47:06:D2:2C,netdev=net0 ^
-netdev user,id=net0 ^
-device vmware-svga ^
-cpu Penryn,+sse4.1,+sse4.2,+ssse3 ^
-smp cpus=1,sockets=1,cores=1,threads=1 ^
-machine q35,vmport=off,i8042=off,hpet=off ^
-accel whpx ^
-global ICH9-LPC.disable_s3=1 ^
• -drive "if=pflash,format=raw,unit=0,file.filename=C:\Program Files\qemu\share\edk2-x86_64-code.fd,file.locking=off,readonly=on" ^
-drive "if=pflash,unit=1,file=C:\Users\boe\Documents\mabam\Drives\efi_vars.fd" ^
-m 4096 ^
-usb ^
-device usb-tablet,bus=usb-bus.0 ^
-device usb-mouse,bus=usb-bus.0 ^
-device usb-kbd,bus=usb-bus.0 ^
-device nec-usb-xhci,id=usb-controller-0 ^
-device ide-hd,bus=ide.0,drive=EFI,bootindex=0 ^
-drive "if=none,media=disk,id=EFI,file=C:\Users\boe\Documents\mabam\Drives\efi.qcow2,discard=unmap,detect-zeroes=unmap" ^
-device ide-hd,bus=ide.1,drive=SLHD,bootindex=1 ^
-drive "if=none,media=disk,id=SLHD,file=C:\Users\boe\Documents\mabam\Drives\Snow Leopard.qcow2,discard=unmap,detect-zeroes=unmap" ^
-name "- Snow Leopard - Port 45002" ^
-monitor tcp:localhost:45002,server,nowait ^
-uuid AE26E2AD-E73B-482E-BD6B-AD01BAA3BFFC ^
-device virtio-rng-pci
However, now I get this error:

Code: Select all

C:\Program Files\qemu\qemu-system-x86_64.exe: Property 'pc-q35-5.2-machine.i8042' not found
But googling for it doesn’t yield anything.

Does anybody have a suggestion?
User avatar
mabam
Master Emulator
Posts: 498
Joined: Wed Apr 10, 2013 9:32 am

Re: QEMU command in Win v.s. macOS host

Post by mabam »

I just tested this original command with QEMU 8 again:
mabam wrote: Mon Nov 13, 2023 9:48 pm […]

Code: Select all

"C:\Program Files\qemu\qemu-system-x86_64.exe" ^
-L "C:\Program Files\qemu\share" ^
-nodefaults ^
-vga none ^
-device e1000,mac=0A:AD:47:06:D2:2C,netdev=net0 ^
-netdev user,id=net0 ^
-device vmware-svga ^
-cpu Penryn,+sse4.1,+sse4.2,+ssse3 ^
-smp cpus=1,sockets=1,cores=1,threads=1 ^
-machine q35,vmport=off,i8042=off,hpet=off ^
-accel whpx ^
-global ICH9-LPC.disable_s3=1 ^
-drive if=pflash,format=raw,unit=0,file.filename="C:\Program Files\qemu\share\edk2-x86_64-code.fd",file.locking=off,readonly=on ^
-drive "if=pflash,unit=1,file=C:\Users\boe\Documents\mabam\Drives\efi_vars.fd" ^
-m 4096 ^
-usb ^
-device usb-tablet,bus=usb-bus.0 ^
-device usb-mouse,bus=usb-bus.0 ^
-device usb-kbd,bus=usb-bus.0 ^
-device nec-usb-xhci,id=usb-controller-0 ^
-device ide-hd,bus=ide.0,drive=EFI,bootindex=0 ^
-drive "if=none,media=disk,id=EFI,file=C:\Users\boe\Documents\mabam\Drives\efi.qcow2,discard=unmap,detect-zeroes=unmap" ^
-device ide-hd,bus=ide.1,drive=SLHD,bootindex=1 ^
-drive "if=none,media=disk,id=SLHD,file=C:\Users\boe\Documents\mabam\Drives\Snow Leopard.qcow2,discard=unmap,detect-zeroes=unmap" ^
-name "- Snow Leopard - Port 45002" ^
-monitor tcp:localhost:45002,server,nowait ^
-uuid AE26E2AD-E73B-482E-BD6B-AD01BAA3BFFC ^
-device virtio-rng-pci
[…]
Only I changed "q35" to "pc-q35-5.2" to test backwards compatibility of my VM with QEMU 5.2 (and I removed the line "-accel whpx" as that would obviously still prevent it from running in QEMU 8).
That went fine so this cannot be the reason for the error message in above post.

Is there possibly something wrong with my installation? Assuming that the QEMU installer had copied everything into C:\Program Files\qemu, I removed QEMU 8 by deleting that folder and then ran the installer for QEMU 5.2. Are there more files I should have removed?
(Again, googling didn't yield an answer to this question.)
User avatar
adespoton
Forum All-Star
Posts: 4285
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: QEMU command in Win v.s. macOS host

Post by adespoton »

So you're saying that with

Code: Select all

-machine pc-q35-5.2,vmport=off,i8042=off,hpet=off ^
everything is working and no error is thrown?

Or are you saying that you still get the error with that machine set?

Regardless, how are you installing QEMU? Using the https://qemu.weilnetz.de/w64/ binaries? I don't tend to use QEMU inside Windows, but depending on the method you use (this or pacman or something else), you'll likely end up with external support libraries being dropped somewhere. Depending on the install method, they'll likely end up in different places.
User avatar
mabam
Master Emulator
Posts: 498
Joined: Wed Apr 10, 2013 9:32 am

Re: QEMU command in Win v.s. macOS host

Post by mabam »

adespoton wrote: Thu Feb 29, 2024 5:29 pm So you're saying that with

Code: Select all

-machine pc-q35-5.2,vmport=off,i8042=off,hpet=off ^
everything is working and no error is thrown?
Only if I use QEMU 8 without the -accel … line, which makes it way too slow to be actually useable.
Or are you saying that you still get the error with that machine set?
If I use QEMU 5.2, yes, I still get the error.

I’ll then look into proper uninstallation first. Thank you.
User avatar
mabam
Master Emulator
Posts: 498
Joined: Wed Apr 10, 2013 9:32 am

Re: QEMU command in Win v.s. macOS host

Post by mabam »

Okay, there was C:\Program Files\qemu\qemu-uninstaller.exe, which I didn’t realise before. But even after running it from both, v. 5.2 and v. 8 and then installing QEMU 5.2 again, I still get the same error message.

I’m using the https://qemu.weilnetz.de/w64/ binaries.
User avatar
adespoton
Forum All-Star
Posts: 4285
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: QEMU command in Win v.s. macOS host

Post by adespoton »

Have you tried building a new guest image from scratch? I seem to recall some architectural changes somewhere along the way that required I set up a new image from scratch. This means your QEMU 8.0 image may not be compatible with QEMU 5.2 due to architectural and EFI changes in the intervening years.
User avatar
mabam
Master Emulator
Posts: 498
Joined: Wed Apr 10, 2013 9:32 am

Re: QEMU command in Win v.s. macOS host

Post by mabam »

I didn’t. But to verify, I ran the image on QEMU 8 using

Code: Select all

-machine pc-q35-5.2,vmport=off,i8042=off,hpet=off ^
which uses the QEMU 5.2 version of the q35 machine. All good except the missing acceleration.

But the mentioned error is printed in the command window before QEMU even tries to start up the guest itself. So it doesn’t seem to be related to what the guest image contains.
Post Reply