Qemu in a Windows host

2024-07-11 @equalsraf

UPDATE: 27/08 I have dropped this setup due to qemu issues with hyper-v - it fails to setup cpuid (reports avx2 but no avx) which breaks some code. I'm now using VirtualBox and disabled hyper-v to the same outcome.

I have several problems with WSL (both version 1 and 2) which led me to abandon it for a more traditional VM setup.

The problems:

The trade off here is that qemu user mode network stack is nicer to work with than WSL2 but the downside is file sharing between the host and VM. For performance I'm relying on WHPX support.

qemu setup

My setup relies on a regular qemu VM. The following need to be passed to qemu

The two main benefits here are:

Whats missing

The main downside of this setup is file sharing, and terminal setup

I don't have a nice solution for file sharing. The best I came up it is

For the terminal issues I just work around them using an ssh connection through the forwarded port. But conemu seems to be a bit better than the windows terminal.

OpenSSH server in Windows

For the VM to be able to access the host I rely on the OpenSSH server which is reachable from the VM.

To configure the ssh server in windows

If not set you may want to set the default shell for ssh (from an admin powershell)

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force

The sshd_config file is stored under C:\ProgramData\ssh and you can disable password based auth and restrict the listening interface with

ListenAddress 127.0.0.1
PasswordAuthentication no
PubkeyAuthentication yes

Key based authentication uses an authorized keys file but its location differs if your user is in the Administrator group:

The later file needs to have special permissions (see the MS docs in the refs)

icacls.exe "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"

References

https://issues.guix.gnu.org/49613https://gitlab.com/qemu-project/qemu/-/issues/974https://unix.stackexchange.com/questions/505037/shared-folder-in-qemu-between-windows-host-and-debian-guesthttps://learn.microsoft.com/en-us/windows/wsl/networkinghttps://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_server_configuration