User:Egberts/Drafts/QEMU

QEMU (Quick EMUlator) is Article description::a generic, open source hardware emulator and virtualization suite.

QEMU is a [Type-2 hypervisor] that runs within user space and performs virtual hardware emulation.

QEMU when used in conjunction with an accelerator becomes a Type-1 hypervisor that runs in kernel space, that allows a user space program access to the hardware virtualization features of various processors. Such accelerator can be 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.

QEMU Virtualization
QEMU is a Type-2 virtualization. (PCI bus pass-through is not supported here so all device drivers must be virtualized mostly using VirtIO).

QEMU with KVM (qemu/kvm) is a Type-1 virtualization. To achieve software-assisted full virtualization of QEMU/KVM, all devices must use VirtIO guest drivers. but not quite the full, full virtualization but more so a paravirtualization where virtual drivers inside the guest VM ensures cooperation between VMs.

Host setup
This section details the fastest paravirtualization (QEMU/KVM) setup for a host that has been installed with Gentoo OS on either x86_64, amd64, or mips CPU hardware platform.

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

To inspect host hardware for virtualization support, issue the following command:

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

Kernel
Described below are the basic requirements for KVM kernel configuration for the host OS. A more complete and up-to-date list can be found at the [//www.linux-kvm.org/page/Tuning_Kernel KVM Tuning Kernel] page.

Physical CPU Processor Support - Host
For the QEMU host, choose one of the two CPU architectures found on its hardware platform:

or

Virtual CPU Processor Support - Guest(s)
For a list of supporting CPUs that the guest platform(s) on this host should support, consult the [QEMU use flags] and insert desire target(s) into the USE= string in the portage configuration  file.

Handling Kernel Config at CLI
To set the various kernel configuration settings from the command lines, the shall be used here:

Mandatory kernel configuration options to set:

Useful kernel configuration options to use:

Accelerated networking, required for  USE flag (recommend):

Needed for 802.1d Ethernet bridging:

Intel VT-g (integrated graphics adapter virtualization)
Mediated device passthrough for Intel GPUs (Broadwell and newer) [//forums.gentoo.org/viewtopic-p-8157704.html].

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, the file(s) can be modified. Two equivalent syntaxes are available: traditional USE flag syntax, i.e.:

Another alternative is to use the newer sexy USE_EXPAND -specific syntax:

Install QEMU host
After reviewing and adding any desired USE flags, emerge :

Kernel Configuration
As a demonstration of completeness of configuration settings for the Linux kernel, the kernel configuration file will be initialized to tinyconfig which is the smallest buildable Linux kernel (but not necessarily the bootable or functional one).

Now blow away the .config with the smallest default setting possible, execute: