26
May

Virtualization with KVM on Linux

The technique of virtualization is to create a virtual version of a hardware resource normally provided physically, in particular the x86 virtualization is the creation of a virtual version of a resource belonging to a system with x86 architecture. Any hardware or software resource can be virtualized, so you can have virtual versions of operating systems, memory, disk.

This technique then allows the execution of one or more operating systems and associated software on a single computer without rebooting the system, and with the advantage of creating a secure environment where they are monitored and carry out the instructions of the virtual system.

Virtualization is made possible by the excessive size of the hardware architectures in use today than those that are normal and most common uses of computers. The uses of virtualization is probably the most popular operating system virtualization to create virtual servers for test server to support the development, or creating websites. In the context of virtualization, there are two different systems, host and guest. The host system is the system that is running a virtualization software that creates a high level the different virtual machines, which function as if they were normal programs, communicating with the hardware only indirectly, through virtualization software that works at low level. The operating systems running within each virtual machine guest are defined.

Types of Virtualization

It is possible to distinguish different types of virtualization, depending on how you run the virtual system. In particular, it distinguishes between:

Full virtualization also known as native : The characteristic of this mode is the presence of a hypervisor that implements the separation between the host system and the physical hardware of the machine, creating an insulation between the two domains. It is also identified as virtualization software, and a well-known example is the implementation of VirtualBox;

Paravirtualization : The control software exports an API to the hypervisor, which allows access to different hardware resources to the host system. This mode is implemented by the KVM virtualization;

Emulation : The control of software emulates the underlying hardware for the host system. This type of virtualization is slower than the other two, since all operations at the level of machine language must be translated by the instruction format of the host system to the guest system.

The virtual extensions from Intel and AMD

Intel and AMD have independently developed virtualization extensions to the x86 architecture, natively integrated in the set of instructions from their CPU, and these extensions are not fully compatible with each other, but support roughly the same instructions. The added value of this selection technique is that the Intel / AMD with support for these extensions allow for virtualization management in hardware, resulting in gains in performance, because a virtual machine that has to emulate a hardware for a host operating system with access to this set of instructions on the CPU, will reduce the computational load on the CPU and no longer having to emulate the entire system in software.

The virtualization extensions developed by Intel for the x86 32-bit (IA-32) and 64-bit (EM64T) is available on all Pentium 4 6×2, Pentium D 9×0, Xeon 7xxx, Core Duo and Core 2 Duo except for the T5200, T5500, E4300, E4400, E4500 and E4600.

AMD processors that use the Socket AM2, Socket S1, and Socket F AMD Virtualization support, including the Athlon 64, Turion 64 and Opteron.

KVM and QEMU Virtualization to 100% in Linux

KVM (Kernel-based Virtual Machine) is open source software, which allows for a full virtualization solution for Linux on x86 hardware that supports virtualization extensions such as Intel VT or AMD-V.

Each virtual machine has its own private virtualized hardware, such as network card, disk, graphics card, without going to touch the guest system. KVM is a kernel module, in a separate part that acts as a core infrastructure virtualization, and then the specific part for the guest of Intel or AMD CPU; modules are intel.ko-kvm and kvm-amd.ko . The module includes a char driver who is responsible for directing the control of I/O from the guest kernel to the host system.

The KVM package includes a modified version of QEMU which makes use of this form. QEMU is a processor emulator that is capable of emulating several hardware architectures, including x86, x86_64, ARM, SPARC, PowerPC, and MIPS.

The system hardware is emulated guest dynamically by examining the code executed within the virtual machine and translate it into instructions comprehensible to the guest machine. Modified QEMU is much faster and with higher performance, because of the KVM uses processor extensions for virtualization and the original emulates the ioctl.

The host, however, is bound to the x86, x86_64 and PowerPC. In the case of the x86 architecture there is an accelerator (kqemu) able to avoid the dynamic translation of instructions, allowing you to achieve performance that is around 30-50% of those of the guest.

