Recently I had an assignment that asked us to use Qemu. It took me some trouble to get it running on Windows so I thought I could document it here in case I need it in the future. It would be nice if this helps someone, too!
- Download Qemu and .iso
- Add Qemu path to environment variables settings
- Create an image
- Starting the VM
- Some problems you might encounter
1. Download Qemu and .iso
Click here to download Qemu and download your desired .iso file. After installing Qemu, open Windows Powershell and type qemu-img
. Now you might see that it does not recognize the command. This takes us to number 2.
2. Add Qemu path to environment variables settings
Copy the Qemu path (should be C:\Program Files\qemu
if you didn't change anything) and open environment variables settings by Right click on "This PC" -> Properties -> Advanced system settings -> Environment Variables
.
Click on path
once and click "Edit...". Click "New" and paste the Qemu path.
Here's the youtube video that taught me how to do this. Otherwise, I'd stuck here forever :P.
3. Create an image
Now you can create an image by typing qemu-img create -f qcow2 [name].qcow2 30G
.
4. Starting the VM
When starting the VM, you would want to use an accelerator, or else it is going to take a lot of time installing the OS. It took me more than an hour to install Ubuntu 16.04 without the accelerator.
For Windows, there are two options: HAXM and whpx. Note that HAXM can only be used on Windows Enterprise/Pro/Education so I'm not going to introduce it here. Although I did get it working for whatever reason and after a Windows update, it just stopped working.🤔
Go to Windows Features
and tick Windows Hypervisor Platform
. After that, restart the computer and type this command in the powershell (in the directory where the image and .iso resides): qemu-system-x86_64 -accel whpx -hda .\[name].qcow2 -m 512 -net nic,model=virtio -net user -cdrom .\[name].iso -vga std -boot strict=on
. It should start up and you can proceed to install the OS.
The second time you start up the machine you don't need to type -cdrom
anymore. Just qemu-system-x86_64 -accel whpx -hda .\[name].qcow2 -m 512 -net nic,model=virtio -net user -vga std -boot strict=on
should do it.
5. Some problems you might encounter
You might get stuck when rebooting after installing the OS
My friend and I both encountered the problem and we both used Ubuntu 16.04 for the VM. Just close the window and restart it and it should work fine. Pretty sure this is not best practice, though.You can't seem to do migration using whpx
I got this error when trying to do migration. I found this Github code and I think it has something to do with whpx. I'm not sure how to resolve this. My TA simply allowed me to do migration on the server.
-
Untick
Windows Hypervisor Platform
when using VirtualBox You might get an error from VirtualBox when starting the machine if you keep it ticked. Remember to untick it.
Top comments (6)
OS : Windows 10 professional.
below command work for me.
qemu-system-x86_64.exe -accel whpx -drive file=hda.img,index=0,media=disk,format=raw -cdrom ./ubuntu-20.04.2.0-desktop-amd64.iso -m 4G -L Bios -usbdevice mouse -usbdevice keyboard -boot menu=on -rtc base=localtime,clock=host -parallel none -serial none -name ubuntu-20 -no-acpi -no-hpet -no-reboot -soundhw all -L "C:\Program Files\qemu"
But it failed to understand -usbdevice mouse and keyboard.
Error :
-usbdevice mouse: '-usbdevice' is deprecated, please use '-device usb-...' instead
How I can add -usbdevice mouse and keyboard ?
Any suggestion is appreciated.
qemu-system-x86_64: -accel whpx: Could not load library WinHvPlatform.dll.
qemu-system-x86_64: -accel whpx: failed to initialize whpx: Function not implemented
Just run the command without it, I got the error
PS C:\Users\user\Downloads\isofiles> qemu-system-x86_64 -accel whpx -hda ....qcow2 -m 512 -net nic,model=virtio -net user -cdrom ....iso -vga std -boot strict=on
C:\Program Files\qemu\qemu-system-x86_64.exe: -accel whpx: WHPX: No accelerator found, hr=00000000
C:\Program Files\qemu\qemu-system-x86_64.exe: -accel whpx: failed to initialize whpx: No space left on device.
until I removed that part and it worked perfectly fine.
If you don't have the -accel whpx it uses tcg so it doesn't get errors
Am curious, does Windows 7 have an accelerator? I use Windows 7
How to passthrough GPU under Windows10 host?