Contacts

Setting up kvm virtualization on ubuntu 16.04. Working with KVM virtual machines. Introduction. Installing and configuring a virtual server

Personally, it’s easiest for me to think of KVM (Kernel-based Virtual Machine) as a level of abstraction over Intel VT-x and AMD-V hardware virtualization technologies. We take a machine with a processor that supports one of these technologies, install Linux on this machine, install KVM in Linux, and as a result we get the opportunity to create virtual machines. This is roughly how cloud hosting works, for example, Amazon Web Services. Along with KVM, Xen is also sometimes used, but a discussion of this technology is beyond the scope of this post. Unlike container virtualization technologies, for example, Docker, KVM allows you to run any OS as a guest system, but it also has O Higher overhead for virtualization.

Note: The steps described below were tested by me on Ubuntu Linux 14.04, but in theory they will be largely valid for both other versions of Ubuntu and other Linux distributions. Everything should work both on the desktop and on the server, accessed via SSH.

Installing KVM

We check whether Intel VT-x or AMD-V is supported by our processor:

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

If something gets hot, it means it is supported, and you can move on.

Installing KVM:

sudo apt-get update
sudo apt-get install qemu-kvm libvirt-bin virtinst bridge-utils

What is usually stored where:

  • /var/lib/libvirt/boot/ - ISO images for installing guest systems;
  • /var/lib/libvirt/images/ — images of hard drives of guest systems;
  • /var/log/libvirt/ - here you should look for all logs;
  • /etc/libvirt/ - directory with configuration files;

Now that KVM is installed, let's create our first virtual machine.

Creating the first virtual machine

I chose FreeBSD as the guest system. Download the ISO image of the system:

cd /var/lib/libvirt/boot/
sudo wget http:// ftp.freebsd.org/ path/ to/ some-freebsd-disk.iso

Virtual machines are managed in most cases using the virsh utility:

sudo virsh --help

Before launching the virtual machine, we will need to collect some additional information.

We look at the list of available networks:

sudo virsh net-list

View information about a specific network (named default):

sudo virsh net-info default

Let's look at the list of available optimizations for guest operating systems:

sudo virt-install --os-variant list

So, now we create a virtual machine with 1 CPU, 1 GB of RAM and 32 GB of disk space, connected to the default network:

sudo virt-install\
--virt-type =kvm\
--name freebsd10\
--ram 1024\
--vcpus=1\
--os-variant =freebsd8 \
--hvm\
--cdrom =/ var/ lib/ libvirt/ boot/ FreeBSD-10.2 -RELEASE-amd64-disc1.iso \
--network network =default,model =virtio \
--graphics vnc\
--disk path =/ var/ lib/ libvirt/ images/ freebsd10.img,size =32 ,bus =virtio

You can see:

WARNING Unable to connect to graphical console: virt-viewer not
installed. Please install the "virt-viewer" package.

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

This is normal, this is how it should be.

Then look at the properties of the virtual machine in XML format:

sudo virsh dumpxml freebsd10

The most complete information is provided here. This includes, for example, a MAC address, which we will need later. For now we are finding information about VNC. In my case:

Using your favorite client (I personally use Rammina), we log in via VNC, using SSH port forwarding if necessary. We get straight into the FreeBSD installer. Then everything is as usual - Next, Next, Next, we get the installed system.

Basic Commands

Let's now look at the basic commands for working with KVM.

Getting a list of all virtual machines:

sudo virsh list --all

Obtaining information about a specific virtual machine:

sudo virsh dominfo freebsd10

Launch virtual machine:

sudo virsh start freebsd10

Stop virtual machine:

sudo virsh shutdown freebsd10

Hardly nail the virtual machine (despite the name, this Not deletion):

sudo virsh destroy freebsd10

Reboot the virtual machine:

sudo virsh reboot freebsd10

Clone virtual machine:

sudo virt-clone -o freebsd10 -n freebsd10-clone \
--file /var/lib/libvirt/images/freebsd10-clone.img

Enable/disable autorun:

sudo virsh autostart freebsd10
sudo virsh autostart --disable freebsd10

Running virsh in dialog mode (all commands in dialog mode - as described above):

sudo virsh

Editing the properties of the virtual machine in XML, including here you can change the limit on the amount of memory, etc.:

sudo virsh edit freebsd10

