QEMU (Quick Emulator)

From Bauman National Library
This page was last modified on 24 December 2016, at 10:23.
</td></tr>
QEMU
Qemu logo.svg.png
The free operating system ReactOS running within QEMU, which runs as a process on Linux
The free operating system ReactOS running within QEMU, which runs as a process on Linux
Original author(s) Fabrice Bellard
Developer(s) QEMU team:
Peter Maydell, et al.
Stable release
2.6.2
Repository {{#property:P1324}}
Written in C
Operating system Linux, Microsoft Windows, Mac OS X and some other UNIX platforms
Type Hypervisor
License GNU GPL version 2
Website qemu.org

QEMU (short for Quick Emulator) is a free and open-source hosted hypervisor that performs hardware virtualization (not to be confused with hardware-assisted virtualization).

QEMU is a hosted virtual machine monitor: It emulates CPUs through dynamic binary translation and provides a set of device models, enabling it to run a variety of unmodified guest operating systems. It also can be used together with KVM in order to run virtual machines at near-native speed (requiring hardware virtualization extensions on x86 machines). QEMU can also be used purely for CPU emulation for user-level processes, allowing applications compiled for one architecture to be run on another.

Licensing

QEMU was written by Fabrice Bellard and is free software and is mainly licensed under GNU General Public License (GPL). Various parts are released under BSD license, GNU Lesser General Public License (LGPL) or other GPL-compatible licenses.[1] There is an option to use the proprietary FMOD library when running on Microsoft Windows, which, if used, disqualifies the use of a single open source software license. However, the default is to use DirectSound.

Operating modes

QEMU has multiple operating modes:[2]

User-mode emulation
In this mode, QEMU can launch 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.
System emulation
n this mode, QEMU emulates a full system (for example a PC), including one or several processors and various peripherals. It can be used to launch different Operating Systems without rebooting the PC or to debug system code.
KVM Hosting
Here QEMU deals with the setting up and migration of KVM images. It is still involved in the emulation of hardware, but the execution of the guest is done by KVM as requested by QEMU.
Xen Hosting
QEMU is involved only in the emulation of hardware; the execution of the guest is done within Xen and is totally hidden from QEMU.

Features

QEMU is a fast processor emulator using dynamic translation to achieve good emulation speed.

QEMU has two operating modes:

  • Full system emulation. In this mode, QEMU emulates a full system (for example a PC), including one or several processors and various peripherals. It can be used to launch different Operating Systems without rebooting the PC or to debug system code.
  • User mode emulation. In this mode, QEMU can launch 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.

QEMU can run without a host kernel driver and yet gives acceptable performance. It uses dynamic translation to native code for reasonable speed, with support for self-modifying code and precise exceptions.

QEMU can save and restore the state of the virtual machine with all programs running. Guest operating-systems do not need patching in order to run inside QEMU.

The virtual machine can interface with many types of physical host hardware. These include: hard disks, CD-ROM drives, network cards, audio interfaces, and USB devices. USB devices can be completely emulated (mass storage from image files, input devices), or the host's USB devices can be used (however, this requires administrator privileges and does not work with all devices).

Virtual disk images can be stored in a special format (qcow or qcow2) that only take up disk space that the guest OS actually uses. This way, an emulated 120 GB disk may occupy only a few hundred megabytes on the host. The QCOW2 format also allows the creation of overlay images that record the difference from another (unmodified) base image file. This provides the possibility for reverting the emulated disk's contents to an earlier state. For example, a base image could hold a fresh install of an operating system that is known to work, and the overlay images are used. Should the guest system become unusable (through virus attack, accidental system destruction, Windows X, ...), the user can delete the overlay and reconstruct an earlier emulated disk-image version.

QEMU can emulate network cards (of different models) which share the host system's connectivity by doing network address translation, effectively allowing the guest to use the same network as the host. The virtual network cards can also connect to network cards of other instances of QEMU or to local TAP interfaces. Network connectivity can also be achieved by bridging a TUN/TAP interface used by QEMU with a non-virtual Ethernet interface on the host OS using the host OS's bridging features.

QEMU integrates several services to allow the host and guest systems to communicate; for example, an integrated SMB server and network-port redirection (to allow incoming connections to the virtual machine). It can also boot Linux kernels without a bootloader.

QEMU does not depend on the presence of graphical output methods on the host system. Instead, it can allow one to access the screen of the guest OS via an integrated VNC server. It can also use an emulated serial line, without any screen, with applicable operating systems.

Simulating multiple CPUs running SMP is possible.

QEMU does not require administrative rights to run, unless additional kernel modules for improving speed are used (like KQEMU), or when some modes of its network connectivity model are utilized.

User mode emulation features

  • Generic Linux system call converter, including most ioctls.
  • clone() emulation using native CPU clone() to use Linux scheduler for threads.
  • Accurate signal handling by remapping host signals to target signals.

Full system emulation features

  • QEMU uses a full software MMU for maximum portability.
  • QEMU can optionally use an in-kernel accelerator, like kvm. The accelerators execute most of the guest code natively, while continuing to emulate the rest of the machine.
  • Various hardware devices can be emulated and in some cases, host devices (e.g. serial and parallel ports, USB, drives) can be used transparently by the guest Operating System. Host device passthrough can be used for talking to external physical peripherals (e.g. a webcam, modem or tape drive).
  • Symmetric multiprocessing (SMP) support. Currently, an in-kernel accelerator is required to use more than one host CPU for emulation.

Hardware-assisted emulation

The MIPS-compatible Loongson-3 processor adds 200 new instructions to help QEMU translate x86 instructions; those new instructions lower the overhead of executing x86/CISC-style instructions in the MIPS pipeline. With additional improvements in QEMU by the Chinese Academy of Sciences, Loongson-3 achieves an average of 70% the performance of executing native binaries while running x86 binaries from nine benchmarks.[3]

Parallel emulation

Virtualization solutions that use QEMU are able to execute multiple virtual CPUs in parallel. QEMU is also able to run multiple threads in user-mode emulation mode.

For full system emulation, QEMU uses a single thread to emulate all the virtual CPUs and hardware. COREMU[4] is a patch to QEMU to eliminate this limitation. Each core uses a separate instance of QEMU binary translation engine, with a thin library layer to handle the inter-core and device communication and synchronization.

Installing QEMU

Most GNU/Linux distributions have simple installation processes based on package repositories. It is often best to use the repository approach for installing QEMU, as you can be confident that it will just install and run. Here are some examples:

Distribution Install command
Fedora [5] yum install qemu
Debian [6] apt-get install qemu qemu-kvm libvirt-bin
SUSE yast -i qemu
Gentoo emerge -av app-emulation/qemu
Arch sudo pacman -S qemu
Mac (Homebrew) brew install qemu

If you can't install QEMU from a package repository, go to the QEMU website and download the latest source code and follow the instructions given.

For Microsoft Windows, you can install a GUI front-end to QEMU called QEMU Manager, or get a vanilla QEMU installer.

QEMU from source

The most surefire way to get QEMU working is to build QEMU from its source. To do so, enter the following commands in a command line environment:

 git clone git://git.qemu-project.org/qemu.git
(The git link here is provided by the QEMU download page)
cd qemu
git submodule init
git submodule update --recursive
(Credit for steps 3,4 and 5)
git submodule status --recursive
git checkout stable-2.6
(As of writing this, the stable branch version is 2.6. Change 2.6 to the number of current stable version when you are applying these steps)
mkdir build
cd build
../configure
(If you want to build QEMU only for a specific target (say, only for 32-bit x86) instead of for all targets, use Template:Nowrap begin../configure --target-list=i386-softmmuTemplate:Nowrap end instead)
make

NOTE: All these steps should work seamlessly on all platforms, except for the step 9 on Windows. To get step 9 working on Windows, you need MinGW or a similar solution. That is, to get this working on Windows, you need MinGW (or a similar solution).

You may find platform specific instructions on compiling QEMU from source here.

External links

References

Cite error: Invalid <references> tag; parameter "group" is allowed only.

Use <references />, or <references group="..." />
  1. QEMU license
  2. QEMU Internals
  3. "Godson-3: A Scalable Multicore RISC Processor with x86 Emulation". IEEE. Retrieved 2009-04-16. 
  4. COREMU project page on SourceForge
  5. Also valid for other RPM-based distributions (e.g. RedHat, CentOS).
  6. Also valid for other dpkg-based distributions (e.g. Ubuntu, Mepis, Mint).