Russian-language documentation for Ubuntu. RedHat finally switches from Xen to KVM Setting up a kvm virtual machine on Linux

03.05.2023

KVM- one of the new virtualization technologies, which makes it possible to install several virtual dedicated servers on a physical dedicated server. The main advantage of this virtualization system is the creation of a VPN with different types operating systems, that is, you can install both linux vps and windows vps on one server without any problems. In addition, each individual VPS server on the KVM platform has its own independent resources: its own disk space, its own RAM, network interface, and so on.

Advantages of KVM virtualization:

  • Possibility to install different OS: centos, debian, ubuntu, mint, freebsd, windows 7, windows 8, windows 10, windows xp and so on.
  • Guaranteed resources on the server, that is, if you ordered a VPS server with certain resources, then rest assured, no one will take the resources away from you. With this virtualization, you cannot use the resources of a neighboring VPS. There is such a thing as overselling, this is when a hosting company sells more resources than are actually on the server. This cannot happen in KVM; all resources are clearly recorded in configuration files and all are sent at once to a virtual dedicated server.
  • It is possible to install your entire operating system on the VPS server, for example, you are an OS developer and you have your own written operating system, you can install it on one of the VPS on a server with KVM, for this you will need to upload a file with an iso image of the OS to server with a special folder.
  • Convenient work with VNC, which makes it possible to remotely manage your vps server as if you were working on your personal PC, using VNC you can configure the bios, reboot the VPS and watch it. If you have installed a Windows server on the VPS and want to go to it and work in graphical mode, then you can do this in two ways: via VNC, or directly get to the VPS via a pre-configured remote desktop.

One of the disadvantages of KVM virtualization is that it is more difficult to use and configure than, for example, openVZ virtualization. So what's the option? If you plan to use a VPS server with Linux operating systems, then we recommend choosing openVZ. If you are planning to use Windows on your virtual dedicated server, then it is better to use KVM virtualization.

