How to virtualize FreeBSD (14-RELEASE) as a vm on top of Windows (11) using qemu + HyperV

Hello FreeBSD lovers.

today I want to show you a qemu setup that I'm working on as a nice alternative to WSL2 (even because WSL2 does not support FreeBSD,but only Linux and that's not good. FreeBSD has the same dignity of Linux).

First of all I've developed this setup because I want to use FreeBSD even when I'm using Windows.
Another reason is because, when I use Windows,I can't access the information stored on my ZFS disks.
There are some tools that allow you to mount a ZFS disk directly in Windows,but I see that's not a good idea to install it because Windows crashes often. So,with my setup I've fixed this problem once for all.
I can avoid the installation of the driver ZFS for Windows because I can mount the ZFS pool directly inside FreeBSD and I can easily share the information stored there in both the systems : Windows and FreeBSD itself,even avoiding the crashes.
Once I can access the data inside the zfs disks within FreeBSD,it's easy to share this data with Windows.
I can easily set up a tunnel using sshfs.

I've cloned a physical installation of FreeBSD 14 by creating its img file with dd. The goal is to virtualize FreeBSD 14 on Windows 11 with qemu using the Hyper-V as hypervisor. The parameters that I've used to launch the vm are the following ones :

Code:
qemu-system-x86_64w.exe -accel whpx -machine q35 \
-cpu kvm64,hv_relaxed,hv_time,hv_synic -m 8G \
-device vmware-svga,id=video0,vgamem_mb=16,bus=pcie.0,addr=0x1 \
-audiodev dsound,id=snd0 -device ich9-intel-hda -device hda-duplex,audiodev=snd0 \
-hda "FreeBSD-140-zfs.img" -rtc base=localtime -device usb-ehci,id=usb,bus=pcie.0,addr=0x3 \
-device usb-tablet -device usb-kbd -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\FreeBSD\OSX-KVM-master\OVMF_combined.fd"

It works well,even Xorg and Xfce4. In addition,I have passed a ZFS physical disk to the vm,so that I can use it within the FreeBSD system. So,first of all I needed to find a tool that allows to Windows to recognize that kind of disk. The tool that I found is here :

https://github.com/openzfsonwindows/openzfs/releases/tag/zfswin-2.1.99

And luckily it worked and it seems stable. I've mounted the zfs disk using the command :

Code:
c:\zpool import zroot-swap

It mounted the zpool and it mapped it as H: drive. Anyway,the tool creates a NTFS disk.

Secondarily I have installed these tools :

1) sshfs-win-3.5.20357-x64
2) winfsp-2.0.23075

and I have configured sshfs like this :


2024-04-18 11 51 30.png


Within the FreeBSD vm I have installed the package fusefs-sshfs and I've mounted the root of Windows as a fuse fs like this :

Code:
sshfs -o Compression=no -o allow_root -o transform_symlinks marietto@192.168.1.5:/ /mnt/zroot-swap

and voila',I can use the zroot disk that I've mounted on Windows directly inside the FreeBSD vm :


2024-04-18 12 04 00.png


As a last 3 instructions :

a) I've installed the port "utouch-kmod" (needed to fix the mouse movements) and I got the information to add the kernel module to /boot/loader.conf. I didn't get any information when I have installed the package.

b) inside the FreeBSD vm I have installed the vmware graphic driver and I've reconfigured xorg with the command "Xorg -configure"

c) inside the rc.conf there isn't any need to add the vmware kernel module.

UPDATE :

Taking in consideration the disk I want to share is 10 and the partition 2,as you can see below :

2024-04-18 16 55 47.png


the path of the disk to add to qemu is : \\.\PhysicalDrive10

So,I tried to pass it to qemu using this parameter :

Code:
-drive file=\\.\PhysicalDrive10 -snapshot

-snapshot is used if you don't want to risk to damage the disk.

and...it worked. Then I've been able to mount the ZFS disk in FreeBSD and not in Windows and zfswin is not needed at all.

So,the working qemu parameters are the following :

Code:
qemu-system-x86_64w.exe -accel whpx -machine q35 \
-cpu kvm64,hv_relaxed,hv_time,hv_synic -m 8G \
-device vmware-svga,id=video0,vgamem_mb=16,bus=pcie.0,addr=0x1 \
-audiodev dsound,id=snd0 -device ich9-intel-hda -device hda-duplex,audiodev=snd0 \
-hda "FreeBSD-140-zfs.img" -drive file=\\.\PhysicalDrive10 -rtc base=localtime \
-device usb-ehci,id=usb,bus=pcie.0,addr=0x3 \
-device usb-tablet -device usb-kbd -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\FreeBSD\OSX-KVM-master\OVMF_combined.fd"

That's all. I hope that this tutorial will be useful for someone...
 

Attachments

  • unnamed.png
    unnamed.png
    5.6 KB · Views: 63
  • 2024-04-18 16 55 47.png
    2024-04-18 16 55 47.png
    386.3 KB · Views: 18
Last edited:
It's a shame that WSL2 of MS offers a better graphic performance than the solution qemu + hyperV,even if MS does not allow to pass through the graphic card if you don't have a server grade motherboard. Anyway,qemu + HiperV neither do it (on Windows as host os). In FreeBSD can I use a more powerful graphic adapter than the "VMware SVGA II Adapter" ? Does this support the 3D acceleration ?

2024-04-25 09 51 13.png
 
I'm trying to use the virtio GPU instead of the VMware SVGA,but I'm not able to make it work.
First of all I've added it to the qemu parameters :

Code:
-vga virtio -display gtk,gl=on

On FreeBSD 14.0 guest os I did :

Code:
# lspci

00:01.0 : VGA compatible controller : Red Hat Inc. Virtio 1.0 GPU (rev. 01)

and then,I've added on /boot/loader.conf the following kernel modules :
Code:
virtio_load="YES"
virtio_pci_load="YES"
virtio_blk_load="YES"
virtio_balloon_load="YES"
I tried to load the virtio kernel modules manually :

Code:
[root@marietto /home/marietto]==> kldload virtio
kldload: can't load virtio: module already loaded or in kernel

[root@marietto /home/marietto]==> kldload virtio_pci
kldload: can't load virtio_pci: module already loaded or in kernel

[root@marietto /home/marietto]==> kldload virtio_blk
kldload: can't load virtio_blk: module already loaded or in kernel

[root@marietto /home/marietto]==> kldload virtio_balloon
kldload: can't load virtio_balloon: module already loaded or in kernel
at this point,I've tried to use two different xorg.conf files to see what happened :

nano /etc/X11/xorg.conf :


Section "Device"
Identifier "Card0"
Driver "modesetting"
BusID "PCI:0:1:0"

Xorg.1.log.modesetting : https://pastebin.ubuntu.com/p/JYbks5yNnV/

nano /etc/X11/xorg.conf :

Section "Device"
Identifier "Card0"
Driver "virtio"
BusID "PCI:0:1:0"

Xorg.1.log.virtio : https://pastebin.ubuntu.com/p/tt9Pnd5Zz4/

none of them worked. Someone can give some suggestion ?
 
Back
Top