Menu
Is free
check in
home  /  BY / VDS KVM Ubuntu 14.04 with graphic shell. Russian-language documentation on Ubuntu

VDS KVM Ubuntu 14.04 with graphic shell. Russian-language documentation on Ubuntu

Earlier I already wrote about the installation QEMU-KVM. at 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, delete.

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 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 the case of 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 repository 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 virtual machines we will install from graphic interfaceYou don't need to create manually TAP "s. 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 Cardreceiving 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 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 (at 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 virtual hDD. 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 To 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 Network (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 systems, Required separate installation QXL drivers (in Windows).


Now when everything is ready, in the upper left corner, click Start installation. And we put the system as usual, with one exception: as soon as the installer starts automatically adjusting the network, click 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.

Earlier I already wrote about the installation QEMU-KVM. at 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, delete.

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 the owner of a good playing 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 the case of 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 the 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 the file manager, turn on the display of hidden files, and you will see the directory .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 starting, Check that our bridge is selected as a network device, write any name for virtuals and click To 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 Network (next), and also specify vitio.. On the tab Display Specify Spice.and on the tab Video - QXL. Usually this bunch provides maximum drawing performance performance, but if you want, you can experiment. Note that for Guest Systems Windows, a separate QXL driver installation is required (in Windows itself).


Now when everything is ready, in the upper left corner, click Start installation. And we put the system as usual, with one exception: as soon as the installer starts automatically adjusting the network, click 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 for a better 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.

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 is close to me and understandably, so that when choosing a distribution 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.

The fact of availability was also taken into account huge number Developers, hosters, commercial solutions precisely on the basis of Xen - the more interesting it was to make a decision on the basis of KVM.

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

For management virtual machines It turned out to be extremely convenient to use the products using it 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 chaduler distributing resources between virtual machines - and what is the most beautiful, the possibility of limiting and disk operations was implemented.

In KVM, nothing has happened before the nuclear resource distribution mechanism appears. As usual in Linux, access to these functions was implemented by means of 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 Linux virtual machine and access the virtual machine data is live, and do it all on Shell, Python, Perl, Java, Ocaml. This is a brief and far from full list 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,

I personally easier to think about KVM (Kernel-based Virtual Machine), as a level of abstraction over the technologies of Hardwork virtualization Intel VT-X and AMD-V. We take a car with a processor supporting one of these technologies, put on this machine Linux, In Linux, install KVM, as a result we get the opportunity to create virtuals. So approximately work cloud hostings, such as Amazon Web Services. Along with KVM, Xen is also used, but the discussion of this technology is already beyond the scope of this post. Unlike container virtualization technologies, for example, the same Docker, KVM allows you to run any OS as a guest system, but it also has aboutleap overhead on virtualization.

Note: The actions described below were tested by me on Ubuntu Linux 14.04, but in theory will be largely valid both for other versions of Ubuntu and other Linux distributions. Everything should work on the desktop and on the server, access to which is carried out by SSH.

KVM installation

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

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

If something is stuck, then it is supported, and you can act further.

Install KVM:

sudo Apt-Get Update
sudo Apt-Get Install QEMU-KVM LIBVIRT-BIN VIRTINST Bridge-Utils

What is used to keep:

  • / var / libvirt / boot / - ISO images for installing guest systems;
  • / VAR / LIB / LIBVIRT / images / - Images hard disks guest systems;
  • / VAR / LOG / LIBVIRT / - Here you should look for all logs;
  • / etc / libvirt / - directory with configuration files;

Now that KVM is installed, create our first virtual.

Creating first virtual arts

I chose FreeBSD as a guest system. Swing ISO-image of the system:

cD / VAR / LIB / LIBVIRT / BOOT /
sudo Wget http: // FTP.FreeBSD.org/ Path / To / Some-FreeBSD-DISK.iso

Management of virtual machines in most cases is performed using the Virsh utility:

sudo Virsh --help.

Before starting virtuals, we will need to gather some additional information.

We look at the list of available networks:

sudo Virsh Net-List

Viewing a specific network (named DEFAULT):

sudo Virsh Net-Info Default

We look at the list of available optimizations for the guest OS:

sudo Virt-Install --os-Variant List

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

sudo Virt-Install \\
--Virt-Type \u003d KVM \\
--Name FreeBSD10 \\
--ram 1024 \\
--vcpus \u003d 1 \\
--os-Variant \u003d FreeBSD8 \\
--HVM \\
--CDROM \u003d / VAR / LIB / LIBVIRT / BOOT / FreeBSD-10.2 -Relese-AMD64-DISC1.ISO \\
--Network Network \u003d Default, Model \u003d Virtio \\
--Graphics VNC \\
--Disk Path \u003d / var / libvirt / images / freebsd10.img, Size \u003d 32, bus \u003d 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 and should be.

