Contacts

Installing Linux Mint KVM Ubuntu. Rubber hypervisor. We use logic groups to virtualize qmu-kvm in Linux. Manual bridge setting

In Ubuntu, it is recommended to use a hypervisor (Virtual Machine Manager) KVM and LIBVIRT library as a management toolkit. LIBVIRT includes a set of software API and user management applications. virtual machines (VM) Virt-Manager (Graphic Interface, GUI) or Virsh ( command line, CLI). Alternative managers, you can use Convirt (GUI) or Convirt2 (Web Interface).

Currently, only KVM hypervisor is officially supported in Ubuntu. This hypervisor is part of the operating core code. linux systems. Unlike Xen, KVM does not support pathrahritualization, that is, in order to use it, your CPU must hold the VT technology. You can check whether your processor supports this technology by running the command in the terminal:

If the result was a message:

Info: / Dev / KVM Exists KVM Acceleration CAN BE Used

so KVM will work without problems.

If you received a message at the exit:

Your CPU Does Not Support KVM Extensions KVM Acceleration CAN NOT BE Used

you can still use a virtual machine, but it will work much slower.

    Install as guest 64-bit systems

    Allocate to guest systems more than 2 GB of RAM

Installation

Sudo Apt-Get Install QEMU-KVM Libvirt-Bin Ubuntu-Vm-Builder Bridge-Utils

This is an installation on the server without Xs, i.e. does not include a graphical interface. Install it can be commanded

Sudo Apt-Get Install Virt-Manager

After that, the menu will appear "Virtual Machine Manager" and, with a lot of probability, everything will work. If any problems still arise, then you will need to read the instructions in English-speaking wiki.

Creating a guest system

The procedure for creating a guest system with graphic interface quite simple.

But the text mode can be described.

qCOW2.

When creating a system using a graphical interface as hard disk It is proposed to either select an existing file image or block device, or create a new file with raw (RAW) data. However, this is not the only available file format. Of all the types of disks listed in MAN qmu-img, QCOW2 is the most flexible and modern. It supports snapshots, encryption and compression. It must be created before creating a new guest system.

QEMU-IMG CREATE -O PREALLOCATION \u003d METADATA -F QCOW2 QCOW2.IMG 20G

According to the same man qmu-img, pre-placing metadata (-orary \u003d metadata) makes the disk initially a little more, but provides better performance In those moments when the image needs to grow. In fact, in this case this option avoids an unpleasant bug. The image created initially takes less than megabytes of the place and it increases to the specified size as necessary. Guest system should immediately see this final specifiedHowever, at the installation stage, it can see the actual file size. Naturally, installed on hDD It will refuse 200 KB. The bug is not specific for Ubuntu, it is manifested in Rhel, at a minimum.

In addition to the type of image, you can subsequently select the method of connecting it - IDE, SCSI or Virtio Disk. This choice will depend on the performance of the disk subsystem. There is no definitely the correct answer, you need to choose from the task that will be assigned to the guest system. If a guest System Created "to see", then any way will come down. In general, it is usually the I / O is a bottleneck of a virtual machine, so when creating a high-loading system to this question, you must take the most responsible as possible.

I am writing this note to demonstrate step-by-step installation and configuring a virtual machine in Linux based on KVM. Earlier, I already wrote about virtualization, where I used wonderful.

Now in front of me the issue of the rental of a good server with a large volume random access memory and a voluminous hard disk. But I don't want projects directly on the host machine, so I will distinguish them on some small virtual servers with Linux OS or Docker-containers (I will tell you about another article).

All modern cloud hosting works on the same principle, i.e. Huster on good gland raises a bunch virtual serversThat 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.

KVM installation

All Machinations to create a virtual machine I will spend on UBuntu OS 16.04.1 LTS. To check whether your processes are hardware virtualization on intel database VT / AMD SVM, perform:

Grep -E "(VMX | SVM)" / proc / cpuinfo

