, 2018-03-29

Run a (Arch)Linux system in a QEMU virtual machine on your Windows.

Intro

This is my first try to use QEMU to run Archlinux in a virtual machine.

To use a virtual machine like QEMU can be quite useful for various reasons.

If you have the choice between a system with 32 and 64 bit then choose the 64bit one. The newer 64bit processors have additional processor commands to support virtual machines. Sometimes these virtualization functions still have to be turned on in the BIOS.

When talking about virtual machines you find the expressions host and guest a lot.

Also to use QEMU you need to use the Windows command prompt. I haven't used it for 15 years, but what you need is really basic so you should be all right.

In this article I wan to set up a QEMU virtual machine with a Windows host and a Archlinux guest.

When the virtual machine is used I am looking for this kind of configuration:

Wifi setup is not for the guest Linux required even if you are actually using Wifi for you host computer. The virtual machine will make the network available to the guest as if it is a cable.

Install QEMU on Windows

You can install QUEMU from their website. The installation is quite straight forward.

After the installation all QEMU commands are in the QEMU folder. However, at least in my case the folder has not been added to the Windows search path. That means the commands will not be found if you just type them into the command prompt.

So instead of typing a command you have to be in the QEMU folder and then type ./command

Starting the virtual machine

Before you can start to install a new system you need a filesystem that the virtual machine can use and also a linux distribution ISO file.

Create a virtual hard drive

To be able to install linux it has to has access to a hard drive. For a virtual machine the hard drive will be emulated by a file on Windows. There are two options for that file:

For this article we will use qcow2. You can create the drive wherever you want. I will put is in a sub-folder in QEMU named harddrive. The actually file is called archlinux.hd

Type this to create the harddrive:

./qemu-img create -f qcow2 harddrive\archlinux.hd 8G

Download a linux distribution to install

First you need to download a linux ISO file somewhere. If you are not sure which one you want the distrowatch lists a lot of choices and ranks them by usage. Also some description is given and for some linux distros you can also find some reviews.

As the title said, for this article I will use Anarchy Linux. That is basically an installer helper to set up an Archlinux system without the hassle to do it all by hand. It's all driven by menus. Previously Anarchy Linux was also called ArchAnywhere. It is probably helpful if you have set up Archlinux by hand once, but not mandatory. Also some knowledge about using the shell is helpful for Archlinux. It is not difficult though and comes quite natural.

If in doubt maybe start with Manjaro. That is a Archlinux based distro that is tailored for ease of use. It is quite popular, has decent documentation and you find a lot of help and forums in in the web.

Anarchy Linux can be found here

Run the virtual machine

So now that all preparations are done we can start the QEMU virtual machine. And install the Linux in the virtual hard drive.

qemu-system-x86_64 -m 2G -cdrom anarchy-cli-1.0.0-x86_64.iso -boot order=d -drive file=harddrive\archlinux.hd

To start and try your shiny new VM you can start it with

qemu-system-x86_64 -m 2G -boot order=c -drive file=harddrive\archlinux.hd

Aaand it turns out it is quite slow.

Luckily some things can be done.

  1. Currently we use only one processor, So that can be increased to two.
  2. QEMU needs some Intel libraries to support the hardware acceleration for modern AMD64 (aka X86_64) processors.

The second option is to use the parameter -accel hax. There is a Intel package that needs to be present for this parameter to work. Instructions here

The -accel hax switch does seem to speed up things. Only problem so far is that my Linux installation crashes. Well.

to be continued, hopefully