Important! Comments from the edited XML are unfortunately removed.

When the virtual machine is stopped, the disk can also be resized:

sudo qemu-img resize /var/ lib/ libvirt/ images/ freebsd10.img -2G
sudo qemu-img info /var/lib/libvirt/images/freebsd10.img

Important! Your guest OS probably won't like the disk suddenly getting bigger or smaller. At best, it will boot into emergency mode with a proposal to repartition the disk. You probably shouldn't want to do that. It may be much easier to create a new virtual machine and migrate all the data to it.

Backup and restore are quite simple. It is enough to save the dumpxml output somewhere, as well as the disk image, and then restore them. On YouTube managed to find the video With a demonstration of this process, everything is really not difficult.

Network settings

An interesting question - how to determine what IP address the virtual machine received after loading? KVM does this in a clever way. I ended up writing this script in Python:

#!/usr/bin/env python3

# virt-ip.py script
# (c) 2016 Aleksander Alekseev
# http://site/

import sys
import re
import os
import subprocess
from xml .etree import ElementTree

def eprint(str) :
print(str, file = sys.stderr)

if len(sys.argv)< 2 :
eprint("USAGE: " + sys .argv [ 0 ] + " " )
eprint("Example: " + sys .argv [ 0 ] + " freebsd10" )
sys.exit(1)

if os .geteuid() != 0 :
eprint("ERROR: you should be root" )
eprint("Hint: run `sudo " + sys .argv [ 0 ] + " ...`" ) ;
sys.exit(1)

if subprocess .call ( "which arping 2>&1 >/dev/null", shell = True ) != 0 :
eprint("ERROR: arping not found" )
eprint( "Hint: run `sudo apt-get install arping`")
sys.exit(1)

Domain = sys.argv[1]

if not re .match ("^*$" , domain) :
eprint( "ERROR: invalid characters in domain name")
sys.exit(1)

Domout = subprocess .check_output ("virsh dumpxml " +domain+" || true" ,
shell = True)
domout = domout.decode("utf-8").strip()

if domout == "" :
# error message already printed by dumpxml
sys.exit(1)

Doc = ElementTree.fromstring(domout)

# 1. list all network interfaces
# 2. run `arping` on every interface in parallel
#3.grep replies
cmd = "(ifconfig | cut -d " " -f 1 | grep -E "." | " + \
"xargs -P0 -I IFACE arping -i IFACE -c 1 () 2>&1 | " + \
"grep "bytes from") || true"

for child in doc.iter() :
if child.tag == "mac" :
macaddr = child.attrib["address"]
macout = subprocess .check_output (cmd .format (macaddr) ,
shell = True)
print(macout.decode("utf-8"))

The script works with both the default network and the bridged network, the configuration of which we will consider later. However, in practice, it is much more convenient to configure KVM so that it always assigns the same IP addresses to guest systems. To do this, edit the network settings:

sudo virsh net-edit default

... something like this:

>



>

After making these changes


>

... and replace it with something like:




>

We reboot the guest system and check that it has received an IP via DHCP from the router. If you want the guest system to have a static IP address, this is configured as usual within the guest system itself.

virt-manager program

You may also be interested in the virt-manager program:

sudo apt-get install virt-manager
sudo usermod -a -G libvirtd USERNAME

This is what its main window looks like:

As you can see, virt-manager is not only a GUI for virtual machines running locally. With its help, you can manage virtual machines running on other hosts, as well as look at beautiful graphics in real time. I personally find it especially convenient in virt-manager that you don’t need to search through the configs to find out on which port VNC is running on a particular guest system. You just find the virtual machine in the list, double-click, and get access to the monitor.

With the help of virt-manager it is also very convenient to do things that would otherwise require labor-intensive editing of XML files and, in some cases, the execution of additional commands. For example, renaming virtual machines, setting CPU affinity and similar things. By the way, using CPU affinity significantly reduces the effect of noisy neighbors and the influence of virtual machines on the host system. Always use it if possible.

If you decide to use KVM as a replacement for VirtualBox, keep in mind that they will not be able to share hardware virtualization between themselves. For KVM to work on your desktop, you will not only have to stop all virtual machines in VirtualBox and Vagrant, but also reboot the system. I personally find KVM much more convenient than VirtualBox, at least because it doesn't require you to run a command sudo /sbin/rcvboxdrv setup after each kernel update, it works adequately with Unity, and generally allows you to hide all windows.

