KVM

KVM or the Kernel-based Virtual Machine is the hardware-assisted virtualization infrastructure provided by the Linux kernel.

Installation
Emerge the qemu-kvm package:

Add your user to the kvm group:

Make sure KVM is enabled in the kernel:

Front ends
To make life easier, there are multiple user-friendly front-ends to KVM, such as or. This guide uses just qemu-kvm.

Creating a virtual machine
To create a disk image for the virtual machine, run:

Since qemu requires a lot of options, it would be a good idea to put them into a shell script. For instance:

This will start a QEMU virtual machine with:
 * Drive set to the one created, using the Virtio disk driver (see below)
 * With a NAT-ed network connection
 * 1 Gigabyte of memory
 * Standard "vga" output (to support multiple resolutions)
 * A monitor interface in the terminal window
 * Titled "Fedora VM"

Additional parameters can be passed to it. To boot the disk image, run:

Enabling Virtio disk driver
Using the default QEMU disk emulation will result in very poor I/O performance due to the guest not being able to cooperate with the host. The solution is to enable Virtio.

Linux
Most recent Linux distributions should be able to support Virtio out-of-the-box. Virtio disks will show up as /dev/vd*.

Windows
Windows will not be able to detect Virtio devices by itself. It is best to enable the driver before the installation starts. When installing Windows XP, it briefly displays "Press F6 if you need to install a third pary SCSI or RAID driver" at the beginning, which will allow the Virtio driver to be loaded. You will need a Windows Virtio driver floppy image:

Temporary
A virtual machine can be started with the -snapshot parameter, which will result in all changes to the image to be discarded. (In fact, no changes are actually written to disk.) This could be useful for experimentation.

Disk image overlays
It is also possible to create a "backing file" which acts as an overlay over the original image - any new changes are made are written to that file while the original is kept unmodified, and kept in its initial state.

Advantages

 * No external modules
 * Does not taint kernel

Disadvantages

 * Requires hardware virtualization support
 * The usual limitations of hardware based virtualization .e.g. supports only architectures that guest OS supports, in particular it's not possible to run x86_64 guest on x86 host but vice versa is supported
 * No seamless guest window integration with host GUI unless both host and guest are using new enough SPICE
 * No 3D acceleration

External resources

 * KVM Wiki
 * Unofficial Gentoo Wiki entry