Using Qemu: the Open-Source x86 PC Emulator

Alexey Eremenko "Technologov"

$Revision: 06 $

$Date: 2007-01-15 $

Qemu is very nice generic computer emulator. Qemu is a user-space program, capable of running on any host architecture, multiple Operating Systems, and emulating many guest modes and/or architectures. The most frequent use, is as an x86 PC Emulator.

Scenarios

  • You want to run some Operating System in emulated mode.

  • You want to test new software under different OSes for compatibility.

  • You want to build virtual networks.

  • Server Consolidation: You want to remove old physical servers, and move their functions on new hardware. It will improve server uptime, reduce power consumption, and will enable easier managing of virtual machines. Most important of all: It will save physical space -- real estate.

  • It is not useful for gaming, as it does not support 3D Graphics acceleration.

It is not as fast as other solutions, such as the more popular Xen. But it's strength over Xen, is that it can run unmodified OSes, on any host CPU, including non-x86. When comparing to VMware, then Qemu has one advantage: it's Open-Source.

Understand what are you doing

You are going to emulate a full PC box, all standard hardware, including: normal video card (not 3D accelerator), sound card, network card, RAM, hard disk, CD-ROM, motherboard, BIOS, and CPU.

On top of it, you will want to run a real Operating System, so make sure you host system has enough CPU power, hard disk space and RAM to handle the load. Main problem here is RAM. I do not recommend systems with less than 512 MB of RAM to even try this. 2 Gigs of RAM is more appropriate for serious use.

Generally I do *not* recommend using qemu for emulating heavy guest OSes such as SUSE 10.x / Windows XP, but for emulation of lighter Windows 95/98 it will do just fine.

Terminology

  • Host - your real computer, on which the emulator software runs.

  • Guest (VM) - your emulated computer, virtual machine, or VM for short, this is *what* you are trying to emulate. Your target. It can be the same, or very different from your real system. For example, your host can be a Pentium III PC, while your guest can be a Sony Playstation. Of course, Qemu cannot simulate Playstations, so look at different software. It's just important that you understand those two basic concepts.

  • Emulation - this technique allow conversion of commands, or instructions, one by one, by using software.

    There are more optimized algorithms exists, that have different names, such as "Dynamic Execution", "Virtualization", whatever...

    Those are software-optimized or hardware-optimized version of the above. As long as everything works as expected, there are no big difference to the end-user.

Procedure

Generally, this procedure does not requires root, with the exception of Qemu system-wide installation.

  1. Please make sure that Qemu is installed:

    suser@localhost:~> rpm -q qemu
    qemu-0.8.2-22

    If not, please install Qemu first, from DualDVD (included only with boxed version of openSUSE) or from the Internet mirrors, such as: http://suse.inode.at/opensuse/distribution/10.2/repo/oss/suse/i586/

  2. I recommend, that you create a qemu virtual machines directory: (for example "~/qemuvm" in your home directory)

    suser@localhost:~> md ~/qemuvm
    suser@localhost:~> cd ~/qemuvm
    suser@localhost:~/qemuvm>

    This is not a strict requirement, but helps organizing once you get several dozens of VMs.

  3. Create a qemu virtual hard disk image, preferably with qcow format: (for syntax help use qemu-img command)

    suser@localhost:~/qemuvm> qemu-img create -f qcow myharddisk.qcow 10G
  4. Start qemu:

    suser@localhost:~/qemuvm> qemu -m 256 -hda myharddisk.qcow -cdrom /dev/cdrom -boot d -localtime
  5. Alternatively, you can start qemu with emulated CDROM:

    suser@localhost:~/qemuvm> qemu -m 256 -hda myharddisk.qcow -cdrom suse-dvd.iso -boot d -localtime

    This method installs faster, because it bypasses the slow access time of a physical CD-ROM, but it requires you to manually prepare an ISO CD image file beforehand (can be done via KDE K3B). I recommend using this technique. As a bonus, your real CD-ROM device will live longer!

  6. After the OS installed, just change the "-boot d" to "-boot c", so the VM will boot from the virtual hard disk.

Additional Modules

By default, Qemu is just a user-space text-controlled application, without any GUI. Unfortunately, none of those modules comes with openSUSE, so you will have to google, download sources and compile yourself.

The graphics user interface front-end module is called QtEmu, it is Open-Source, cross-platform and based on Qt4. This GUI is very nice, stable, and I really recommend it to users.

You can get it at: http://www.kde-apps.org/content/show.php?content=50780

Now, besides a GUI, there are 3 acceleration modules. You can choose one, or run Qemu without any. They may accelerate your Qemu up to x20 fold ! Of course acceleration of those 3 modules requires, that both host and guest be x86 systems. In addition to that KVM requires Intel's VT-capable CPU (read: Intel Core 2 E6000+ series CPU).

  • KVM - Kernel Accelerator Module. OSS. Requires Intel's Vanderpool Technology, AMD Pacifica. Part of official Linux kernel since 2.6.20.

  • QVM - Kernel Accelerator Module. OSS. Doesn't requires special CPUs.

  • Kqemu - Kernel Accelerator Module. Non Free Software. Doesn't requires special CPUs. The oldest module developed.

Now, with introduction of Intel's VT and Linux's KVM, Qemu+KVM became more similar to Xen+VT now, as both apps perform fast now, require special CPUs, and work with unmodified guest OSes now.

For More Information

Qemu Home Page: http://fabrice.bellard.free.fr/qemu/

An Introduction to Virtualization: http://www.kernelthread.com/publications/virtualization/

For more information about my original Qemu how-to: http://en.opensuse.org/Using_Qemu

Run qemu and qemu-img commands without parameters.