In this introductory article, I will briefly introduce all the software tools used in the service development process. They will be discussed in more detail in the following articles.

Why ? This operating system is close and understandable to me, so there was no torment, torment or tossing when choosing a distribution. It does not have any particular advantages over Red Hat Enterprise Linux, but the decision was made to work with a familiar system.

If you are planning to independently deploy an infrastructure using similar technologies, I would advise you to take RHEL: thanks to good documentation and well-written application programs, it will be, if not an order of magnitude, then certainly twice as simpler, and thanks to the developed certification system, you can easily will find a number of specialists who are familiar with this OS at the proper level.

We, again, decided to use Debian Squeeze with a set of packages from Sid/Experimental and some packages backported and compiled with our patches.
There are plans to publish a repository with packages.

When choosing virtualization technology, two options were considered - Xen and KVM.

Also, the fact that there was a huge number of developers, hosters, and commercial solutions based on Xen was taken into account - the more interesting it was to implement a solution based on KVM.

The main reason why we decided to use KVM is the need to run virtual machines with FreeBSD and, in the future, MS Windows.

To manage virtual machines, it turned out to be extremely convenient to use products that use its API: virsh, virt-manager, virt-install, etc.

This is a system that stores the settings of virtual machines, manages them, keeps statistics on them, makes sure that the interface of the virtual machine is raised when starting, connects devices to the machine - in general, it does a lot of useful work and a little more than that.

Of course, the solution is not ideal. The disadvantages include:

  • Absolutely insane error messages.
  • Inability to change part of the virtual machine configuration on the fly, although QMP (QEMU Monitor Protocol) allows this.
  • Sometimes, for some unknown reason, it is impossible to connect to libvirtd - it stops responding to external events.

The main problem in implementing the service at the very beginning was the limitation of resources for virtual machines. In Xen, this problem was solved with the help of an internal scheduler that distributes resources between virtual machines - and what’s best is that the ability to limit disk operations was also implemented.

There was nothing like this in KVM until the advent of the kernel resource allocation mechanism. As usual in Linux, access to these functions was implemented through a special file system cgroup, in which, using the normal write() system calls, one could add a process to a group, assign it its parrot weight, specify the core on which it will run, specify the disk bandwidth that the process can use, or, again, assign a weight to it.

The benefit is that all this is implemented inside the kernel, and it can be used not only for the server, but also for the desktop (which was used in the famous “The ~200 Line Linux Kernel Patch That Does Wonders”). And in my opinion, this is one of the most significant changes in the 2.6 branch, not counting my favorite #12309, and not the filing of another file system. Well, perhaps, except for POHMELFS (but purely because of the name).

My attitude towards this utility library is very ambiguous.

On the one hand it looks something like this:

And this thing is also damn difficult to assemble from source, much less into a package: sometimes it seems to me that Linux From Scratch is a little easier to build from scratch.

On the other hand, it is a very powerful thing that allows you to create images for virtual machines, modify them, compress them, install grub, modify the partition table, manage configuration files, transfer hardware machines to a virtual environment, transfer virtual machines from one image to another, transfer virtual machines from the image to hardware and, to be honest, here my imagination lets me down a little. Oh, yes: you can also run a daemon inside a Linux virtual machine and access the virtual machine data live, and do all this in shell, python, perl, java, ocaml. This is a short and by no means exhaustive list of what you can do with .

Interestingly, most of the code is generated at the time of assembly, as well as the documentation for the project. Ocaml and perl are widely used. The code itself is written in C, which is then wrapped in OCaml, and the repeated pieces of code are generated themselves. Working with images is carried out by launching a special service image (supermin appliance), to which commands are sent through a channel into it. This rescue image contains a certain set of utilities, such as parted, mkfs and others useful for a system administrator.

Recently I even started using it at home, when I extracted the data I needed from the nandroid image. But this requires a yaffs-enabled kernel.

Other

Below are some more interesting links to a description of the software used - read and study it yourself if you are interested. For example,

Checking hypervisor support

We check that the server supports virtualization technologies:

cat /proc/cpuinfo | egrep "(vmx|svm)"

You should get something like this in response:

flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperf mperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 popcnt aes lahf_lm epb tpr_shadow vnmi flexpriority ept vpid dtherm ida arat

Otherwise, go to the BIOS, find the option to enable virtualization technology (has different names, for example, Intel Virtualization Technology or Virtualization) and enable it - set the value Enable.

You can also check compatibility with the command:

* if the command returns an error "kvm-ok command not found", install the appropriate package: apt-get install cpu-checker.

If we see:

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

This means there is hardware support.

Preparing the server

For our convenience, we will create a directory in which we will store data for KVM:

mkdir -p /kvm/(vhdd,iso)

* two directories will be created: /kvm/vhdd(for virtual hard disks) and /kvm/iso(for iso images).

Let's set the time:

\cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime

* this command sets the zone in accordance with Moscow time.

ntpdate ru.pool.ntp.org

* We synchronize with the time server.

Installation and launch

We install KVM and the necessary management utilities.

a) Ubuntu up to version 18.10

apt-get install qemu-kvm libvirt-bin virtinst libosinfo-bin

b) Ubuntu after 18.10:

apt-get install qemu-kvm libvirt-daemon-system libvirt-bin virtinst libosinfo-bin

* Where qemu-kvm- hypervisor; libvirt-bin— hypervisor control library; virtinst— virtual machine management utility; libosinfo-bin— a utility for viewing a list of operating system options that can be used as guest operating systems.

Let's configure the service to start automatically:

systemctl enable libvirtd

Let's launch libvirtd:

systemctl start libvirtd

Network configuration

Virtual machines can work behind NAT (which is a KVM server) or receive IP addresses from the local network - for this you need to configure a network bridge. We'll configure the latter.

When using a remote connection, check your settings carefully. If an error occurs, the connection will be terminated.

Install bridge-utils:

apt-get install bridge-utils

a) network setup in older versions of Ubuntu (/etc/network/interfaces).

Open the configuration file to configure network interfaces:

vi /etc/network/interfaces

And let's put it in this form:

#iface eth0 inet static
# address 192.168.1.24
# netmask 255.255.255.0
#gateway 192.168.1.1
# dns-nameservers 192.168.1.1 192.168.1.2

Auto br0
iface br0 inet static
address 192.168.1.24
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1 192.168.1.2
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off

* where everything that is commented out is the old settings of my network; br0— name of the interface of the created bridge; eth0— an existing network interface through which the bridge will operate.

Restart the network service:

systemctl restart networking

b) setting up a network in new versions of Ubuntu (netplan).

vi /etc/netplan/01-netcfg.yaml

* depending on the system version, configuration file yaml may have a different name.

Let's bring it to form:

network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: false
dhcp6: false
wakeonlan: true

Bridges:
br0:
macaddress: 2c:6d:45:c3:55:a7
interfaces:
-eth0
addresses:
- 192.168.1.24/24
gateway4: 192.168.1.1
mtu: 1500
nameservers:
addresses:
- 192.168.1.1
- 192.168.1.2
parameters:
stp: true
forward-delay: 4
dhcp4: false
dhcp6: false

* in this example we are creating a virtual bridge interface br0; we use as a physical interface eth0.

Apply network settings:

We insist on redirecting network traffic (so that virtual machines with a NAT network interface can access the Internet):

vi /etc/sysctl.d/99-sysctl.conf

Add the line:

net.ipv4.ip_forward=1

Apply the settings:

sysctl -p /etc/sysctl.d/99-sysctl.conf

Creating a virtual machine

To create the first virtual machine, enter the following command:

virt-install -n VM1\
--autostart\
--noautoconsole\
--network=bridge:br0 \
--ram 2048 --arch=x86_64 \
--vcpus=2 --cpu host --check-cpu \
--disk path=/kvm/vhdd/VM1-disk1.img,size=16 \
--cdrom /kvm/iso/ubuntu-18.04.3-server-amd64.iso \
--graphics vnc,listen=0.0.0.0,password=vnc_password \
--os-type linux --os-variant=ubuntu18.04 --boot cdrom,hd,menu=on

  • VM1 - the name of the machine being created;
  • autostart — allow the virtual machine to automatically start along with the KVM server;
  • noautoconsole — does not connect to the virtual machine console;
  • network - network type. In this example, we are creating a virtual machine with a “network bridge” interface. To create an internal interface with NAT type, enter --network=default,model=virtio;
  • ram - amount of RAM;
  • vcpus — number of virtual processors;
  • disk - virtual disk: path — path to disk; size — its volume;
  • cdrom - virtual drive with a system image;
  • graphics parameters for connecting to a virtual machine using a graphical console (in this example we use vnc); listen - at what address vnc requests are received (in our example, all); password - password for connecting using vnc;
  • os-variant — guest operating system (we received the entire list with the command osinfo-query os, in this example we install Ubuntu 18.04).

