Mastering KVM Virtualization
上QQ阅读APP看书,第一时间看更新

Chapter 3. Setting Up Standalone KVM Virtualization

In the second chapter, you learned about KVM internals; now in this chapter, you will learn about how to set up your Linux server as a virtualization host. We are talking about using KVM for virtualization and libvirt as the virtualization management engine.

KVM enables virtualization and readies your server or workstation to host the virtual machines. In technical terms, KVM is a set of kernel modules for an x86 architecture hardware with virtualization extensions; when loaded, it converts a Linux server into a virtualization server (hypervisor). The loadable modules are kvm.ko, which provides the core virtualization capabilities and a processor-specific module, kvm-intel.ko or kvm-amd.ko.

Note

According to https://en.wikipedia.org/wiki/Hypervisor. A hypervisor or virtual machine monitor (VMM) is a piece of computer software, firmware, or hardware that creates and runs virtual machines.

It is not enough to just load the KVM kernel modules to start your virtual machines. You need an emulator to emulate the hardware peripherals for your virtual machines. It is now time to introduce QEMU.

Quick Emulator (QEMU) is an open source machine emulator. This emulator will help you to run the operating systems that are designed to run one architecture on top of another one. For example, Qemu can run an OS created on the ARM platform on the x86 platform; however, there is a catch here. Since QEMU uses dynamic translation, which is a technique used to execute virtual machine instructions on the host machine, the VMs run slow.

If QEMU is slow, how can it run blazing fast KVM-based virtual machines at a near native speed? KVM developers thought about the problem and modified QEMU as a solution. This modified QEMU is called qemu-kvm, which can interact with KVM modules directly and safely execute instructions from the VM directly on the CPU without using dynamic translations. In short, we use qemu-kvm binary to run the KVM-based virtual machines.

It is getting more and more confusing, right? If qemu-kvm can run a virtual machine, then why do you need to use libvirt. The answer is simple, libvirt manages qemu-kvm and qemu-kvm runs the KVM virtual machines.

Note

The qemu-kvm binary is now deprecated and all of the codes in that are now merged with the qemu-system-x86_64 binary. For the purpose of understanding, we are using qemu-kvm. Some Linux distributions still carry qemu-kvm.

Without further ado, let us see what topics will be covered in this chapter:

  • Introduction to libvirt
  • libvirt management tools
  • Hardware setup recommendations