Then see the virtual properties in XML format:

sudo Virsh DumpXML FreeBSD10

Here is the most full information. Including, for example, and the MAC address that will be needed to us further. So far we find information about VNC. In my case:

With the help of your favorite client (I personally use Rammina) go through the VNC, if necessary, using SSH Port Forwarding. Find right in the FreeBSD instant. Further, everything is as usual - NEXT, NEXT, NEXT, we obtain the installed system.

Main teams

Let's now consider the main commands to work with KVM.

Getting a list of all virtuals:

sudo Virsh List --All

Receiving information about a specific virtual machine:

sudo Virsh Dominfo FreeBSD10

Run the virtual:

sudo Virsh Start FreeBSD10

Stop virtual about:

sudo Virsh Shutdown FreeBSD10

Rigid to kill a virtual (despite the name, it not Removal):

sudo Virsh Destroy FreeBSD10

Rebut a virtual:

sudo Virsh Reboot FreeBSD10

Build virtual:

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 the dialog mode - as described above):

sudo Virsh.

Editing the properties of virtuals in XML, including here you can change the limit on the amount of memory and so on:

sudo Virsh Edit FreeBSD10

Important! Comments from edited XML, unfortunately, are deleted.

When a virtuette is stopped, the disc can also be delivered:

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 is most likely not like that the disc suddenly became more or less. At best, it will boot in emergency mode with a proposal to redeem the disk. Most likely, you should not want to do so. It is much easier to be to start a new virtual and toggle all the data on it.

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

Settings Network

An interesting question - how to determine which IP address received a virtual one after downloading? In KVM, this is done by cunning. I eventually wrote such a script on 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 \u003d SYS .stderr)

iF LEN (SYS .ARGV)< 2 :
EPRINT ("Usage:" + sys .argv [0] + " " )
EPRINT ("Example:" + sys .argv [0] + "FreeBSD10")
sYS .EXIT (1)

if os .geteuid ()! \u003d 0:
EPRINT ("Error: You Shold Be Root")
EPRINT ("Hint: Run` Sudo" + sys .argv [0] + "...` ");
sYS .EXIT (1)