If the terminal is non-empty, then everything is in order and KVM can be installed. Ubuntu officially supports only KVM hypervisor (included in the Linux kernel) and advises to use the libvirt library as a tool for managing them, what we will do next.

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

In case of success, 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 graphics shell of the system, you can install the GUI LIBVIRT manager:

Sudo Apt-Get Install Virt-Manager

You can simply use Virt-Manager (not more difficult than VirtualBox), so this note will be discussed about the console version of the installation and configuration of the virtual server.

Installing and configuring a virtual server

In the console version of the installation, settings and control of the system, an indispensable tool is the Virsh utility (add-on above LIBVIRT library). She has a large number of options and parameters, detailed description You can get like this:

Man Virsh.

or call the standard "HELP":

Virsh Help.

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

  1. Stranu iSO images OS in the catalog / Var / Lib / libvirt / boot
  2. Store Virtual Machine Images in Catalog / Var / Lib / Libvirt / Images
  3. I clearly ask each new virtual machine your static IP address via DHCP server of the hypervisor.

We will proceed to install the first virtual art (64-bit server Ubunt 16.04 LTS):

CD / VAR / LIB / Libvirt / Boot Sudo Wget http://releases.ubuntu.com/16.04/ubuntu-16.04.1-Desktop-amd64.iso

By downloading the image Run the installation:

Sudo virt-install \\ --virt-type \u003d kvm \\ --name ubuntu1604 \\ --ram 1024 \\ --vcpus \u003d 1 \\ --os-Variant \u003d ubuntu16.04 \\ --HVM \\ --CDROM \u003d / VAR / LIB / LIBVIRT / BOOT / UBUNTU-16.04.1-Server-AMD64.iso \\ --network Network \u003d Default, Model \u003d Virtio \\ --Graphics VNC \\ --Disk Path \u003d / VAR / LIB / LIBVIRT / images / Ubuntu1604. IMG, Size \u003d 20, bus \u003d Virtio

Transferring all these parameters to "Human Language", it turns out that we create a virtual machine with UBuntu OS 16.04, 1024 MB of RAM, 1 processor, standard network card (the virtual machine will go to the Internet as if because of NAT), 20 HDD GB.

It is worth paying attention to the parameter --os-Variant, it indicates a hypervisor to which OS should adapt settings.
The list of available OS options can be obtained by running the command:

Osinfo-Query OS

If this utility is not in your system, you set:

Sudo Apt-Get Install Libosinfo-Bin

After starting the installation, this inscription 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 to install via VNC.
We look at what port it was raised from our virtual art (in the next terminal, for example):

Virsh DumpXML Ubuntu1604 ... ...

Port 5900, on the local address 127.0.0.1. To connect to VNC, you need to use Port Forwarding via SSH. Before doing this, make sure TCP Forwarding is allowed from the SSH Demon. To do this, we go to the SSHD settings:

CAT / ETC / SSH / SSHD_CONFIG | Grep AllowTcpforwarding

If nothing has found or you see:

AllowTcPorwarding No.

Then the config rights on

AllowTcpforwarding Yes

and reboot SSHD.

Setting up Port Forwarding

We carry out the command on the local machine:

SSH -FN -L Login -L 127.0.0.1:5900:localhost:900 Server_IP

Here we configured Ssh Port Forwarding from the local port of 5900 to the 5900 server port. Now you can already connect to the VNC using any VNC client. I prefer ultravnc because of simplicity and convenience.

After a successful connection, the standard Ubuntu start welcome window will appear on the screen:

After completing the installation and the usual reboot, the login window will appear. Authorized, I define the IP address of the newly prominent virtuals to later make it static:

IFconfig

We remember and go to the host car. I pull out the MAC address "Network" virtual cards:

Virsh DumpXml Ubuntu1604 | Grep "Mac Address"

We remember our Mac address:

Edit network settings Hypervisor:

Sudo Virsh Net-Edit Default

We are looking for DHCP, and add it:

It should turn out something like this:

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

Sudo Virsh Net-Destroy Default Sudo Virsh Net-Start Default Sudo Service Libvirt-Bin Restart

