Some notes and tips on how to build and run virtual machines (VMs) with the Quick Emulator (QEMU) on Windows.
Preparation
- Download and install QEMU ("QEMU is a generic and open source machine emulator and virtualizer").
- Performance tip for a Windows host:
Activate the Windows Hypervisor Platform feature (called “whpx” in QEMU):
- Open PowerShell (as Administrator!)
- Run
> Enable-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform -All - At the end, you will be asked to reboot the computer to apply the changes.
Create an empty disk image file for a VM
Use the program qemu-img (usually installed in C:\Program Files\qemu) with the command create to generate an empty disk image file (i.e. the “hard-disk” of the future VM).
Example (for a Haiku VM):
> qemu-img.exe create -f qcow2 C:\VMs\haiku.img 8G
-fspecifies the format of the disk image:qcow2is the current and recommended QEMU image format (most versatile, images are a bit smaller than with other formats).- Followed by the filepath of the disk image.
- Followed by the max. size of the disk image in bytes (the inital size of the “virtual hard disk” after creation will only be a few hundred Kilobytes).
Supported optional suffixes are:korK(= Kilobytes),M(= Megabytes),G(= Gigabytes) andT(= Terabytes);bis ignored!
Install an operating system to a VM
The program qemu-system-x86_64.exe (usually installed in C:\Program Files\qemu) is the main executable of QEMU for a x86-64-bit System running Windows: It provides the means to run a guest operating system on a Windows host.
Example: Install Haiku on a virtual x86-64-bit-PC as a guest for a Windows host
A virtual machine that represents a standard (x86-64-bit) PC and boots the Haiku ISO on boot from the “CD-ROM drive”.
For a Haiku VM (should all be on one line!):
> qemu-system-x86_64.exe -machine q35,usb=on
-cpu Penryn
-accel whpx
-drive file="C:\<path>\haiku.img",format=qcow2
-smp 4
-m 8G
-name Haiku
-usb
-device usb-tablet
-net user
-vga virtio
-display sdl
-cdrom "C:\<path>\haiku-...-anyboot.iso" # only needed for installation!
-boot menu=on # only needed for installation!
-
-machine: The emulated machine by model name (use -machine help to list available machines).
Defines the exact virtual hardware blueprint (chipset, bus architecture, and version-locked features) of a virtual machine. That way, VMs have a well-defined and stable environment. Example:pc: Standard PC (i440FX + PIIX, 1996);q35: Standard PC (Q35 + ICH9, 2009) -
-cpu: To configure the CPU model:- Host passthrough (
-cpu host): Default and recommended. Use the features and capabilities of the real processor of the host machine) - Named model (e.g.
-cpu IvyBridge: Intel Xeon E3-12xx v2 (Ivy Bridge, 2012) — used in a Lenovo ThinkPad T430s (2012-2014).
Note for Haiku:
The “GLTeapot” demo crashes with WHPX acceleration and-cpu host. That’s not critical or very important, yet it still bothered me.
The reason seems to be a problem with the combination of -cpu host and -accel whpx: Windows Hypervisor Platform (WHPX), CPU instruction passthrough and FPU-/SSE emulation don’t play nice with Haiku’s implementation of the Mesa 3D Graphics Library.
Workarounds like kernel-irqchip=off also didn’t help in my case – what helped in the end: Using a stable CPU emulation like-cpu Penryn(Intel Core 2 Duo P9xxx (Penryn Class Core 2, 2007))! - Host passthrough (
-
-accel: To enable an accelerator.
Depending on the target architecture, that can be: kvm, xen, hvf, nitro, nvmm, whpx (Windows Hypervisor Platform), mshv or tcg. -
-drive: The-file=option defines which disk image (the “virtual hard disk”) should be used — see previous section.Don’t use path with spaces in it: Else, you’d need quotation marks and when QEMU is run from a Powershell, the “C:...” confuses QEMU/Powershell.; Neither double or single quotation marks mix well with the colon (interpreted by QEMU as a protocol); and workarounds (like
--%at the start of the parameters or-drive file="file:C:\...") didn’t work for me neither. -
-smp: “Simulate a SMP system with n CPUs initially present on the machine type board.” -
-m: “Sets guest startup RAM size to megs megabytes. Default is 128 MiB. Optionally, a suffix of “M” or “G” can be used to signify a value in megabytes or gigabytes respectively.” -
name: Sets the name of the guest (e.g. for the SDL window caption or for the VNC server). -
-usb: USB stuff… -
-device usb-tablet: “Pointer device that uses absolute coordinates (like a touchscreen). This means QEMU is able to report the mouse position without having to grab the mouse.” -
-nic user,model=virtio: To enable a network connection, using a virtio network interface (the fastest paravirtualized network adapter that QEMU supports). This is also simpler than emulating a real network card, and therefore it’s a bit better in terms of performance. -
-vga virtio(works too:-vga vmware) and-display sdlare essential for good graphics/GUI performance (at least on my ThinkPad notebook, without dedicated graphics hardware, the GUI was otherwise unusable slow). -
-cdrom: “Use <file> as CD-ROM image on the default bus of the emulated machine […]” — e.g. for loading an ISO file for an OS installation. -
-boot: “Specify boot order drives as a string of drive letters. Valid drive letters depend on the target architecture. […]
Interactive boot menus/prompts can be enabled viamenu=onas far as firmware/BIOS supports them. The default is non-interactive boot.”
Optional:
-k: Keyboard layout language (e.g. de or en-us); normally not needed on PC/Linux or PC/Windows hosts (the default isen-us).
Run the VM
After the OS is installed in the disk image file, run the same command as above (qemu-system-x86_64.exe -machine ...) to start the VM — but without the parameters
for the boot medium (i.e. no -cdrom) and or boot order (i.e. no -boot)!
For daily use, it would make sense to either put it in a script or to use a GUI front-end for QEMU…
File Sharing between Guest and Host · 🚧 Not tested yet!
Example: Between Haiku (Guest) and Windows (Host)
SSH/SCP
SMB
- QEMU Windows Guest: Easy File Sharing with QEMU’s built-in SMB (Shallow Thoughts)
- https://www.qemu.org/docs/master/system/invocation.html#hxtool-5 (smb=dir)
But: Haiku/3rd-party-components only support SMBv1 — which is not secure and not recommended (thus disabled by default on Windows!).
On Windows:
- Share a directory (let’s call it “HaikuShare”)
- Enable/Disable SMB1
- Reboot
On Haiku:
- Create a local directory as the mount-point for the share: (let’s call it “WindowsShare”):
mkdir /boot/home/Desktop/WindowsShare - Mount the share:
mount_smbfs //<Username>:<Password>@<IPAddressOfTheWindowsPC>/HaikuShare /boot/home/Desktop/WindowsShare
NFS
- But: Windows 11 Pro doesn’t offer a NFS Server, only a NFS Client (and and Administrative Tools)
- The Server for NFS is only available in Windows Server and Windows 11 Enterprise | Education editions (when the optional NFS Server capability is added via DISM; and even then, it’s limited).
— Source - Alternative: Use a NAS that offers NFS support
I would recommend NFS as SMB v1 is not secured:
Synology NAS do indeed have NFS support. In addition to enabling the protocol in settings, you may have to set NFS permissions on your shared folders in DSM (go to System Settings, then Shared Folders, select one and click Edit, then you have an NFS-Permissions tab). As already hinted at, never enable SMB v1 on any device, as the encryption of the SMB v1 protocol has been broken a long time ago and your devices will be wide open for ransomware and other attacks.
[…]
So after enabling NFS on my NAS, is there something I need to install on the Haiku side to be able to mount the network share?
Create a folder to receive your shared folder and connect to it via command line :
mount_nfs NAS_address:/volume1/shared/folder /boot/home/nfs 0 0
DevLog (19)
Film & Television (58)
Hardware (3)
How-To (74)
News & Announcements (20)
On Software (12)
Projects (26)