Using KVM, one can have multiple virtual machines running simultaneously. The kernel component of KVM is included in mainline Linux kernel since 2.6.20.

Preparing for Installation of KVM

From all this it is clear that KVM is necessary to run the CPU support virtualization natively. You can test whether there is support in a simple way from the console with the command

root @ User-VirtualBox: ~ # egrep-c ‘(vmx | svm)’ / proc / cpuinfo

If the answer is 0 means that the CPU does not support hardware virtualization, but if the answer is a virtualization is supported , but you must verify that the BIOS option is enabled for virtualization or not. Some computers have disabled the possibility to use the virtualization extensions of the processor, in this case, go into the BIOS and enable the use.

Installing KVM requires some precautions, especially for the amount of memory that will be allocated to the host system. Indeed, there is a limit to the amount of memory you can dedicate to the virtual system, and adopted at a maximum of 2 GB by installing a 32-bit kernel, over 2 GB with a 64-bit kernel.

This choice implies, therefore a 64-bit virtual machines can accommodate 64-bit and 32 bit, instead of a 32-bit system is limited to only being able to accommodate 32-bit virtual machines. Obviously a 64-bit kernel requires a processor from the same surface area, which can be verified very simply with the command:

User-root @ server1: ~ # grep ‘lm’ / proc / cpuinfo

lm stands for long if this command mode does not provide any response means that the CPU is 64 bit. Instead, to verify that you are running a 64-bit kernel can use a command like the classic;

User-root @ server1: ~ # uname-m

the result indicates the type of processor, in particular, the term x86_64 from information that you are using a 64-bit kernel, while the abbreviations i386, i486, i586 or i686, indicate that you are using a 32-bit kernel .

Installing KVM

Installing Ubuntu in a 10.10, as always, is helped by magical apitude, which will install and prepare everything you need:

User-root @ server1: ~ # apt-get install libvirt-bin kvm qemu-ubuntu-vm-builder bridge-utils virt-viewer

Specifically, the packages that are installed with this process are described below:

  • qemu-kvm is the backend, that is the real core that creates and manages virtual machines;
  • libvirt-bin daemon provides libvirtd required to administer instances of using kvm and qemu libvirt ubuntu-vm-builder is a command line tool, very powerful, used for creating virtual machines;
  • bridge-utils provides a bridge between a network and the virtual machine to allow communication with the real external world;
  • virt-viewer, you see instances of virtual machines

After completing the installation process it is necessary to have an image of the host system to boot. To create an image, simply use the command qemu-img that is in the directory / usr / local / kvm / bin /:

User-root @ server1: ~ # / usr / local / kvm / bin / qemu-img create-f qcow
filename.img 3000M

after which you can launch and use QEMU:

User-root @ server1: ~ # / usr / local / kvm / bin / qemu

In conclusion

Virtualization is a very complex and extensive that it cannot be exhausted in a few lines. We have just taken a little ‘dust from one topic that often scares in an excessive way, because it is relatively young, and because often, virtualization is introduced as a concept, we speak of the creation of virtual systems, but do not expose those added values and benefits of using a virtual system in daily use.

The return on investment is due to the use of a virtual server, thanks to excessive size of current systems than those that are with the daily workload. Virtualization allows you to use hardware resources more efficiently, to create virtual networks internal to a single computer, to test software, attacks and their methods of defense in a safe environment without compromising the guest.

Also the possibility to migrate a virtual machine from one guest to another, in a simple way you can start services that would normally take longer because of the need to find a dedicated server hardware, thus the mobility of users and the portability achieve greater added value.

I personally think that the ability to run applications and systems are no longer supported, developed for different hardware and thus have no need for a high number of physical servers in addition to the charges involve in a significant investment in space, and still being able to eliminate the dual boot and to use as Windows and Linux simultaneously on the desktop and laptop to communicate the two systems as if they were on a real network, has paid off all efforts to push virtualization to the degree of maturity that has reached today.

ESDS

Leave a Reply