qemu How to virtualize FreeBSD 13.2 on Windows 11 with qemu-kvm and the whpx hypervisor.

Hello to every FreeBSD lover.

I would like to virtualize FreeBSD on Windows 11 wth qemu-kvm (for Windows) using the Hyper-V hypervisor (if I don't make a mistake it should be "-accel whpx"). The idea comes to my mind because at the beginning I found this nice article and I wanted to emulate MacOS :


https://www.digitalfoundations.com.au/blog/macos-on-windows-with-qemu/


but,at a certain point,I've thought,who cares about MacOS ? I love FreeBSD. Why not try with it ?

So,I have modified the parameters a little bit and I tried with these ones :

Code:
I:\OS\qemu\Linux\qemu\qemu-system-x86_64w.exe -accel whpx -machine q35 -m 8G \
-vga qxl -audiodev dsound,id=snd0 -device ich9-intel-hda \
-device hda-duplex,audiodev=snd0 \
-hda "I:\OS\ISO\FreeBSD\FreeBSD-13.2-RELEASE-amd64-disc1.iso" \
-hdb "I:\OS\qemu\Linux\FreeBSD.img" -rtc base=localtime \
-device nec-usb-xhci,id=xhci -device usb-tablet -device usb-kbd \
-global nec-usb-xhci.msi=off -smbios type=2 -nodefaults \
-netdev user,id=net0 \
-device virtio-net-pci,netdev=net0,id=net0,mac=52:54:00:11:22:33 \
-device ich9-ahci,id=sata \
-bios "I:\OS\qemu\Linux\OSX-KVM-master\OVMF_combined.fd"

Unfortunately some parameter is not good,because I get this nice kernel panic :


r3pqzq7nyjdb1.png



I think that the wrong parameter is the following one :


Code:
 -bios "I:\OS\qemu\Linux\OSX-KVM-master\OVMF_combined.fd"


What's OVMF_combined.fd ? The article says how it has been assembled :


WHPX crashes using separate OVMF CODE & VARS, so combine these to a single file :

copy /B OVMF_VARS.fd + OVMF_CODE.fd OVMF_combined.fd


Anyway,what do you think ? I would like to be able to emulate it on top of Windows 11.
 
Last edited:
Kernel is crashing on rdmsr during early code initialization. I don't have any Windows 11 box available to test this though very likely this is not 11 specific.

Not that long ago I did fire up debugger to troubleshoot similar GP issue here. Look at the CPU specific options -cpu host,hv_relaxed,hv_time,hv_synic,hv-vpindex, it may help you too.
 
these parameters have been accepted by qemu and the installation of FreeBSD has continued :

Code:
-cpu Westmere,vendor=GenuineIntel,+pcid,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check

curiously these are the cpu parameters used for the installation of MacOS with qemu-kvm. Isn't this a sign of the profound similarity that exists between the two operating systems :D ? Can you suggest to me something different than Westmere ?
 
these parameters have been accepted by qemu and the installation of FreeBSD has continued :
Did you try my suggestion ?
It could be that the Westmere causes FreeBSD to skip certain part of its cpu_startup code and that's why it didn't crash (not reading specific address by rdmsr).

In the thread I shared above I actively debugged the panic and pinpointed why it crashed and suggested options to make sure rdmsr gets through.
You could try random options with qemu (I suggest to start with as less options as possible), maybe you get lucky.
Other than that you need actively debug it and see what's wrong.
 
Did you try my suggestion ?
It could be that the Westmere causes FreeBSD to skip certain part of its cpu_startup code and that's why it didn't crash (not reading specific address by rdmsr).

In the thread I shared above I actively debugged the panic and pinpointed why it crashed and suggested options to make sure rdmsr gets through.
You could try random options with qemu (I suggest to start with as less options as possible), maybe you get lucky.
Other than that you need actively debug it and see what's wrong.

sure. I tried. With your parameters it hangs for a couple of seconds and then it exits. The VM is not launched.
 
Now I'm trying to configure Xorg and the xfce4 desktop environment. Since I'm using qemu,there are a lot of display devices available to try,but I don't know which one is good for FreeBSD :


I have installed the package drm-kmod and it suggests to me to add on the rc.conf one of these parameter:

1) for amdgpu : kld_list="amdgpu"
2) for intel : kld_list="i915kms"
3) for radeonkms : kld_list="radeonkms"

unfortunately qemu does not cover any of those. And I don't know which qemu option is decent for my case. The most interesting for me it is :


virtio vga​


  • qemu: -vga virtio or -device virtio-vga
  • libvirt: <model type='virtio'/> (on x86).
  • ✓ VGA compatible
  • ✓ vgabios support
  • ✓ UEFI support (QemuVideoDxe)
  • ✓ linux driver (virtio-gpu.ko)

This is a modern, virtio-based display device designed for virtual machines. It comes with VGA compatibility mode. You need a guest driver to make full use of this device. If your guest OS has no driver it should still show a working display thanks to the VGA compatibility mode, but the device will not provide any advantages over standard VGA then.


