QEMU: Maybe a VMWare Killer, Maybe Not

By Carla Schroder | Jan 24, 2006 | Print this Page
http://www.enterprisenetworkingplanet.com/netos/article.php/3579721/QEMU-Maybe-a-VMWare-Killer-Maybe-Not.htm

Hackers are not evil persons who infest your computer with malware, or devote their lives to finding ways to break into your systems and do bad things. Those are crackers. I know, it's an uphill battle trying to rescue the real meaning of "hacker", but I must try. Because hackers do fun, creative, useful things, like capture innocent, unsuspecting operating systems and make them run other operating systems.

This opens up all kinds of possibilities. You can access Windows applications from Linux without having to dual-boot or have a second PC. Or Linux geeks trapped on a Windows machine can still have their favorite Linux stuff. Software developers use virtual environments for cross-platform testing and development, usually VMWare Workstation. VMWare has long dominated the Linux-on-Windows/Windows-on-Linux space. If you have almost $200 to spend and don't mind using a closed-source proprietary product, it's an excellent application with lots of features, polish and good performance.

Of course no self-respecting FOSS hacker is going to fork over money for such a thing, but instead will sit down and code something. And thus we have a number of FOSS applications for running Linux on Windows, Windows on Linux, Windows applications on Linux, Linux on Linux, and other platforms get to join the party as well.

The Wide Wide World of Virtual Environments
You can run Windows applications without Windows:

Hardware emulators are for creating a complete PC system environment inside your operating system, which allows you to run all kinds of different operating systems:

You can run GNU/Linux applications on Windows inside a nice little Linux-like capsule:

How about a Free Windows clone?

Run multiple Linuxes on a single machine:

And finally, the star of today's article, QEMU. QEMU operates in two modes: full system emulation or user mode emulation. It can emulate an entire system, which allows alien operating systems to run, like Windows on Linux. Or it can emulate a CPU, which allows binaries to run on different CPUs than they were compiled for. So far this only works on Linux. User mode emulation is faster and less system-resource intensive. The kqemu accelerator is what makes user mode emulation go, which we'll get to presently.

QEMU has been ported to Linux, Solaris, Windows, OS/2, NetBSD, and several other platforms, and there are a number of good third-party ports at FreeOSZoo.org, including Mac OS X and PowerPC. FreeOSZoo is a great resource for QEMU users.

Emulation sucks up a lot of horsepower, as VMWare fans know well, so don't try this on your antique classic Pentium. Any decent modern PC should work fine. QEMU is pretty efficient, and using the kqemu accelerator makes a big difference. Which is brings us to the first QEMU gotcha: QEMU is GPL, but kqemu is closed-source and proprietary. The terms of use are liberal, but because of the license you won't see it in any Linux distributions; you have to install it from sources, then load a kernel module. Whee.

kqemu is available for Linux, and beta versions have been released for Windows and FreeBSD. This means using Linux as your host operating system works best, and using the others will probably hit a few bumps. Without further ado, let us give QEMU a test-drive.

The Damn Small Linux Quickstart
The fastest way to see QEMU in operation is to go to the Damn Small Linux download page and download Damn Small Linux with QEMU already built-in. You don't have to install a thing on the host operating systems. Get dsl-2.1b-embedded.zip. Unzip it (yes, Linux has an unzipcommand) and burn the unpacked files to a CD, or copy them to a USB key. Don't copy the top-level directory, just the files, so it looks like this:

$ ls
boot.msg
dsl-linux.sh
dsl-windows.bat
f2
f3
german.kbd
KNOPPIX
linux24
logo.16
minirt24.gz
qemu
readme.txt
syslinux.cfg

Figure 1.
(Click for a larger image)

This gives you a CD or USB drive that can either boot the machine, or run inside Linux or Windows. On Windows, pop in the disk or USB key and click dsl-windows.bat. Which gives you a window like the one in Figure 1.

To run it on Linux, run dsl-linux.sh, which you foresightfully made executable.

The OpenBSD Demo
With QEMU you can run any bootable operating system image. The fine folks at FreeOSZoo.org have created a number of them for us to play with. I downloaded the OpenBSD image, and imagine my surprise when this nice little 100-megabyte download expanded to a full gigabyte. That's some kind of compression. The unpacked image is named openbsd37.img. You need root privileges to get networking to work, like this:

$ sudo qemu -hda openbsd37.img
Password:
Connected to host network interface: tun0

Figure 2.
(Click for a larger image)

Which opens a window where you can watch OpenBSD boot up until it stops at a login prompt, as shown in Figure 2.

Be sure to read the OpenBSD README to get the login password and default network settings.

kqemu
Naturally we want the best performance, which means compiling and installing kqemu. On Linux, get the kqemu sources for your distribution, and make sure you have your kernel headers installed on your system, and the SDL libraries. Follow these directions for building, compiling, and installing kqemu. (Windows instructions are here too.) Don't forget to load the module with modprobe kqemu.

Not Really a VMWare Killer - Yet
QEMU is still young, and the kqemu license troubles some folks. I can't say if it's reliable for heavy-duty production use, though I know a number of developers who rely on it. For example, they'll use it to test an .iso to make sure it works before burning it to disk. I've found it's most reliable using Linux as the host system.

You'll find lots of documentation installed with QEMU, and the user forums are active and helpful. Also see Resources for more help and information.

Resources