QEMU

QEMU (Quick EMUlator) is Article description::a generic, open source hardware emulator and virtualization suite. 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 virtualization 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 effect 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 flags
Some packages are aware of the USE flag.

Review the possible USE flags for QEMU:

USE_EXPAND
Additional ebuild configuration frobs are provided as the USE_EXPAND variables QEMU_USER_TARGETS and QEMU_SOFTMMU_TARGETS. See for a list of all the available targets (there are a heck of a lot of them; most of them are very obscure and may be ignored; leaving these variables at their default values will disable almost everything which is probably just fine for most users).

For each target specified, a qemu executable will be built. A  target is the standard qemu use-case of emulating an entire system (like VirtualBox or VMWare, but with optional support for emulating CPU hardware along with peripherals). targets execute user-mode code only; the (somewhat shockingly ambitious) purpose of these targets is to "magically" allow importing user-space linux ELF binaries from a different architecture into the native system (that is, they are like multilib, without the awkward need for a software stack or CPU capable of running it).

In order to enable QEMU_USER_TARGETS and QEMU_SOFTMMU_TARGETS we can edit the variables globally in, i.e.:

Or, we can edit the file(s). Two equivalent syntaxes are available: traditional "use-flag" syntax, i.e.:

and, a newer sexy USE_EXPAND-specific syntax:

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

Networking
For Networking configuration, see the networking options documentation.

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:

virt-manager
After emerging, to run virt-manager as a normal user, ensure each user has been added to the group:

Uncomment the following lines from the libvirtd configuration file:

Be sure to have the user log out then log in again for the new group settings to be applied.

Issue the following command to restart the libvirtd service under OpenRC:

Issue the following command to restart the libvirtd service under systemd:

should now be launchable as a regular user.

libvirt recommended kernel config
In addition to the kernel requirements listed above, the following kernel config is recommended by the libvirt installer; check the logs to see if any additional ones are requested by the build.

Checking networking
Network interfaces for virt-manager can be checked by running

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.

Creating TUN/TAP device - No such file or directory
Sometimes this error can occur if TUN/TAP support cannot be found in the kernel. To solve this, try loading the driver:

If that works, add this to a file in to load on startup:

configuration does not support video model 'qxl''
This is usually the case if QEMU is not built with USE flag spice.

So to resolve this issue try to build QEMU with USE flag spice

if you have not installed QEMU try this:

if you have already installed QEMU without USE flag spice try these steps

Remember to use emerge --unmerge carefully as it may cause damage to your Gentoo system.

External resources

 * https://www.linux-kvm.org/page/KvmOnGentoo - The Gentoo article on the KVM wiki
 * https://wiki.qemu.org/Main_Page - The Official QEMU wiki