Using Qemu on Windows 10 Home Edition
Tags: qemu, windows
Published: 2020-05-02 16:25:20

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!

1. Download Qemu and .iso
2. Add Qemu path to environment variables settings
3. Create an image
4. Starting the VM
5. Some problems you might encounter

## 1. Download Qemu and .iso
[Click here](https://www.qemu.org/download/#windows) 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](https://www.youtube.com/watch?v=al1cnTjeayk) 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`.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/16xmu67njkkc190heqh1.jpg)

## 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.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/yg1y1bs0e64dhls5ndr5.jpg)

## 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](https://github.com/qemu/qemu/blob/master/target/i386/whpx-all.c) 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.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/wxpgbq7s1xt7gkx5lzmq.jpg)

* **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.