This device has (optional) hardware-assisted opengl acceleration support. This can be enabled using the virgl=on property, which in turn needs opengl support enabled (gl=on) in the qemu display.


This device has multihead support, can be enabled using the max_outputs=2 property.


This device has no dedicated video memory (except for VGA compatibility), gpu data will be stored in main memory instead. Therefore this device has no config options for video memory size.


This is the place where most development happens, support for new, cool features will most likely be added to this device.

but then kld_list="what ?".
 
This is what I did to try to use the cirrus driver :

Code:
pkg install xf86-video-cirrus

so,here it is at 0:1:0

2023-07-23 15_21_33-QEMU.png


so,I have created xorg.conf with this content :

Code:
Section "Device"
Identifier "Device0"
Driver "cirrus"
BusID "PCI:0:1:0"
Screen 0
EndSection

error : no screens found.
 
the module seems to be there :

Code:
cd /usr/local/lib/xorg/modules/drivers/
ls
cirrus_drv.so ; modesetting_drv.so ; scfb_drv.so ; vesa_drv.so ;
 
Why Cirrus-Logic VGA and not scfb?
You don't have a Cirrus-Logic card so how do you expect this to work? Same with ATI?
I would assume the Cirrus driver uses hardware for 'hardware acceleration'.
 
Nope. I have declared the cirrus on the qemu parameters. It's not needed to have the hardware :

Code:
I:\OS\qemu\Linux\qemu\qemu-system-x86_64w.exe -accel whpx -machine q35 -m 8G -vga cirrus

actually I've also tried the qxl driver like this :

Code:
I:\OS\qemu\Linux\qemu\qemu-system-x86_64w.exe -accel whpx -machine q35 -m 8G -vga qxl

this time I've got a nice seg fault error :


2023-07-23 17_37_51-QEMU.png


I didn't use any xorg.conf file,but I have only installed the package : xf86-video-qxl
 
I'm gonna try : xf86-video-ati,since qemu supports it :

ati vga​

  • qemu: -device ati-vga.
  • ✓ VGA compatible
  • ✓ vgabios support
  • ✗ no UEFI support
 
I've installed virt-manager inside the Ubuntu / WSL2 subsystem installed on top of Windows 11 and I've virtualized FreeBSD. Virt-manager offers more display option. Now the problem is that the pointer of my mouse seems crazy. Inside the desktop environment it uses relative movements,but these movements aren't synchronized with the absolute movements of the mouse outside of the qemu window. So,it's not usable at all.
 
uses relative movements,but these movements aren't synchronized with the absolute movements of the mouse outside of the qemu window. So,it's not usable at all.
A workaround is to specify usb tablet and use that as a mouse. Something similar to:

Code:
qemu-system-x86_64 -M pc ${otheroptions}                        \
    -drive if=none,id=usbstick,format=raw,file=/path/to/image   \
    -usb                                                        \
    -device usb-tablet,bus=usb-bus.0
 
I'm using virt-manager. I should remove :

Code:
<input type="mouse" bus="ps2"/>

but it won't that I do this. The remove button is greyed out. I've also tried with "virsh edit FreeBSD-13.2" ; but it recreates the block of code everytime I try to remove it.


2023-07-24 00_13_39-FreeBSD-13.2 on QEMU_KVM (Ubuntu-22.04).png
 
I installed W11 and tested it. While "host" CPU is not a valid type on qemu8 under w11 similar option exists: kvm64. I had issues using qemu's default UEFI for some reason; I used firmware from proxmox.

With the options I was able to start the VM successfully. Without it GP occurs on the same instruction you posted.

qemu-system-x86_64 -device virtio-blk-pci,drive=hd0 -drive if=none,id=hd0,format=qcow2,file=FreeBSD-13.2-RELEASE-amd64.qcow2 -m 8G -accel whpx,kernel-irqchip=off -cpu kvm64,hv_relaxed,hv_time,hv_synic -bios OVMF_CODE.fd

Unfortunately whpx/gdbserver combination is not available on w11/qemu8. If I recall correctly I was debugging this issue before on Linux host with whpx acceleration.
 
Please help me to fix the mouse issue. I'm banging my head on this problem. The pointer of my mouse seems crazy. Inside the desktop environment it uses relative movements,but these movements aren't synchronized with the absolute movements of the mouse outside of the qemu window. So,it's not usable at all,neither with the qemu "raw" commands,nor with virt-manager. Regarding your qemu parameters,which differences there are between these :

Code:
-cpu Westmere,vendor=GenuineIntel,+pcid,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check

and these :

Code:
-cpu kvm64,hv_relaxed,hv_time,hv_synic

? mine works,so I use mine,since they seem to be more structured.
 
They are different options. Yours are not more structured, you just named different parameters (and very likely some of them are redundant). I shared my 2c why Westmere type may be working there.

I reacted to your thread about the GP issue and shared the solution. If anything for future people brought here by search engine.
 
Back
Top