iF subprocess .call ( "Which Arring 2\u003e & 1\u003e / Dev / NULL", Shell \u003d True)! \u003d 0:
EPRINT ("Error: Arring nOT FOUND." )
EPRINT ( "Hint: Run` Sudo Apt-Get Install Arruing`)
sYS .EXIT (1)

Domain \u003d SYS .Argv [1]

if not re .match ("^ * $", domain):
EPRINT ( "ERROR: INVALID CHARACTSERS IN DOMAIN NAME")
sYS .EXIT (1)

Domout \u003d Subprocess .Check_output ("Virsh DumpXML" + Domain + "|| True",
Shell \u003d True)
Domout \u003d Domout.Decode ("UTF-8"). Strip ()

if Domout \u003d\u003d "":
# Error Message Already Printed by dumpxml
sYS .EXIT (1)

Doc \u003d ElementTree.FromString (Domout)

# 1. LIST ALL NETWORK INTERFACES
# 2. RUN `Arping` on every interface in parallel
# 3. GREP Replies
cmd \u003d "(iFconfig | cut -d" "-f 1 | grep -e". "|" + \
"Xargs -p0 -i IFACE Arping -i IFACE -C 1 () 2\u003e & 1 |" + \
"Grep" Bytes From ") || True"

for Child in Doc.iter ():
if child.tag \u003d\u003d "Mac":
Macaddr \u003d Child.attrib ["address"]
Macout \u003d subprocess .Check_output (CMD.Format (Macaddr),
Shell \u003d True)
pRINT (Macout.Decode ("UTF-8"))

The script works both with the Default network and with the bridged network whose setting we will look next. However, in practice, much more convenient to configure KVM so that it always assigns the same IP addresses to guest systems. For this network setup rules:

sudo Virsh Net-Edit Default

... about this way:

>



>

After making these edits


>

... and replace something like:




>

Restart the guest system and check that it received IP by DHCP from the router. If you want to guest System had a static IP address, it is configured as usual within the guest system itself.

VIRT-MANAGER program

You may also be interested in the program Virt-Manager:

sudo Apt-Get Install Virt-Manager
sudo UserMod -A -G Libvirtd Username

This is the main window:

As you can see, the Virt-Manager is not only the GUI for virtuals running locally. With it, you can manage virtual machines working on other hosts, as well as look at beautiful schedules in real time. I personally find especially convenient in the Virt-Manager what you do not need to search for configs, which port is spinning a VNC of a particular guest system. You just find a virtual about the list, you make a double click, and you get access to the monitor.

Even with the help of Virt-Manager, it is very convenient to make things that would otherwise require the time-consuming editing of XML files and in some cases performing additional commands. For example, renaming virtual machines, configuring CPU Affinity and similar things. By the way, the use of CPU Affinity significantly reduces the effect of noisy neighbors and the effect of virtual machines on the host system. If possible, use it always.

If you decide to use KVM as a substitute for VirtualBox, take into account that they cannot divide the hardware virtualization. To KVM earn in your desktop, you will not only have to stop all virtuals in VirtualBox and Vagrant, but also restart the system. I personally find KVM much more convenient than VirtualBox, at a minimum, because it does not require the command sudo / SBIN / RCVBOXDRV Setup After each core update, C Unity works adequately, and in general it allows you to hide all the windows.

KVM (Virtual Machine based on kernel or Kernel-based Virtual) - Free Virtualization Software with Open source code. You can create several virtual machines (VM), each virtual machine has its own virtual equipment, such as disk, processor, rAM etc. It was included in the main part of the Linux kernel in version 2.6.20 kernel.

If you are looking for an alternative VirtualBox.We strongly recommend using KVM. We also personally use this amazing virtualization software.

Installing KVM Ubuntu 17.04

To install KVM, you must have the following preliminary blanks.

  1. Enable virtualization in the system BIOS.
  2. Check the system CPU if it supports virtualization. Follow the command below.

egrep - C '(VMX | SVM)' / Proc / Cpuinfo

When you get a conclusion from the above command or 1, or more, this means that the processor supports virtualization other than 0 or less means that it does not support.

3. Check the architecture Ubuntu. 16.04 LTS by running one command i.e

X86_64 is a 64-bit kernel.
I386, i486, i586 or i686 are a 32-bit kernel.

The 32-bit OS is limited to 2 GB of RAM as much as possible for this virtual machine.
The 32-bit kernel will be placed only a 32-bit guest core, whereas in the 64-bit core can be both 32-bit and 64-bit guest O.S.

Perform steps to install KVM on Ubuntu

In this section we will write down the steps to install KVM. In our previous post we have learned. Perhaps it will also be interesting for you.

1. Installing KVM Ubuntu 17.04 and other dependent packages

In Ubuntu 17.04 LTS you can use the command aPT or APT-Get Both. There will be no differences in the packages installed using the APT or APT-GET command, so you are good here.

sudo Apt Update.

sudo Apt Install QEMU - KVM LIBVIRT - Bin Bridge - Utils

2. Learn about new users and a KVM software group.

After installing the packages, some additions will occur in the number of users and groups.

(A) Two users are created.
- libvirt-qmu
- LIBVIRT-DNSMASQ

[Email Protected] : ~ $ Tail - 2 / etc / passwd

lIBVIRT - QEMU: X: 64055: 129: Libvirt QEMU,: / var / libvirt: / bin / false

libvirt - DNSMASQ: X: 121: 130: Libvirt DNSMASQ,: / var / lib / libvirt / dnsmasq: / bin / false

s. [Email Protected] :~ $

B) Two groups will be created.

- KVM.
- Libvirtd.

[Email Protected] : ~ $ Tail - 2 / etc / group

kVM: X: 129:

libvirtD: X: 130: Sharad

[Email Protected] :~ $

You may notice that the so-called "Sharad" used is a member of the LIBVIRTD group. This means that this user can use KVM.

3. Check the KVM installation

It is quite simple to check the KVM installation. Run the team -

Virsh - C qmu: /// System List

For the first time he will show a mistake.

error: FAILED TO CONNECT TO THE HYPERVISOR

error: Failed to Connect Socket To '/ VAR / RUN / LIBVIRT / LIBVIRT-SOCK': Permission Denied.

[Email Protected] :~ $

To solve this problem, you must go out and log in on your desktop. Indicates that the current user must re-log in.

After logging into the system, restart the command. This time you must get the result as indicated below. It is empty because the virtual machine is not created.

[Email Protected] : ~ $ Virsh - C qemu: /// System List

ID NAME STATE.

—————————————————-

[Email Protected] :~ $

4. Install the Virtual Machine Manager

Here we use Virtual Machine Manager, which is a desktop application for managing KVM virtual machines via libvirt.

Run this command to install the virtual machine manager.

sudo Apt Install Virt - Manager

You can open the virtual machine manager by entering it in the Dash Home.Click the icon, it will open the application.

To open the Virtual Machine Manager through command line, enter -

virt - Manager.

Previously, when we installed KVM in Ubuntu 14.04 LTS Desktop, we encountered a problem when creating the first virtual machine, but we decided it very easily. In Ubuntu 16.04 LTS Desktop, we did not find such a problem.

If you have questions about the topic "Installing KVM Ubuntu 17.04" - Write them to us in the form for comments. We will help you to deal with your question much faster.

If you have found a mistake, please select the text fragment and click Ctrl + Enter..