Running virtual linux using qemu on windows

Here is how I run a minimal version of CentOS 7 on a Windows 7 Enterprise, 64 bits, without being a member of the administrator group (non-admin).

The basic idea is:

  1. Download qemu for windows and unzip it anywhere
  2. Download an ISO image of the Linux distribution you want to run
  3. Create a file that will be your virtual machine hard disk
  4. Run qemu, booting from the CD image
  5. Install the OS
  6. Reboot the virtual machine, this time without the CD image

Networking and fancy graphics are hard to get right. Still struggling, actually...

1. Download QEMU

Use a precompiled binary found on QEMU links page. I used version 2.8.0 for this.

To "install" this version as a non-admin, open a command prompt, issue the command set __COMPAT_LAYER=RunAsInvoker and run qemu-w64-setup-20170131.exe from that prompt. Install in a folder where you have write permissions, like "My Documents" or something.

2. Download an ISO image of Linux

Again, help yourself. I used the Minimal distribution of CentOS 7, the file is called CentOS-7-x86_64-Minimal-1611.iso.

3. Create a virtual hard disk

I used a batch file for this. Copy the following to a file named createvm.bat and adjust the variables to suit your environment:

@echo off
rem ==================================
rem Replace with your values
rem ==================================
set "QEMUDIR=%USERPROFILE%\Documents\Warez\qemu-2.8.0-win64"

rem ==================================
rem Safety net
rem ==================================
if not exist hda.img (
    rem CREATE a virtual hard disk 
    %QEMUDIR%\qemu-img.exe create hda.img 40G
) else (
    echo file hda.img already exist. Delete or move and try again.
    goto:eof
)

4. Run QEMU, booting from the virtual CD

Use a batch for this one, as you might use it often. Copy the follwing into installvm.bat:

@echo off

rem ==================================
rem Replace with your values
rem ==================================
set "QEMUDIR=%USERPROFILE%\Documents\Warez\qemu-2.8.0-win64"
set "ISOFILE=CentOS-7-x86_64-Minimal-1611.iso"

rem ==================================
rem You can add a w suffix to this if 
rem you don't want a console
rem ==================================
set "QEMUBIN=qemu-system-x86_64.exe"

rem ==================================
rem Run the virtual machine
rem ==================================
start "QEMU" %QEMUDIR%\%QEMUBIN% -drive file=hda.img,index=0,media=disk,format=raw -cdrom %ISOFILE% -m 2G -L Bios -usbdevice mouse -usbdevice keyboard -boot menu=on -rtc base=localtime,clock=host -parallel none -serial none -name centos -no-acpi -no-hpet -no-reboot 

5. Install the OS

I had trouble with the GUI installer. When prompted to install CentOS, hit the TAB key and replace the word quiet at the end of that line with the word text.

Follow the installation instructions on screen. When the installation is finished, the virtual machine will exit. It can take quite a while, especially when running as a non-admin user.

6. Run your Linux image in QEMU

This step is what you will do over and over again to run the VM each time you need it. Copy the follwing into runvm.bat:

@echo off

rem ==================================
rem Replace with your values
rem ==================================
set "QEMUDIR=%USERPROFILE%\Documents\Warez\qemu-2.8.0-win64"

rem ==================================
rem You can add a w suffix to this if 
rem you don't want a console
rem ==================================
set "QEMUBIN=qemu-system-x86_64.exe"

rem ==================================
rem Run the virtual machine
rem ==================================
start "QEMU" %QEMUDIR%\%QEMUBIN% -drive file=hda.img,index=0,media=disk,format=raw -m 2G -L Bios -usbdevice mouse -usbdevice keyboard -boot menu=on -rtc base=localtime,clock=host -parallel none -serial none -name centos -no-acpi -no-hpet -no-reboot -device e1000,netdev=user.0 -netdev user,id=user.0,hostfwd=tcp::2222-:22

I added a local portforward : if you ssh/putty to localhost:2222, you will reach the SSH daemon of your VM. Beware that firewalld or iptables might block traffic, depending on the way you installed Linux.


The Qemu manual would be a good place to start. It'll help you work out what you're supposed to do next, which is to tell qemu what to do, and exactly how to do that.