Connecting to a virtual machine

On the computer from which we plan to work with virtual machines, download a VNC client, for example, TightVNC and install it.

On the server we enter:

virsh vncdisplay VM1

the command will show which port VNC is running on for machine VM1. I have had:

* :1 means that you need to add 1 to 5900 - 5900 + 1 = 5901.

Launch TightVNC Viewer, which we installed and enter the connection data:

Click on Connect. When prompted for a password, enter the one you specified when creating the VM ( vnc_password). We will connect to the virtual machine using a remote console.

If we don’t remember the password, we open the virtual machine setup with the command:

And we find the line:



* in this example, a password is used to access the virtual machine 12345678 .

Managing a virtual machine from the command line

Examples of commands that may be useful when working with virtual machines.

1. Get a list of created machines:

virsh list --all

2. Enable the virtual machine:

virsh start VMname

* Where VMname— the name of the created machine.

3. Shut down the virtual machine:

ubuntu-vm-builder is a package developed by Canonical to make it easier to create new virtual machines.

To install it, enter:

apt-get install ubuntu-vm-builder

KVM or Kernel Virtual Module is a virtualization module for the Linux kernel that allows you to turn your computer into a hypervisor for managing virtual machines. This module operates at the kernel level and supports hardware acceleration technologies such as Intel VT and AMD SVM.

By itself, KVM software in user space does not virtualize anything. Instead, it uses the /dev/kvm file to configure virtual address spaces for the guest in the kernel. Each guest machine will have its own video card, network and sound card, hard drive and other equipment.

Also, the guest system will not have access to components of the real operating system. The virtual machine runs in a completely isolated space. You can use kvm both on a GUI system and on servers. In this article we will look at how to install kvm Ubuntu 16.04

Before proceeding with the KVM installation itself, you need to check whether your processor supports hardware virtualization acceleration from Intel-VT or AMD-V. To do this, run the following command:

egrep -c "(vmx|svm)" /proc/cpuinfo

If the result returns 0, then your processor does not support hardware virtualization, if 1 or more, then you can use KVM on your machine.

Now we can proceed to installing KVM, a set of programs can be obtained directly from the official repositories:

sudo apt install qemu-kvm libvirt-bin bridge-utils virt-manager cpu-checker

We installed not only the kvm utility, but also the libvirt library, as well as the virtual machine manager. Once the installation is complete, you need to add your user to the libvirtd group, because only root and users in this group can use KVM virtual machines:

sudo gpasswd -a USER libvirtd

After running this command, log out and log in again. Next, let's check if everything was installed correctly. To do this, use the kvm-ok command:

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

If everything was done correctly, you will see the same message.

Using KVM on Ubuntu 16.04

You have completed the task of installing kvm in Ubuntu, but you cannot yet use this virtualization environment but it still needs to be configured. Next, we will look at how kvm Ubuntu is configured. First you need to set up your network. We need to create a bridge with which the virtual machine will connect to the computer's network.

Setting up a bridge in NetworkManager

This can be done in several ways, for example, you can use the network configuration program NetworkManager.

Click the NetworkManager icon in the panel, then select change connections, then click the button Add:

Then select the connection type Bridge and press Create:

In the window that opens, click the button Add, to link our bridge to the internet connection:

From the list, select Ethernet and press Create:

In the next window, select in the field device, network interface to which our bridge should be associated:

Now you will see your bridge in the list of network connections. All that remains is to reboot the network to fully apply the changes, to do this, run:

Manual bridge setup

First you need to install the bridge-utils set of utilities if you have not already done so:

sudo apt install bridge-utils

Then, using the brctl program, we can create the bridge we need. To do this, use the following commands:

sudo brctl addbr bridge0
$ sudo ip addr show
$ sudo addif bridge0 eth0

