QEMU

QEMU (Quick EMUlator) is a generic, open source machine emulator and virtualizer. Often it is used in conjunction with acceleration in the form of a Type-I hypervisor such as KVM (Kernel-based Virtual Machine) or Xen. If no accelerator is used, QEMU will run entirely in user-space using its built in binary translator TCG (Tiny Code Generator). Using QEMU without an accelerator is relatively inefficient and slow.

BIOS and UEFI firmware
In order to utilize KVM either Vt-x or AMD-V must be supported by the processor. Vt-x or AMD-V are Intel and AMD's respective technologies for permitting multiple operating systems to concurrently execute operations on the processors.

To inspect hardware for visualization support issue the following command:

For a period manufacturers were shipping with virtualization turned off by default in the system BIOS. Note that changing this feature in the BIOS may actually require full removal of power from the system to take effect. If restarting the system does not work try shutting down, unplugging the system and pressing the power button in an unplugged state to discharge any residual energy from the power supply unit (PSU). Reapply power to the system to verify success.

If KVM support is available there should be a "kvm" device listed at. This will take affect after the system has booted to a KVM enabled kernel.

Kernel
Activate the following kernel options:

Needed for  USE flag (recommend):

Needed for 802.1d ethernet bridging:

USE flag is needed for file capabilities support:

When using the ext4 filesystem, enable the  USE flag if stats support is needed:

USE flags
Review the possible USE flags for QEMU.

Emerge
After reviewing and adding any desired USE flags, emerge :

Networking
Basic networking support can be configured "out of the box" by creating a vlan with the following options.

A more advanced networking concept is outlined below, which enables guest access to an external network and also works with both wired and wireless adapters on the host. If desired, a DHCP server can also be setup on the host to allow for dynamic guest IP configurations. There are many different tutorials available online to further understand these concepts.[//blog.san-ss.com.ar/2016/04/setup-nat-network-for-qemu-macosx][//shanetomlinson.com/2009/bridging-a-wireless-card-in-kvmqemu/][//blog.bodhizazen.net/linux/bridge-wireless-cards/][//forums.gentoo.org/viewtopic-t-987790-start-0.html]

Creating TUN/TAP device
This allows the guest to communicate with the bridge. QEMU's default group is, ensure that the correct group is given permissions to control the TAP. Enabling promiscuous mode for the adapter might be unnecessary.

Create network bridge
Creating a network bridge seems necessary, even if only 1 guest is configured. Create the bridge and add each TAP to it. Spanning tree protocol is disabled because there is only 1 bridge.[//https://en.wikibooks.org/wiki/QEMU/Networking#TAP_interfaces]

Packet Forwarding and NAT
Allows for proper packet routing.

Guest configuration
The following should be added to the configuration.

After starting the guest, the IP should be configured to be on the vlan and the gateway should be the IP given to the bridge. The exact process will vary based on OS.

Ipv6
For IPv6 networking see the IPv6 subarticle.

Permissions
In order to run a KVM accelerated virtual machine without logging as root, add normal users to the  group. Replace  in the example command below with the appropriate user(s):

Front ends
To make life easier, there are multiple user-friendly front ends to QEMU:

Usage
The following sub-articles provide instructions on QEMU usage:


 * Usage options - Contains common options used with QEMU.
 * Linux guest - Describes the configuration steps needed to setup Linux to run on QEMU.
 * Windows guest - Describes the configuration steps needed to setup Windows to run on QEMU.
 * OS2WarpV3 guest - Describes the configuration steps needed to setup OS2WarpVs=3 to run on QEMU.

"kvm: already loaded the other module"
Sometimes during the early boot splash the error message "kvm: already loaded the other module" can be seen. This message indicates both the Intel and the AMD kernel virtual machine settings have been enabled in the kernel. To fix this, enable as a module or disable either the Intel or AMD KVM option specific to the system's processor in the kernel configuration. For example, if the system has an Intel processor enable the Intel KVM, then make sure the AMD KVM is set as a module (M) or is disabled (N). The relevant options to enable or disable can be found in the kernel's file via the CONFIG_KVM_INTEL and CONFIG_KVM_AMD variables or in the configuration section above.

External resources

 * http://www.linux-kvm.org/page/KvmOnGentoo - The Gentoo article on the KVM wiki
 * http://wiki.qemu.org/Main_Page - The Official QEMU wiki
 * http://www.tuxradar.com/content/howto-linux-and-windows-virtualization-kvm-and-qemu - A TuxRadar howto.