After that, overload the virtual machine, now it will always have the IP address given to it - 192.168.122.131.

There are other ways to set a virtual static IP, for example, directly editing network settings inside the guest system, but here already as your soul will be pleased. I only showed an option that I myself prefer to use.

To connect to the virtual machine terminal, perform:

SSH 192.168.122.131

The car is ready for battle.

Virsh: team list

To view launched virtual hosts (All available can be obtained by adding --All):

Sudo Virsh List.

Reload the host can be:

Sudo Virsh Reboot $ VM_NAME

Stop the virtual machine:

Sudo Virsh Stop $ vm_name

Run Halt:

Sudo Virsh Destroy $ vm_name

Sudo Virsh Start $ vm_name

Disconnection:

Sudo Virsh Shutdown $ VM_NAME

Add to autorun:

Sudo Virsh Autostart $ vm_name

It is often necessary to block the system to use it in the future as a frame for other virtual OS, for this use the Virt-Clone utility.

Virt-Clone --help

It clones the existing virtual and changes the Host-sensitive data, for example, Mac Address. Passwords, files and other User-Specific Information in the clone remains the same. If the IP address has been registered on the IP cloned virtual, then problems may arise with SSH access to a clone due to conflict (2 hosts with the same IP).

In addition to installing virtuals via VNC, an option with X11Forwarding through the Virt-Manager utility is also possible. In Windows, for example, you can use Xming and Putty.

In this introductory article, I will tell in brief about all softwareused in the development process. In more detail about them will be told in the following articles.

Why? This operating system I am close and understandable, so when choosing a flib of torment, torments and thumbnails were not tested. He has no special advantages to Red Hat Enterprise Linux, but it was decided to work with a familiar system.

If you plan to independently deploy the infrastructure using similar technologies, I would advise you to take RHEL: Thanks to good documentation and well written applied programs It will be if not an order of magnitude, then exactly two times easier, and thanks to the developed system of certification without much difficulty it will be possible to find a certain number of specialists, at the proper level of acquaintances in this OS.

We, I repeat, decided to use Debian Squeeze with a set of packages from SID / EXPERIMENTAL and some packages, backported and collected with our patches.
The plans have a publishing repository with packages.

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

Also, the fact of the presence of a huge number of developers, hosters, commercial solutions was made on the basis of XEN - the more interesting it was to make a decision precisely on the KVM database.

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

To manage virtual machines, it turned out to be extremely conveniently used and products using its API: virsh., virt-Manager., virt-Install, etc.

This is a system that stores the settings of virtual machines, controls them, leads statistics on them, ensures that when starting the virtual machine, the interface rises, connects the devices to the machine - in general, performs a bunch of useful work and a little more.

Of course, the solution is not perfect. Of the minuses should be called:

  • Absolutely invaliable error messages.
  • The inability to change the portion of the virtual machine configuration on the fly, although QMP (QMU Monitor Protocol) is quite allowed.
  • Sometimes it is impossible to connect to libvirtd for an incomprehensible reason - it ceases to respond to external events.

The main problem in the implementation of 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 chateler distributing resources between virtual machines - and what is the most beautiful, the opportunity to limit and disk operations including.

In KVM, nothing has happened before the nuclear resource distribution mechanism appears. As usual in Linux, access to these functions was implemented through a special file system. cgroup.in which you could add the process to the group using conventional system calls to the group, assign it its weight in parrots, specify the kernel on which it will work, specify throughput The disk that this process can use, or, again, assign the weight to it.

