QEMU overview
QEMU is a FAST! processor emulator using dynamic translation to achieve good emulation speed. ["Xen"] is the free source alternative to ["VMWare"] and ["Xen"] is the free source alternative to QEMU.
QEMU has two operating modes:
- Full system emulation. In this mode, QEMU emulates a full system (for example a PC), including a processor and various peripherials. It can be used to launch different Operating Systems without rebooting the PC or to debug system code.
- User mode emulation (Linux host only). In this mode, QEMU can launch Linux processes compiled for one CPU on another CPU. It can be used to launch the ["Wine"] Windows API emulator or to ease cross-compilation and cross-debugging.
As QEMU requires no host kernel patches to run, it is very safe and easy to use.
There is also an [http://fabrice.bellard.free.fr/qemu/kqemu-doc.html accelerator kernel module] available which speeds up execution when emulating an x86 CPU on a native x86 CPU. The latest release of the kernel accelerator module is open source, and currently available in DebianExperimental.
gcc-4.0 hint
qemu can not yet be compiled with gcc-4.0. Use something like
$ ./configure --cc=gcc-3.4 --host-cc=gcc-3.4
when compiling qemu yourself and your gcc is already gcc-4.0.
Setting up a testing/unstable system with qemu
qemu is especially handy to set up an emulated testing/unstable system when working on the Debian installer itself or on the boot system, or when trying some experimental features without impact on the productive system. A sid system can be set up with the following steps:
Create the hard disk image with
$ qemu-img create debian.img 2G
Download a current boot image, e.g. the businesscard image at http://cdimage.debian.org/cdimage/daily-builds/daily/arch-latest/i386/iso-cd/
Boot the image with
$ qemu -hda debian.img -cdrom debian-testing-i386-businesscard.iso -boot d -m 256
- When the usual debian boot screen appears, boot into "expert" mode
- Install the system as usual; to set up a sid system choose "unstable" when being asked by the installer.
After the installation is done, the system can be booted with
$ qemu -hda debian.img -m 256
Backing up the disk image
The disk image "debian.img" is a [http://www.wiktionary.org/wiki/sparse sparse] file. After installing a ?DebianBaseSystem, it fits on a CD-ROM even without compression:
$ tar c --sparse -f backup.tar debian.img
creates a ["tar"] file of about 320M (supposed that the image contains a 1.["9GB"] ext3 root filesystem and a ["250MB"] swap partition). After unpacking with tar xf, the sparse file is restored and can be booted immediately.
Better still, convert from a sparse file into the qemu's own "Copy On Write" image. This conversion will save the same space and still be runnable.
$ qemu-image convert -c debian.img -O qcow debian_recompressed.img
If the guest system's image is still larger than reasonable, then open up the Guest system and run "dd if=/dev/zero of=/tmp/junk ; sync ; rm /tmp/junk". That will push out deleted file scraps, recompression should work then.
Using kqemu accelerator
As of version 1.3.0pre10, Kqemu is now distributed under a GPL licence (see [http://fabrice.bellard.free.fr/qemu/kqemu-changelog.html Kqemu changelog]). Consequently it is quite simple to compile and install it yourself, using the package kqemu-source, or any of the prebuild modules : kqemu-module-$(uname -r).
qemu will use the kernel accelerator by default if available for user-space processes in the emulated OS. If you wish to use the kernel accelerator for the emulated kernel as well, then use the -kernel-kqemu option to qemu. When running a current Debian release under qemu with this option, you may need to add pci=nobios to the kernel command line.
External links
[https://gna.org/projects/qemulaunch/ Qemulaunch for GNOME]
[http://technowizah.com/2007/02/debian-how-to-qemu-virtual-machine.html Debian HOW-TO : QEMU Virtual Machine]
[http://kvm.qumranet.com/kvmwiki/Debian Debian - Kernel based Virtual Machine]