Please enable JavaScript to view the comments powered by Disqus.
Recent Posts
  • The use of the latest passenger and freight lifts allows us to provide optimal circumstances...

  • To ensure that your website always opens using the harmless https:// protocol, we...

  • In new versions Chrome browser Scrolling the page with the wheel stopped working...

  • Internet trade in Ukraine is gaining more and more every year...

  • HTP is an IT direction in Belarus that was created...

  • In Ukraine, namely in Dnepropetrovsk, the 1st...

  • Now it’s hard to imagine a world without IT, because...

  • We present to your attention a new service on the website abcname.com.ua. Besides,…

  • Today we will tell you about the features of choosing a VPS server. First…

  • Today we are in a hurry to please everyone new opportunity our unique, and...

  • 1) Checking the domain name We check whether the string is the correct domain...

  • You can check the IP address on this page: http://abcname.com.ua/index.php?c=192 IP address (literally, then...

  • ABCname company presents to your attention the SYNONYMIZER program. Link to synonymizer: https://abcname.net/news-new/sinonimizator-ru.html…

  • You can download the visit counter developed by ABCname by following this link: http://abcname.com.ua/stat/…

  • IN latest update operating room iOS systems The developers closed 9.0.2 very...

  • Last news Skype: for users of this program on Windows...

  • Google once again pleased us with its invention, recently in the city...

  • Recently it became known that Samsung is launching a new payment…

  • In new ThinkPad laptops from Lenovo, which are pre-installed...

  • Pebble recently developed new series smart watch under…

  • I am writing this note to demonstrate step-by-step installation and setting up a KVM-based virtual machine in Linux. I previously wrote about virtualization, where I used the wonderful .

    Now I am faced with the question of renting a good server with a large capacity random access memory and a large hard drive. But I don’t want to run projects directly on the host machine, so I will separate them into separate small virtual servers running Linux or Docker containers (I’ll talk about them in another article).

    All modern cloud hostings work on the same principle, i.e. a hoster on good hardware raises a bunch of virtual servers, which we used to call VPS/VDS, and distributes them to users, or automates this process (hello, DigitalOcean).

    KVM (kernel-based virtual machine) is software for Linux, using x86-compatible processor hardware to work with Intel VT/AMD SVM virtualization technology.

    Installing KVM

    I will carry out all the machinations of creating a virtual machine on Ubuntu 16.04.1 LTS OS. To check whether your processes support hardware virtualization based on Intel VT/AMD SVM, run:

    Grep -E "(vmx|svm)" /proc/cpuinfo

    If the terminal is not empty, then everything is in order and KVM can be installed. Ubuntu officially supports only the KVM hypervisor (part of the Linux kernel) and recommends using the libvirt library as a tool for managing it, which is what we will do next.

    You can also check hardware virtualization support in Ubuntu using the command:

    If successful, you will see something like this:

    INFO: /dev/kvm exists KVM acceleration can be used

    Install packages for working with KVM:

    Sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils

    If you have access to the system's graphical shell, you can install the libvirt GUI manager:

    Sudo apt-get install virt-manager

    Using virt-manager is quite simple (no more difficult than VirtualBox), so in this article we will talk about the console option for installing and configuring a virtual server.

    Installing and configuring a virtual server

    In the console version of installation, configuration and system management, an indispensable tool is the virsh utility (an add-on to the libvirt library). She has a large number of options and parameters, detailed description can be obtained like this:

    Man virsh

    or call the standard "help":

    Virsh help

    I always adhere to the following rules when working with virtual servers:

    1. I keep iso images OS in /var/lib/libvirt/boot directory
    2. I store virtual machine images in the /var/lib/libvirt/images directory
    3. I explicitly assign each new virtual machine its own static IP address via the hypervisor’s DHCP server.

    Let's start installing the first virtual machine (64-bit server Ubuntu 16.04 LTS):

    Cd /var/lib/libvirt/boot sudo wget http://releases.ubuntu.com/16.04/ubuntu-16.04.1-desktop-amd64.iso

    After downloading the image, start the installation:

    Sudo virt-install \ --virt-type=kvm \ --name ubuntu1604\ --ram 1024 \ --vcpus=1 \ --os-variant=ubuntu16.04 \ --hvm \ --cdrom=/var/ lib/libvirt/boot/ubuntu-16.04.1-server-amd64.iso \ --network network=default,model=virtio \ --graphics vnc \ --disk path=/var/lib/libvirt/images/ubuntu1604. img,size=20,bus=virtio

    Translating all these parameters into “human language”, it turns out that we are creating a virtual machine with Ubuntu 16.04 OS, 1024 MB of RAM, 1 processor, a standard network card (the virtual machine will access the Internet as if due to NAT), 20 GB HDD.

    It is worth paying attention to the parameter --os-variant, it tells the hypervisor which OS the settings should be adapted to.
    A list of available OS options can be obtained by running the command:

    Osinfo-query os

    If such a utility is not on your system, then install:

    Sudo apt-get install libosinfo-bin

    After starting the installation, the following message will appear in the console:

    Domain installation still in progress. You can reconnect to the console to complete the installation process.

    This is a normal situation, we will continue the installation via VNC.
    Let's look at which port it was raised on our virtual machine (in the next terminal, for example):

    Virsh dumpxml ubuntu1604... ...

    Port 5900, on local address 127.0.0.1. To connect to VNC, you need to use Port Forwarding via ssh. Before doing this, make sure that tcp forwarding is enabled in the ssh daemon. To do this, go to the sshd settings:

    Cat /etc/ssh/sshd_config | grep AllowTcpForwarding

    If nothing was found or you see:

    AllowTcpForwarding no

    Then we edit the config to

    AllowTcpForwarding yes

    and reboot sshd.

    Setting up port forwarding

    We execute the command on the local machine:

    Ssh -fN -l login -L 127.0.0.1:5900:localhost:5900 server_ip

    Here we have configured ssh port forwarding from local port 5900 to server port 5900. Now you can connect to VNC using any VNC client. I prefer UltraVNC because of its simplicity and convenience.

    After successful connection, the screen will display standard window greetings for starting Ubuntu installation:

    After the installation is complete and the usual reboot, the login window will appear. After logging in, we determine the IP address of the newly created virtual machine in order to later make it static:

    Ifconfig

    We remember and go to the host machine. We pull out the mac address of the virtual machine’s “network” card:

    Virsh dumpxml ubuntu1604 | grep "mac address"

    Let's remember our mac address:

    Editing network settings hypervisor:

    Sudo virsh net-edit default

    We look for DHCP and add this:

    It should look something like this:

    In order for the settings to take effect, you need to restart the DHCP server of the hypervisor:

    Sudo virsh net-destroy default sudo virsh net-start default sudo service libvirt-bin restart

    After this, we reboot the virtual machine, now it will always have the IP address assigned to it - 192.168.122.131.

    There are other ways to set a static IP for a virtual machine, for example, by directly editing the network settings inside the guest system, but here it’s whatever your heart desires. I just showed the option that I prefer to use.

    To connect to the virtual machine terminal, run:

    Ssh 192.168.122.131

    The car is ready for battle.

    Virsh: command list

    To view running virtual hosts (all available ones can be obtained by adding --all):

    Sudo virsh list

    You can reboot the host:

    Sudo virsh reboot $VM_NAME

    Stop a virtual machine:

    Sudo virsh stop $VM_NAME

    Execute halt:

    Sudo virsh destroy $VM_NAME

    Sudo virsh start $VM_NAME

    Disable:

    Sudo virsh shutdown $VM_NAME

    Add to autorun:

    Sudo virsh autostart $VM_NAME

    Very often it is necessary to clone a system in order to use it in the future as a framework for other virtual operating systems; for this, the virt-clone utility is used.

    Virt-clone --help

    It clones an existing virtual machine and changes host-sensitive data, for example, mac address. Passwords, files and other user-specific information in the clone remain the same. If the IP address on the cloned virtual machine was registered manually, then problems may arise with SSH access to the clone due to a conflict (2 hosts with the same IP).

    In addition to installing a virtual machine via VNC, it is also possible to use X11Forwarding through the virt-manager utility. On Windows, for example, you can use Xming and PuTTY for this.

    When choosing a tariff, a person also chooses the virtualization method for the server. We offer a choice of virtualization at the operating system level OpenVZ and hardware virtualization KVM.

    It is impossible to change the type of virtualization after launch, since the servers are on different hardware platforms. You will have to order a new server, transfer the project and abandon the old server.

    Comparison of virtualization types

    OpenVZ KVM

    OS from a number of proposed ones: Debian, CentOS, Ubuntu

    Linux, Windows, FreeBSD, installing your own distribution

    Changing resources without rebooting ( HDD, memory, processor)

    Memory and processor will change after a reboot, hard drive - only after contacting support (memory cannot be changed on ready-made plans)

    Change tariff plan without reboot

    Changing the tariff plan. The server will be unavailable for 1-2 hours.

    Soft limits: maximum performance server may deviate up or down

    Hard limits: each server receives the declared resources

    Restriction on launching high-load projects. It is prohibited to run Java applications, mass mailings, or proxy traffic. TUN/TAP is disabled.

    Ability to run any projects (except distributed computing systems)

    Opportunity . For this type of virtualization, connecting to the GUI via VNC is not possible.

    Opportunity . If for some reason the server is not accessible via SSH or you need to connect to the graphical interface, you can access the server via VNC.

    You can go to the ISPmanager control panel:

    • from Personal account: section - Products - Virtual servers - select a server, “Go” button at the top,
    • follow the link from the Instructions: Personal account - Products - Virtual servers - select the server, at the top “Instructions”.

    OpenVZ virtualization

    OpenVZ - operating system level virtualization. The technology is based on the Linux OS kernel and allows you to create and run copies isolated from each other selected operating system (Debian, CentOS, Ubuntu). Installing another OS is not possible, since the virtual servers use a common Linux kernel.

    The technology is different ease of server management: the user can independently * add more resources (memory, processor, hard drive) or switch to another plan with the same virtualization. Changes are applied automatically, without rebooting the server.

    On servers with OpenVZ virtualization prohibited run:

    • services for organizing proxying of any type of traffic
    • streaming services
    • game servers
    • systems or elements of distributed computing systems (for example, bitcoin mining)
    • Services mass mailing email messages, even if they are used for legal purposes
    • Java applications
    • other resource-intensive applications

    Such projects create an uneven load on the parent server and can interfere with neighboring virtual machines.

    * - for previous versions of tariffs (VDS-2015, VDS-Summer, VDS-2016), changing the tariff in your personal account is no longer available. Independent change of the tariff plan is possible only on the current OVZ virtualization tariffs. If it is important for you to have access to quick management of server resources, switch to the current tariff plan. If the cost of the new tariff is higher than the cost of the current one, the tariff change is free of charge, in other cases - within the framework. The tariff changes without rebooting the server.

    KVM virtualization

    KVM (Kernel-based Virtual Machine) is a hardware virtualization technology that allows you to create full virtual analogue physical server . KVM allows you to create a virtual server completely isolated from its “neighbors” with its own OS kernel, which the user can customize and modify to suit their own needs without restrictions. Each such server is allocated its own area in RAM and hard disk space, which increases the overall reliability of such a server.

    Installation possible any operating system to choose from (Debian, CentOS, Ubuntu, FreeBSD, Windows Server), or installing your own distribution (in the VMmanager panel, in the ISO images section, click the Create button and add your system ISO image).

    Change of tariff plan is possible only in a larger direction and only within the framework of the basic line of tariffs (Start, Acceleration, Breakaway, Fly away). If your project “grows” beyond the tariff, write a support request from your Personal Account - administrators will change the tariff to the required one free of charge. Change tariff downward You can only transfer it to a new server. Order a new server and transfer the data yourself, or specialists technical support They will help with the transfer for 1 request for the administration package or 250 rubles.

    Remember that on the VDS-Forsazh and VDS-Atlant tariffs, you can change resources instead of changing the tariff: the number of available processor cores and RAM independently in the control panel, and the size hard drive- after contacting support (as part of administration or for 250 rubles).

    Considering the features and advantages that KVM virtualization provides, it tariffs are more expensive similar tariffs with OpenVZ virtualization.

    On servers with KVM virtualization, the Subscriber is prohibited from placing systems or elements of distributed computing systems (for example, bitcoin mining).

    Changing virtualization on the server

    It is impossible to change virtualization from OpenVZ to KVM and vice versa within the same server.

    1. Order a second server with the required virtualization in the BILLmanager panel, section Virtual servers → Order

    2. Transfer data to it.

    3. After transfer and verification old server can be deleted (Virtual servers → Delete).


    Let's say you are a young, but still poor student, which means that of all possible platforms you only have a PC on Windows and PS4. One fine day you decide to come to your senses and become a programmer, but wise people on the Internet told you that you cannot become a normal engineer without Linux. You cannot install Fedora as your main and only system, because Windows is still needed for games and VKontakte, and fear or lack of experience prevents you from installing Linux as a second system on your hard drive.

    Or, let’s say, you have already grown up, now you are the head of servers in a large company, and one fine day you notice that most of the servers are not even half loaded. You cannot place more applications and data on servers for security reasons, and the costs of supporting and maintaining a growing server farm are rapidly increasing.

    Or, let’s say, you already have a beard and glasses, you’re a technical director, and you’re not happy that it takes two months for developers to get a new server to deploy a new application. How to move forward quickly in such conditions?

    Or maybe you are an architect who designed a new complex system for processing business analytics. Your system includes things like ElasticSearch, Kafka, Spark and much more, and each component must live separately, be configured intelligently and communicate with other components. As a good engineer, you understand that it is not enough to simply install this entire zoo directly on your system. You need to try to deploy an environment as close as possible to the future production environment, and preferably so that your developments will then work seamlessly on production servers.

    And what to do in all these difficult situations? Correct: use virtualization.

    Virtualization allows you to install many operating systems completely isolated from each other and running side by side on the same hardware.

    A little history. The first virtualization technologies appeared already in the 60s, but the real need for them appeared only in the 90s, as the number of servers grew more and more. It was then that the problem arose of effectively recycling all the hardware, as well as optimizing the processes of updating, deploying applications, ensuring security and restoring systems in the event of a disaster.

    Let's leave behind the scenes the long and painful history of the development of various technologies and methods of virtualization - for the curious reader, at the end of the article there will be additional materials on this topic. The important thing is what it all ultimately came to: three main approaches to virtualization.

    Approaches to virtualization

    Regardless of the approach and technology, when using virtualization there is always a host machine and a hypervisor installed on it that controls the guest machines.

    Depending on the technology used, a hypervisor can be either separate software installed directly on the hardware, or part of the operating system.

    An attentive reader who loves buzzwords will start muttering in a couple of paragraphs that his favorite Docker containers are also considered virtualization. We’ll talk about container technologies another time, but yes, you’re right, attentive reader, containers are also some kind of virtualization, only at the resource level of the same operating system.

    There are three ways for virtual machines to interact with hardware:

    Dynamic broadcast

    In this case, the virtual machines have no idea that they are virtual. The hypervisor intercepts all commands from the virtual machine on the fly and processes them, replacing them with safe ones, and then returns them back to the virtual machine. This approach obviously suffers from some performance issues, but it allows you to virtualize any OS, since the guest OS does not need to be modified. Dynamic translation is used in VMWare products, the leader in commercial virtualization software.

    Paravirtualization

    In the case of paravirtualization source the guest OS is specially modified so that all instructions are executed as efficiently and safely as possible. At the same time, the virtual woman is always aware that she is a virtual woman. One of the benefits is improved performance. The downside is that this way you cannot virtualize, for example, MacOS or Windows, or any other OS to which you do not have access to the source code. Paravirtualization in one form or another is used, for example, in Xen and KVM.

    Hardware virtualization

    Processor developers realized in time that the x86 architecture is poorly suited for virtualization, since it was initially designed for one OS at a time. Therefore, after dynamic translation from VMWare and paravirtualization from Xen appeared, Intel and AMD began to release processors with hardware support for virtualization.

    At first, this did not provide much of a performance boost, since the main focus of the first releases was improving the processor architecture. However, now, more than 10 years after the advent of Intel VT-x and AMD-V, hardware virtualization is in no way inferior and even in some ways superior to other solutions.

    Hardware virtualization uses and requires KVM (Kernel-based Virtual Machine), which we will use in the future.

    Kernel-based Virtual Machine

    KVM is a virtualization solution built right into the Linux kernel that is as functional as other solutions and superior in usability. Moreover, KVM is an open source technology, which, nevertheless, is moving forward at full speed (both in terms of writing code and in terms of marketing) and is being implemented into its products by Red Hat.

    This, by the way, is one of the many reasons why we insist on Red Hat distributions.

    The creators of KVM initially focused on supporting hardware virtualization and did not reinvent many things. A hypervisor, in essence, is a small operating system that must be able to work with memory, networking, etc. Linux already knows how to do all this perfectly, so using the Linux kernel as a hypervisor is logical and beautiful technical solution. Each KVM virtual machine is just a separate Linux process, security is provided using SELinux/sVirt, resources are managed using CGroups.

    We'll talk more about SELinux and CGroups in another article, don't be alarmed if you don't know these words.

    KVM doesn't just work as part of the Linux kernel: since kernel version 2.6.20, KVM has been a core component of Linux. In other words, if you have Linux, then you already have KVM. Convenient, right?

    It is worth saying that in the field of public cloud platforms, Xen dominates a little more than completely. For example, AWS EC2 and Rackspace use Xen. This is due to the fact that Xen appeared earlier than everyone else and was the first to achieve a sufficient level of performance. But there is good news: in November 2017, which will gradually replace Xen for the largest cloud provider.

    Although KVM uses hardware virtualization, for some I/O device drivers KVM can use paravirtualization, which provides performance gains for certain use cases.

    libvirt

    We have almost reached the practical part of the article, all that remains is to consider another open source tool: libvirt.

    libvirt is a set of tools that provides a single API to many different virtualization technologies. Using libvirt, in principle, it doesn’t matter what the “backend” is: Xen, KVM, VirtualBox or something else. Moreover, you can use libvirt inside Ruby (and also Python, C++ and much more) programs. You can also connect to virtual machines remotely via secure channels.

    By the way, libvirt is being developed by Red Hat. Have you already installed Fedora Workstation as your main system?

    Let's create a virtual machine

    libvirt is just an API, but it is up to the user how to interact with it. There are a lot of options. We will use several standard utilities. We remind you: we insist on using Red Hat distributions (CentOS, Fedora, RHEL) and the commands below were tested on one of these systems. There may be slight differences for other Linux distributions.

    First, let's check whether hardware virtualization is supported. In fact, it will work without its support, only much slower.

    egrep --color = auto "vmx|svm|0xc0f" /proc/cpuinfo # if nothing is displayed, then there is no support :(

    Since KVM is a Linux kernel module, you need to check whether it is already loaded, and if not, then load it.

    lsmod | grep kvm # kvm, kvm_intel, kvm_amd. If nothing is displayed, then you need to load the necessary modules # If the module is not loaded modprobe kvm modprobe kvm_intel # or modprobe kvm_amd

    It is possible that hardware virtualization is disabled in the BIOS. Therefore, if the kvm_intel/kvm_amd modules are not loaded, then check the BIOS settings.

    Now let's install the necessary packages. The easiest way to do this is to install a group of packages at once:

    yum group list "Virtual*"

    The list of groups depends on the OS used. My group was called Virtualization. To manage virtual machines from the command line, use the virsh utility. Check if you have at least one virtual machine using the virsh list command. Most likely no.

    If you don’t like the command line, then there is also virt-manager - a very convenient GUI for virtual machines.

    virsh can create virtual machines only from XML files, the format of which can be studied in the libvirt documentation. Fortunately, there is also virt-manager and the virt-install command. You can figure out the GUI yourself, but here is an example of using virt-install:

    sudo virt-install --name mkdev-vm-0 \ --location ~/Downloads/CentOS-7-x86_64-Minimal-1511.iso \ --memory = 1024 --vcpus = 1 \ --disk size = 8

    Instead of specifying the disk size, you can create it in advance through virt-manager, or through virsh and an XML file. I used the above image from Centos 7 minimal, which is easy to find on the Centos website.

    Now one important question remains: how to connect to the created machine? The easiest way to do this is through virt-manager - just double-click on the created machine and a window with a SPICE connection will open. The OS installation screen awaits you there.

    By the way, KVM can nested virtualization: virtual machines inside a virtual machine. We need to go deeper!

    After you install the OS manually, you will immediately wonder how this process can be automated. To do this, we need a utility called Kickstart, designed to automatically configure the OS for the first time. This is a simple text file in which you can specify the OS configuration, down to various scripts that are executed after installation.

    But where can I get such a file? Why not write it from scratch? Of course not: since we have already installed Centos 7 inside our virtual machine, we just need to connect to it and find the file /root/anaconda-ks.cfg - this is the Kickstart config in order to create a copy of the already created OS. You just need to copy it and edit the contents.

    But just copying a file is boring, so we'll add something else to it. The fact is that by default we will not be able to connect to the console of the created virtual machine from the command line of the host machine. To do this, you need to edit the GRUB boot loader config. Therefore, at the very end of the Kickstart file we will add the following section:

    %post --log = /root/grubby.log /sbin/grubby --update-kernel = ALL --args = "console=ttyS0" %end

    %post , as you might guess, will be executed after the OS is installed. The grubby command will update the GRUB config to add the ability to connect to the console.

    By the way, you can also specify the ability to connect via the console right during the creation of the virtual machine. To do this, you need to pass one more argument to the virt-install command: --extra-args="console=ttyS0" . After this, you can install the OS itself in interactive text mode from the terminal of your host machine, connecting to the virtual machine via virsh console immediately after its creation. This is especially convenient when you create virtual machines on a remote hardware server.

    Now you can apply the created config! virt-install allows you to pass additional arguments when creating a virtual machine, including the path to the Kickstart file.

    sudo virt-install --name mkdev-vm-1 \ --location ~/Downloads/CentOS-7-x86_64-Minimal-1511.iso \ --initrd-inject /path/to/ks.cfg \ --extra- args ks = file:/ks.cfg \ --memory = 1024 --vcpus = 1 --disk size = 8

    After the second virtual machine is created (fully automatically), you can connect to it from the command line using the virsh console vm_id command. vm_id You can find out from the list of all virtual machines using the virsh list command.

    One of the benefits of using KVM/libvirt is the amazing documentation, including that produced by Red Hat. The dear reader is invited to study it with due curiosity.

    Of course, creating virtual machines like this manually in the console, and then setting them up only using Kickstart is not the most convenient process. In future articles, we will look at many cool tools that make system configuration easier and completely automated.

    What's next?

    It is impossible to fit everything worth knowing about virtualization into one article. We looked at several options for using virtualization and its advantages, delved a little deeper into the details of its operation and got acquainted with the best, in our opinion, solution for these tasks (KVM), and even created and configured a virtual machine.

    It is important to understand that virtual machines are the building blocks of modern cloud architectures. They allow applications to automatically grow to unlimited sizes, maximizing in a fast way and with maximum utilization of all resources.

    No matter how powerful and rich in services AWS is, its foundation is virtual machines on top of Xen. Every time you create a new droplet on DigitalOcean, you are creating a virtual machine. Almost all the sites you use are hosted on virtual machines. The simplicity and flexibility of virtual machines allows not only to build production systems, but also makes local development and testing ten times easier, especially when the system involves many components.

    We learned how to create one single machine - not bad for testing one application. But what if we need several virtual machines at once? How will they communicate with each other? How will they find each other? To do this, we will need to understand how networks generally work, how they work in the context of virtualization, and which components are involved in this work and need to be configured - in the next article in the series.

    Today it is difficult to imagine a world without computerized devices. About 20 years ago, almost all household appliances were electro-mechanical, about use computer circuits everywhere there was not even a word. The very first computers took up significant amounts of space and could do relatively little. Computer systems for Lately have come quite a long way of development. Although computers have not changed fundamentally, computing power has increased rapidly. Having a computer in a simple family is no longer something special.

    At the moment, often a large number of computer equipment in the premises can cause significant inconvenience. For this reason, centralized systems began to appear. But centralized systems often cannot solve the problems that a network of computers solves. For this reason, the concept of virtualization was proposed, when one central computer acts as a network of computers.

    At its core, all operating systems are, in general, some kind of virtual environment that is provided to the software developer as a means of implementing final tasks. The time has long passed when programs were written specifically for computer hardware using hardware codes and queries. Today, any application is, first of all, an application written on some API, which is controlled by the OS. The task of the OS is to provide these APIs with direct access to hardware resources.

    There are actually several types of virtualization:

    • Software virtualization;
    • Hardware virtualization;
    • Operating system level virtualization.

    Virtualization, in turn, happens full And partial.

    Software virtualization– a type of virtualization that uses various OS libraries, translating virtual machine calls into OS calls. (DOSBox, Virtualbox, VirtualPC)

    Hardware virtualization- a type that provides specialized hardware instructions, specifically processor instructions. Allows you to execute queries bypassing the guest OS, and execute them directly on the hardware. (KVM virtualization, XEN virtualization, Parallels, VMware, Virtualbox)

    Operating system level virtualization– virtualization of only part of the platform, without complete virtualization of the hardware. Implies the operation of several instances of the OS environment. (Docker, LXC)

    This article will consider Hardware virtualization, and specifically KVM virtualization.

    Scheme 1. – Interaction of virtual machine components with hardware

    Features of virtualization for the Linux kernel

    To execute direct hardware requests, the OS must have a library that would send these requests to the hardware directly. For a long time, on Linux-based platforms, no built-in virtualization system (built-in hypervisor) simply existed. Each virtualization software manufacturer that supported hardware virtualization technology was forced to create their own modules for the Linux kernel (vboxdrv in Virtualbox, vmware-service in VMWare, etc.) Naturally, this could not last forever, and Qumranet, Inc., which was then bought out Radhat created the Open Virtualization Alliance, which was considered to solve the problem of the lack of a basic hypervisor for the Linux kernel. That's how it was created hypervisor KVM or Kernel-based Virtual Machine.

    Implementation

    The KVM hypervisor is a loadable Linux kernel module that is designed to provide virtualization on the Linux x86 platform. The module itself contains the virtualization component itself (kvm.ko), and the processor-specific loadable module kvm-amd.ko or kvm-intel.ko.

    A prerequisite for using KVM is support for virtualization instructions - Intel VT or AMD, and Linux kernel version 2.6.20 and higher. There is also a KVM port for Free-BSD. QEMU is traditionally used to invoke KVM, but there are also efforts to add KVM support to Virtualbox.

    KVM itself does not perform emulation. Instead, the program running in user space uses the /dev/kvm interface to configure the address space of the virtual machine guest, and through it emulates I/O devices and the video adapter.

    KVM allows virtual machines to use unmodified disk images of QEMU, VMware and others containing operating systems. Each virtual machine has its own virtual hardware: network cards, disk, video card and other devices.

    Usage

    There are many implementations for using this hypervisor. Some are entire specialized libraries, others take the form of simple graphical applications.

    For clarity, we consider KVM virtualization based on the library virt-manager.

    This library allows you to simplify the call of various hypervisors, providing a convenient interface for automating the virtualization process. In addition, the library has the ability to work with network infrastructure, which is sometimes important when building client-server workstations.

    Scheme 2. – Interaction of libvirt components

    QEMU allows you to create a frame for calling the hypervisor on the client system. This program configured by call arguments command line, is quite easy and simple.

    There are also several graphical shells, such as Gnome-Boxes.

    Conclusion

    Virtualization is an integral part of modern corporate systems, it allows you to save enormous financial and energy resources. The development of virtualization technologies is a priority for many organizations. Technologies such as VGAPassthrough (technology for “forwarding” the host device’s video card into a virtual machine) and PCIPassthrough (“forwarding” a PCI device) are being developed.