The profit is that all this is implemented inside the kernel, and it is possible to use this not only for the server, but also for desktop (as used in the known "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 your favorite # 12309, rather than pooling the next file system. Well, except for pohmelfs (but purely because of the name).

The attitude to this library-utility I have quite ambiguous.

On the one hand it looks like this:

And this thing is damn it is difficult to collect from the source and the more in the package: sometimes it seems to me that Linux from Scratch collect from scratch somewhat easier.

On the other hand, a very powerful thing that allows you to create images for virtual machines, modify them, climb, to put GRUB, modify the partition table, manage configuration files, transferring the "iron" machines to the virtual environment, transfer virtual machines from one image to another To transfer virtual machines from an image to iron and, honestly, here I fantasy fails. Oh, yes: you can still run the daemon inside the virtual linux cars And access the virtual machine data is live, and do it all on Shell, Python, Perl, Java, Ocaml. This is a brief and not complete list of what can be done with.

Interestingly, most of the code B is generated at the time of assembly, as well as the documentation for the project. Ocaml, Perl is very widely used. The code itself is written on C, which then turns into OCAML, and repeated pieces of code are generated themselves. Working with images is carried out by running a special service image (Supermin Appliance), in which commands are sent through the channel inside it. Inside this image contains some Rescue a set of utilities, such as parted, MKFS and other useful system administrator.

With recently, I even began to use him at home when I was smelted from the image of Nandroid I needed the data. But this requires the kernel with support for Yaffs.

Other

Below is a few more interesting references to the description of the used cards - read and discourse yourself, if interesting. For example,

Earlier I already wrote about the installation QEMU-KVM. in Debian.. But, in my opinion, the information turned out to be incomplete. Plus I did not consider some nuances. Therefore, I bring to your attention an updated article on installing the QEMU-KVM virtual machine. Old article, naturally, deleted.

I think to explain what is virtual machine, not worth it. You probably know it (if you read this article). If not - . We will dwell directly on sabget. QEMU-KVM. - This is a project to combine two noticeable (in my opinion) full virtualization technologies. QEMU. - This is a kind of computer emulator, which supports the great many hardware architectures. You can run almost any OS for any device (for example, I launched old versions. Mac OS X.which for PowerPc.). The disadvantage of QEMU is its slowness due to the lack of an approach acceleration. And then another project comes to the rescue - KVM. . Or Kernel Virtual Machine. KVM is a Linux kernel technology that allows you to provide hardware acceleration with full virtualization. The disadvantage of KVM is the support of only x86 architecture

Why qmu-kvm? For Linux, this is the most recommended virtualization project. It works faster than VirtualBox. and VMware Player. (According to my tests), KVM is a technology native to Linux. Plus, if you are a good owner gaming computer With two video cards, you can install in QEMU-KVM Windows, we break into it one of the video cards, and forget about the reboot to another OS. Wanted to play - launched a virtual with Windows and play. Performance will be 95% of the performance installed on the "iron" of Windows. But it's just gorgeous, in my opinion. I will write a separate article about it. It will be interesting:)

Now I will describe the plan of our actions. First, I will carry out the installation on the example Debian 8.2 GNOME 64 BITAlthough there will be no special differences in other graphic environments. Secondly - I will describe work with KVM only in graphical mode (we will not put it on the server). Therefore, no terminals, scripts, and so on, as usually come in case server virtualization. Thirdly, I advise you to additionally read the QEMU and KVM documentation (ladies link at the end of the article). It is very useful to you if you want a maximum to use the full potential of this bundle. Well, well, the plan of our actions is clear. Now steps actions:

  • qEMU-KVM installation;
  • installing a graphics manager and additional utilities;
  • setting the network bridge;
  • creating a storage for virtual machines;
  • installing a guest system.
To begin with, check whether your computer supports hardware virtualization. To do this, in the terminal perform the command:

egrep "(VMX | SVM)" / Proc / Cpuinfo

In the output of the team should be present either vMXeither sVM.. If there are no - whether virtualization is enabled in the BIOS (Look for items Intel VT-I or similar for AMD.). If there is nothing - it means it is not lucky.

Install the required components:

sudo Apt Install QEMU-KVM Bridge-Utils Libvirt-Bin Virt-Manager

We add yourself to the libvirt group:

sudo AddUser $ User Libvirt

Now set the network. In order for all the vertaal cars to go to the network and communicate with each other, you need to create a network bridge and virtual network cards for each virtual ( tAP devices). Since we will install virtual machines from the graphical interface, then you do not need to create a manually tap. Virt Manager. Make it for us every time you start. We only need to configure the bridge. To begin with, turn on the routing in the kernel:

sudo nano /etc/sysctl.conf.

We are looking for a string net.ipv4_forward \u003d 0 and change its value to 1 . Save and:

sudo Sysctl -p.

Next, I will assume the following: 1) On your computer there is one network card that receives the IP address from the router. 2) You go online through a 3G modem, and your network card is free. This option suggests more handmade, but it has been checked repeatedly (at one of the cars itself). So, open the interfaces file:

