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: Open PowerShell (as Administrator!) and activate the Windows Hypervisor Platform feature (called “whpx” in QEMU):
(At the end, you will be asked to reboot the computer to apply the changes.)> Enable-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform -All
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
-f: Specifies 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.
Supported optional suffixes:korKfor Kilobyte (1024),Mfor Megabyte (1024K),Gfor Gigabyte (1024M) andTfor Terabyte (1024G) —bis ignored!
The “virtual hard disk” isn’t created with its full maximum size: Here, it should be 8 Gigabytes; but the disk image file was after its creation only 193 Kilobytes big. And after the basic installation of Haiku from the ISO file (see below), the file grew to ~650 Megabytes.
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
A virtual machine that represents a standard (x86-64-bit) PC and boots the Haiku ISO on boot from the “CD-ROM drive”:
(should all be on one line!)
> qemu-system-x86_64.exe -machine q35
-cpu host
-accel whpx
-drive file="C:\<path>\haiku.img"
-smp 4
-m 8G
-name Haiku
-usb
-device usb-tablet
-net user
-cdrom "C:\<path>\haiku-...-anyboot.iso" # only needed for installation
-boot menu=on # only needed for installation
-machine: The emulated machine by 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 host: Two ways to configure the CPU model with QEMU: Host passthrough (recommended/default to use the features/capabilities of the real processor) or Named model (e.g.IvyBridgewas used in a Lenovo ThinkPad T430s from 2012/2014).
(Host seems to require an accelerator…)-accel whpx: This is used to enable an accelerator. Depending on the target architecture, kvm, xen, hvf, nitro, nvmm, whpx, mshv or tcg can be available.-drive file=<path>: The -file= option defines which disk image (the “hard-disk”) to use with this drive — see previous section.-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.”- -net user: “Configure a host network backend” — no idea yet, what exactly user does or why everyone is using that…
-cdrom<file>: “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 (but without the parameters for the boot medium () and or boot order (-cdrom)) to start the VM
(for daily use, either put it in a script, or use a GUI front-end).-boot
Check (with Haiku R1b6) and conclusion (for now)
- ☑ Network/Internet/LAN: OK
- ☑ Mouse: OK (with
-usb -device usb-tablet!) - ☐ Performance: Using it with -accel whpx, but the fullscreen performance is terrible, even in lower resolution (and in window mode, the GUI of Haiku is tiny)!
On the other hand: I’m currently testing it on a regular laptop with no special graphic/GPU support.
Maybe I haven’t yet found that one magic trick, but for now, I think I will leave it at that:
I know now how to create and run a VM with QEMU (in general), have documented the basics (for future endeavors) here, in my KB.
But my original plan, to use Haiku more often, in a VM, sadly doesn’t look so appealing at the moment…
Film & Television (58)
How-To (75)
Journal (18)
Miscellaneous (4)
News & Announcements (21)
On Software (12)
Projects (26)