The first command adds the bridge device br0, with the second you need to determine which network interface is the main connection to the external network, in my case it is eth0. And with the last command we connect bridge br0 to eth0.

Now you need to add a few lines to the network settings so that everything starts up automatically after the system starts. To do this, open the /etc/network/interfaces file and add the following lines there:

sudo gedit /etc/network/interfaces

loopback
auto lo bridge0
iface lo inet loopback
iface bridge0 inet dhcp
bridge_ports eth0

When the settings are added, reboot the network:

sudo systemctl restart networking

Now the installation and configuration of KVM is completely completed and you can create your first virtual machine. After this, you can view the available bridges using the command:

Creating KVM virtual machines

The Ubuntu KVM setup is complete and we can now move on to using it. First, let's look at the list of existing virtual machines:

virsh -c qemu:///system list

It's empty. You can create a virtual machine through the terminal or in the graphical interface. To create via the terminal, use the virt-install command. First let's go to the libvirt folder:

cd /var/lib/libvirt/boot/

To install CentOS the command will look like this:

sudo virt-install\
--virt-type=kvm \
--name centos7\
--ram 2048\
--vcpus=2 \
--os-variant=rhel7 \
--hvm\
--cdrom=/var/lib/libvirt/boot/CentOS-7-x86_64-DVD-1511.iso \
--network=bridge=br0,model=virtio \
--graphics vnc\
--disk path=/var/lib/libvirt/images/centos7.qcow2,size=40,bus=virtio,format=qcow2

Let's take a closer look at what the parameters of this command mean:

  • virt-type- type of virtualization, in our case kvm;
  • name- name of the new car;
  • ram- amount of memory in megabytes;
  • vcpus- number of processor cores;
  • os-variant- type of operating system;
  • cdrom- installation image of the system;
  • network-bridge- the network bridge that we configured earlier;
  • graphics- a way to gain access to the graphical interface;
  • diskpath- address of the new hard drive for this virtual machine;

After the installation of the virtual machine is complete, you can find out the VNC connection parameters using the command:

sudo virsh vncdisplay centos7

Now you can enter the received data in your VNC client and connect to the virtual machine even remotely. For Debian the command will be slightly different, but everything looks similar:

Go to the folder for images:

cd /var/lib/libvirt/boot/

You can download the installation image from the Internet if necessary:

sudo wget https://mirrors.kernel.org/debian-cd/current/amd64/iso-dvd/debian-8.5.0-amd64-DVD-1.iso

Then let's create a virtual machine:

sudo virt-install\
--virt-type=kvm \
--name=debina8 \
--ram=2048\
--vcpus=2 \
--os-variant=debian8 \
--hvm\
--cdrom=/var/lib/libvirt/boot/debian-8.5.0-amd64-DVD-1.iso \
--network=bridge=bridge0,model=virtio \
--graphics vnc\
--disk path=/var/lib/libvirt/images/debian8.qcow2,size=40,bus=virtio,format=qcow2

Now let's look at the list of available machines again:

virsh -c qemu:///system list

To start the virtual machine you can use the command:

sudo virsh start machinename

To stop:

sudo virsh shutdown machinename

To switch to sleep mode:

sudo virsh suspend machinename

To reboot:

sudo virsh reboot machinename

sudo virsh reset machinename

To completely remove a virtual machine:

sudo virsh destroy machinename

Creating virtual machines in GUI\

If you have access to a graphical interface, there is no need to use a terminal; you can use the full graphical interface of the Virtual Manager virtual machine manager. The program can be launched from the main menu:

To create a new machine, click on the icon with the monitor icon. Next, you will need to select the ISO image of your system. You can also use a real CD/DVD drive:

On the next screen, select the amount of memory that will be available to the virtual machine, as well as the number of processor cores:

On this screen, you need to select the size of the hard drive that will be available in your machine:

At the last step of the wizard, you have to check that the machine settings are correct and also enter its name. You also need to specify the network bridge through which the machine will connect to the network:

After this, the machine will be ready for use and will appear in the list. You can launch it using the green triangle on the manager toolbar.

conclusions

In this article, we looked at how to install KVM Ubuntu 16.04, we looked at how to fully prepare this environment for work, as well as how to create virtual machines and use them. If you have any questions, ask in the comments!

To conclude, a lecture from Yandex about what virtualization is in Linux:

Did you like the article? Share it