sudo Nano / etc / Network / Interfaces

The default content is:



aUTO LO.
iFACE LO INET LOOPBACK

Change its contents. For the first option:

source /etc/network/interfaces.d/*

# THE LOOPBACK NETWORK INTERFACE
aUTO LO.
iFACE LO INET LOOPBACK

AUTO ETH0.
iFACE ETH0 INET MANUAL

AUTO BR0.
iFACE BR0 INET STATIC
aDDRESS 192.168.0.2.
gateway 192.168.0.1
netMask 255.255.255.0.
network 192.168.0.0.
broadcast 192.168.0.255
Bridge_Ports Eth0.
bridge_stp off.
Bridge_maxwait 0.
Bridge_fd 0.

For the second option:

source /etc/network/interfaces.d/*

# THE LOOPBACK NETWORK INTERFACE
aUTO LO.
iFACE LO INET LOOPBACK

AUTO PPP0.
iFACE PPP0 INET WVDIAL

AUTO ETH0.
iFACE ETH0 INET MANUAL

AUTO BR0.
iFACE BR0 INET STATIC
aDDRESS 192.168.0.2.
gateway 192.168.0.1
netMask 255.255.255.0.
network 192.168.0.0.
broadcast 192.168.0.255
Bridge_Ports Eth0.
bridge_stp off.
Bridge_maxwait 0.
Bridge_fd 0.
up Route Del Default Br0

Note: If you do not need to automatically connect the Internet via the modem after the start of the system, remove the AUTO PPP0 line from the config
iFACE PPP0 INET WVDIAL. Otherwise, make sure that when starting the system, the modem is inserted into the USB port.

We save. Now for an option with a modem, you need to install the Dialing Program wvdial:

sudo Apt Install Wvdial

Correct config (Note: 3G modem is used as an example Beeline.. Examples of configs for other modems you can easily find on the Internet):

sudo Nano /etc/wvdial.conf.


Init1 \u003d atz.
INIT2 \u003d ATQ0 V1 E1 S0 \u003d 0 & C1 & D2 + FCLASS \u003d 0
INIT3 \u003d AT + CGDCont \u003d 1, "IP", "home.beeline.ru"
Stupid Mode \u003d 1
ISDN \u003d 0.
MODEM TYPE \u003d USB Modem
New pppd \u003d yes
Phone \u003d * 99 #
Modem \u003d / dev / ttyacm0
UserName \u003d Beeline.
Password \u003d Beeline
Baud \u003d 9600.
Country \u003d Russia.
AUTO RECONNECT \u003d ON
AUTO DNS \u003d OFF
IDle Seconds \u003d 0

We save. Now the modem will be turned on immediately after loading the system. The UP ROUTE DEL Default Br0 string deletes the default route through the bridge. If this is not done, you will not be able to connect with the Internet, as the traffic will go on the bridge, and not through a 3G modem.

Last stage we need to say farwallSo that he missed traffic from our virtual and back to the network. To do this, you can go in two ways: write a script with multiple rules for iPTABLES.which will run along with the system, or enter these rules manually and save them. I will take advantage of the first option. For the second you will need to install the package iPTABLES-Persistent And just alternately enter the rules (using sudo). So. Create a script (in any text editor). Insert the following contents there:

#! / bin / sh

# Define the output interface for which the address replacement will be applied (NAT)
iPTABLES -V -T NAT -A POSTROUTING -O PPP0 -J MASQUERADE

# We send all the packages that came to the modem from the global network (0.0.0.0/0) to the local area network (192.168.0.0/24)
iPTABLES -V -A FORWARD -I PPP0 -O BR0 -S 0.0.0.0/0 -D 192.168.0.0/24 -J Accept

# We send all the packages that came from local network (192.168.0.0/24) to the global (0.0.0.0/0)
iPTABLES -V -A FORWARD -I BR0 -O PPP0 -S 192.168.0.0/224 -D 0.0.0.0/0 -J Accept

Keep it as gateway.sh. and give rights to execute (or in the properties of the file, or in the terminal command cHMOD + X Gateway.sh). Now you can either run it manually, after the system has been loaded, or add to autoload. To do this, move the script in ~ / .config / autostart (in file Manager Turn on the show hidden filesand you will see the catalog .config in the home directory).

Now everything is ready to install a virtual machine. From the application menu, run Virt Manager (Virtual Machine Manager):

Right-click on the line localhost. and choose Details. Go to the tab Storage. We need to specify a directory (or disk / disk section) for storing virtual machines.

In the lower left corner, click on the plus sign ( Add Pul), I specify the type of repository and the path to it.

On the tab Network interfacesYou can check whether everything works.

Now click File - New Virtual Machine. Specify the path to the disk image, the type of virtual machine. Next, specify the number of RAM for it and the number of processor cores. Next, specify our storage and click New volume . Indicate the name, the type is left qCOW2.and size. It will be a virtual hard disk. If you plan to install a system with a graphic shell and a bunch of programs, give places more (Gigs 50). On the last tab, put a tick on Change settings before startingcheck that as network device Our bridge is selected, write any name for virtuals and click Complete. You will open the parameters window of this virtual machine.





Go to the tab CPUand put a tick on Copy host system processor settings.

Next to the tab Net (next), and also specify vitio.. On the tab Display Specify Spice.and on the tab Video - QXL. Usually this bundle provides maximum productivity Recruit graphs, but if you want, you can experiment. Note that for guests windows systemsThe QXL drivers are required (in Windows itself).


Now when everything is ready, in the left upper corner Click Start installation. And we put the system as usual, with one exception: as soon as the installer starts automatically adjusting the network, press Canceland select Set up a network manually. Specify the desired IP address for virtuals (in our case 192.168.0.3 ), subnet mask ( 255.255.255.0 ), the gateway (the gateway will be the address of the host, i eat 192.168.0.2 ) and DNS server (here just enter the Google 8.8.8.8 ). And that's it. Next do nothing. Put the system and configure. In general, everything. The actions described are the way to replace, say, VirtualBox on more best alternative. After reading the documentation, you will understand how wide the possibilities of QEMU-KVM. I intentionally did not describe here additional console parameters and methods for starting virtual machines through the terminal, as it is not always needed on a home machine. I will write about this separate article, on setting up a home multifunctional server (which can also act as a virtual machine server). For those who, for some reason, did not understand what was written, or remained incomprehensible moments - I propose to watch the video, in which I will not describe, but I'll show you how everything is good and tune. If you have any suggestions or additions to the article - write in the comments.

Checking support for hypervisor

Check that the server supports virtualization technologies:

cat / Proc / Cpuinfo | Egrep "(VMX | SVM)"

In response, you should get something like:

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 aperfmperf 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, we go to the BIOS, we find the option to enable virtualization technology (it has different names, for example, Intel Virtualization Technology or Virtualization) and turn it on - set the value Enable.

Also check compatibility by the command:

* if the command returns the 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

so support from the hardware is there.

Preparing Server

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

mKDIR -P / KVM / (VHDD, ISO)

* Two catalog will be created: / KVM / VHDD (for virtual hard drives) and / KVM / ISO (for ISO images).

Customize time:

\\ CP / USR / SHARE / ZONEINFO / EUROPE / MOSCOW / ETC / LOCALTIME

* This command sets the zone according to Moscow time.

ntpdate ru.pool.ntp.org.

* Perform time synchronization.

Installation and Starting

Install KVM and the necessary management utilities.

a) ubuntu 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 management library; virtinst. - virtual machine management utility; libosinfo-Bin. - utility to view the list of options for operating systems that can be as a guest.

Customize automatic start Service:

systemCTL Enable Libvirtd.

Start LibvirtD:

systemCTL Start Libvirtd.

Network configuration

Virtual machines can work for NAT (which serves as KVM server) or receive IP addresses from the local network - for this you need to configure the network bridge. We will set the last.

Using remote connectionCheck the settings carefully. In case of error, the connection will be interrupted.

Install Bridge-Utils:

aPT-Get Install Bridge-Utils

a) Setting up the network in the old Ubuntu versions (/ etc / network / interfaces).

Open a configuration file to configure network interfaces:

vI / ETC / Network / Interfaces

And we give it to mind:

#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 all that commented is the old settings of my network; bR0. - the name of the interface of the generated bridge; eth0. - An existing network interface through which the bridge will work.

Restart the network service:

systemCTL Restart Networking.

b) network setting in new Ubuntu versions (NetPlan).

vI /etc/netplan/01-netcfg.yaml.

* Depending on the system version, configuration file. yaml May have another name.

We bring it to mind:

network:
Version: 2.
Renderer: Networkd.
Ethernets:
ETH0:
DHCP4: False.
DHCP6: False
Wakeonlan: True.

Bridgees:
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 create a virtual bridge interface bR0.; We use as a physical interface eth0..

Apply Network Settings:

We insist the redirects of network traffic (so that the virtual machines with the NAT network interface can go online):

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

Add a string:

net.ipv4.ip_forward \u003d 1.

Apply 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 \u003d bridge: br0 \\
--ram 2048 --arch \u003d x86_64 \\
--Vcpus \u003d 2 --cpu host --Check-CPU \\
--Disk Path \u003d / KVM / VHDD / VM1-DISK1.img, Size \u003d 16 \\
--cdrom /kvm/iso/ubuntu-18.04.3-server-amd64.iso \\
--graphics VNC, LISTEN \u003d 0.0.0.0, Password \u003d VNC_PASSWORD \\
--os-Type Linux --os-Variant \u003d ubuntu18.04 --Boot CDROM, HD, MENU \u003d ON

  • VM1 - the name of the machine being created;
  • autostart - Allow the virtual machine to automatically start with the KVM server;
  • noautoconsole - does not connect to the console of the virtual machine;
  • network - Type of network. In this example, we create a virtual machine with a network bridge type interface. To create an internal interface with NAT type Introduce --Network \u003d Default, Model \u003d Virtio;
  • rAM - The amount of RAM;
  • vCPUS - number of virtual processors;
  • dISK - virtual disk: path - way to disk; size - its volume;
  • cDROM - Virtual drive system;
  • graphics - Connection parameters to a virtual machine using a graphical console (in this example, we use VNC); listen - What address accepts VNC requests (in our example on all); password - password for connecting with VNC;
  • oS-VARIANT - Guest operating system (the entire list we received a team osinfo-Query OSIn this example, install Ubuntu 18.04).

Connect 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.

We enter on the server:

virsh VNCDISPLAY VM1

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

*: 1 So you need to add 1 - 5900 + 1 \u003d 5901 to 5900.

Run the TightVNC Viewer, which we installed and enter the data for connectivity:

Click of PO Connect.. We introduce the name to the password request when creating a VM, ( vNC_PASSWORD.). We will connect to the virtual machine remote console.

If we do not remember the password, open the virtual machine setting as a command:

And find the string:



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

Management of the virtual machine from the command line

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

1. Get a list of machines created:

virsh List --all

2. Enable a virtual machine:

virsh Start Vmname.

* where Vmname. - The name of the machine being created.

3. Turn off the virtual machine:

ubuntu-VM-Builder is a package developed by Canonical to simplify the creation of new virtual machines.

To install it, we enter:

aPT-Get Install Ubuntu-VM-Builder



Did you like the article? Share it