Home VM Tips What is QEMU Emulator and How It Works with KVM?

What is QEMU Emulator and How It Works with KVM?

2022-09-06 | Nick Zhao

Table of contents
  • What is QEMU Emulator?
  • How does QEMU interact with KVM?
  • Backup Virtual Machine with Vinchin Backup & Recovery
  • Sum Up

What is QEMU Emulator?

QEMU Emulator is open-source freeware for emulating hardware and devices. It is often used to emulate an independent virtual machine, making virtual machine think it is interacting with the real hardware, but in fact, the hardware is emulated by QEMU Emulator. It is QEMU Emulator that translates all kinds of commands to the real hardware.

This software, mainly licensed under the GNU General Public License, is compiled by Fabrice Bellard, widely used on GNU and Linux. It is like other software like Bochs, PearPC, etc., but without some features like high speed and crossing platform.With KQEMU, a closed-source accelerator, QEMU can emulate nearly the speed of real computer.

Before QEMU 1.0, KQEMU can be used to accelerate QEMU but in QEMU and the later version, it is the QEMU-KVM module that is used as the accelerator and the result is obviously better and stabler than KQEMU.

The performance of QEMU virtual machine is not so good as expected because QEMU Emulator is only a tool and it takes to for every command to be translated and transferred. Therefore, in production environment, IT administrators will use KVM and QEMU Emulator to deploy virtual environment together.

KVM is good at hardware resources virtualization so it is used to do the sophisticated work like virtualizing CPU, memory, etc. while QEMU is responsible for virtualizing I/O. Both of their advantages can get fully utilized to improve the performance of virtual environment.

Technically, every virtual machine is one of the courses on the host and the course (like CPU course, I/O course, etc.) executed by virtual machine is one of the threads of QEMU Emulator course.

There are mainly two modes in QEMU Emulator, User Mode and System Mode. User Mode can help boot the Linux programs that are compiled by different CPU and System Mode is used to emulate the whole system including CPU and other hardware, which makes it easy to test programs compiled on different platforms.

How does QEMU interact with KVM?

Let's see how QEMU interacts with KVM from the example of booting virtual machine:

1 Obtain KVM handle

kvmfd = open("/dev/kvm", O_RDWR)

2 Create virtual machine and obtain the virtual machine handle

vmfd = ioctl(kvmfd, KVM_CREATE_VM, 0);

3 Map memory for virtual machine and initiate PCI and signals

ioctl(kvmfd, KVM_SET_USER_MEMORY_REGION, &mem);

4 Map the virtual machine image to memory. This process is like booting physical virtual machine.

5 Create vCPU and allocate space for vCPU

ioctl(kvm->vcpus->vcpu_fd, KVM_RUN, 0);

6 Thread goes into a loop. The exit reason is captured and related command is executed.

for (;;) {

  ioctl(KVM_RUN)

  switch (exit_reason) {

      case KVM_EXIT_IO:  /* ... */

      case KVM_EXIT_HLT: /* ... */

  }

}

Exit here does not always mean powering off virtual machine. Some other reasons will also cause exit. Generally speaking, it means CPU context returns to QEMU.

Backup Virtual Machine with Vinchin Backup & Recovery

Backing up virtual machine can protect business continuity and Vinchin Backup & Recovery will let you easily backup virtual machine. (Native KVM is not supported for now)

You don't have to type commands in Vinchin Backup & Recovery because the whole process will be completed on a user-friendly web console. You just need to type the credentials of hosts to add them to backup system and then you can preview and select VMs on these hosts to backup them agentlessly.

Your data will be safely stored because Vinchin Backup & Recovery will verify the data to prevent ransomware.

Vinchin Backup & Recovery will also help simply and quickly recover VMs. You just need to select a VM backup and point a host to recover the VM. Vinchin Instant Recovery technology can even help recover a failed VM of any size from its backup in 15 seconds.

Another advantage of Vinchin Backup & Recovery is cross-platform migration. After you add different platforms into Vinchin backup system, you can easily move VM between different hosts.

You can try this system with a 60-day full-featured free trial. Download the installation package and spend a few minutes deploying it.

Sum Up

Server virtualization is popular for improving the work efficiency of IT environment now and QEMU Emulator is one of the tool for that. By using QEMU Emulator and KVM hypervisor together, IT administrators can deploy a highly efficient virtual environment.

Vinchin Backup & Recovery can help you easily protect your virtual machines with features like agentless backup, cross-platform recovery, instant recovery, etc. Don't miss the free trial.

Share on:

Categories: VM Tips