Total Pageviews

Wednesday, 21 December 2016

Linux KVM (Kernel-based Virtual Machine) !!!

So far I covered virtualization concepts of VMware (ESXi host and VMs) and Solaris (LDOMS), In this post I am going to discuss about virtualization in Linux which is KVM (Kernel-based Virtual Machine).

Soon after installing Linux OS on top of some high configuration server, we have to install few packages and enable virtualization at kernel level to build and configure VMs (Virtual Machines).

In my Ubuntu machine, I am going to install some packages like kvm, qemu (Quick Emulator) and libvirtd-bin to work with CLI of KVM which is virsh (Virtualization Shell).

QEMU is opensource hosted hypervisor to achieve hardware virtualization, we use qemu so that we can create VMs with different CPU architecture. If we use KVM, we can create and manage VMs with the same architecture of CPU as host machine.

Let me explain you in detail with steps,

At first lets update our apt (Advanced Packaging Tool)....

root@ubuntu-kvm:~# apt-get update
Hit:1 http://us.archive.ubuntu.com/ubuntu yakkety InRelease
Get:2 http://us.archive.ubuntu.com/ubuntu yakkety-updates InRelease [102 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu yakkety-backports InRelease [102 kB]
Get:4 http://security.ubuntu.com/ubuntu yakkety-security InRelease [102 kB]
Fetched 306 kB in 3s (78.1 kB/s)
Reading package lists... Done
root@ubuntu-kvm:~#

Before installing, let us check for the packages which we are going to install now.

root@ubuntu-kvm:~# apt list --installed | grep -i libvirtd

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

root@ubuntu-kvm:~#
root@ubuntu-kvm:~# apt list --installed | grep -i virt-manager

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

root@ubuntu-kvm:~#
root@ubuntu-kvm:~# apt list --installed | grep -i qemu-kvm

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

root@ubuntu-kvm:~#

Now I will install qemu-kvm package which acts as hypervisor for managing our guest machines. Here I am giving normal kvm also, just to show one thing...

root@ubuntu-kvm:~# apt-get install kvm qemu-kvm
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'qemu-kvm' instead of 'kvm'
The following additional packages will be installed:
  cpu-checker ipxe-qemu libaio1 libasound2 libasound2-data libasyncns0 libbluetooth3 libboost-iostreams1.61.0

  ****************        OUTPUT TRUNCATED     ****************

Need to get 14.4 MB of archives.
After this operation, 56.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 libjpeg-turbo8 amd64 1.5.0-0ubuntu1 [113 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 libogg0 amd64 1.3.2-1 [17.2 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 libiscsi7 amd64 1.17.0-1 [55.6 kB]

****************        OUTPUT TRUNCATED     ****************

Fetched 14.4 MB in 3s (4,468 kB/s)
Extracting templates from packages: 100%
Selecting previously unselected package libjpeg-turbo8:amd64.
(Reading database ... 61611 files and directories currently installed.)
Preparing to unpack .../00-libjpeg-turbo8_1.5.0-0ubuntu1_amd64.deb ...
Unpacking libjpeg-turbo8:amd64 (1.5.0-0ubuntu1) ...

****************        OUTPUT TRUNCATED     ****************

Setting up libpulse0:amd64 (1:9.0-2ubuntu2.1) ...
Setting up libsdl1.2debian:amd64 (1.2.15+dfsg1-4) ...
Setting up qemu-system-x86 (1:2.6.1+dfsg-0ubuntu5.1) ...
Setting up qemu-kvm (1:2.6.1+dfsg-0ubuntu5.1) ...
Processing triggers for libc-bin (2.24-3ubuntu1) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (231-9git1) ...                          DONE

root@ubuntu-kvm:~#

This time if we check for the package,

root@ubuntu-kvm:~# apt list --installed | grep -i qemu-kvm

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

qemu-kvm/yakkety-updates,yakkety-security,now 1:2.6.1+dfsg-0ubuntu5.1 amd64 [installed]
root@ubuntu-kvm:~#

As I explained above, so far whatever we did, is for enabling virtualization only. We still need some other packages for creating and managing VMs.

root@ubuntu-kvm:~# virsh list
The program 'virsh' is currently not installed. You can install it by typing:
apt install libvirt-clients
root@ubuntu-kvm:~#                              That is why we can't work with virt shell commands...

Now let us install packages related to libvirt-bin, entire binary package of libvirt and bridge-utils which is responsible for Ethernet bridging (VMs network connectivity).

root@ubuntu-kvm:~# apt-get install libvirt-bin bridge-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:

  ****************        OUTPUT TRUNCATED     ****************

Need to get 4,952 kB of archives.
After this operation, 20.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 libavahi-common-data amd64 0.6.32-1ubuntu1 [22.0 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 libavahi-common3 amd64 0.6.32-1ubuntu1 [21.6 kB]

****************        OUTPUT TRUNCATED     ****************

Get:19 http://us.archive.ubuntu.com/ubuntu yakkety/main amd64 vbetool amd64 1.1-4 [11.5 kB]
Fetched 4,952 kB in 1s (2,813 kB/s)
Selecting previously unselected package libavahi-common-data:amd64.
(Reading database ... 62254 files and directories currently installed.)
Preparing to unpack .../00-libavahi-common-data_0.6.32-1ubuntu1_amd64.deb ...
Unpacking libavahi-common-data:amd64 (0.6.32-1ubuntu1) ...
****************        OUTPUT TRUNCATED     ****************

Setting up libvirt-daemon (2.1.0-1ubuntu9.1) ...
Setting up libvirt-clients (2.1.0-1ubuntu9.1) ...
Setting up libvirt-daemon-system (2.1.0-1ubuntu9.1) ...
Adding group `libvirt' (GID 118) ...
Done.
Adding user `libvirt-qemu' to group `libvirt-qemu' ...
Adding user libvirt-qemu to group libvirt-qemu
Done.
Created symlink /etc/systemd/system/multi-user.target.wants/libvirt-guests.service → /lib/systemd/system/libvirt-guests.service.

****************        OUTPUT TRUNCATED     ****************

Setting up libvirt-daemon dnsmasq configuration.
Setting up libvirt-bin (2.1.0-1ubuntu9.1) ...
Processing triggers for libc-bin (2.24-3ubuntu1) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (231-9git1) ...
root@ubuntu-kvm:~#

Now we can check with "virsh" commands....

root@ubuntu-kvm:~# virsh list
 Id    Name                           State
----------------------------------------------------
root@ubuntu-kvm:~#

root@ubuntu-kvm:~# virsh -c qemu:///system list
 Id    Name                           State
----------------------------------------------------
root@ubuntu-kvm:~#

To work with GUI part of virtual machine management we need virt-manager.

root@ubuntu-kvm:~# virt-manager
The program 'virt-manager' is currently not installed. You can install it by typing:
apt install virt-manager

root@ubuntu-kvm:~#

So I am installing it now, if you need GUI you have to install it.

root@ubuntu-kvm:~# apt-get install virt-manager ubuntu-vm-builder
Reading package lists... Done                            
           ubuntu-vm-builder is different utility to create and manage virtual machines in ubuntu.
Building dependency tree
Reading state information... Done

The following additional packages will be installed:

****************        OUTPUT TRUNCATED     ****************

Setting up gir1.2-vte-2.91:amd64 (0.44.2-1ubuntu3) ...
Setting up indicator-application (12.10.1+15.04.20150128-0ubuntu1) ...
Setting up gir1.2-appindicator3-0.1 (12.10.1+16.10.20160905-0ubuntu1) ...
Setting up virt-manager (1:1.3.2-3ubuntu3) ...
Processing triggers for libc-bin (2.24-3ubuntu1) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (231-9git1) ...

Processing triggers for libgdk-pixbuf2.0-0:amd64 (2.34.0-1ubuntu2) ...
root@ubuntu-kvm:~#

root@ubuntu-kvm:~# apt list --installed | grep -i virt-manager

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.


virt-manager/yakkety,yakkety,now 1:1.3.2-3ubuntu3 all [installed]
root@ubuntu-kvm:~#

root@ubuntu-kvm:~# apt list --installed | grep -i ubuntu-vm-builder

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

ubuntu-vm-builder/yakkety,yakkety,now 0.12.4+bzr494-0ubuntu1 all [installed]
root@ubuntu-kvm:~#

As of now, we installed required packages and ready for creating some VMs.

To create VMs from CLI, 

root@ubuntu-kvm:~# virt-install

WARNING  KVM acceleration not available, using 'qemu'
ERROR
--name is required
--memory amount in MiB is required
--disk storage must be specified (override with --disk none)
An install method must be specified
(--location URL, --cdrom CD/ISO, --pxe, --import, --boot hd|cdrom|...)

root@ubuntu-kvm:~#

To start working with GUI virt-manager, 



Then a window will be popped, by clicking on "Create a Virtual Machine" we can start creating VMs.


That's it for this post, we covered what packages need to be installed and how to enable virtualization in Linux machine. In the next post, I will discuss about how to create/manage VMs.

######################################################################################

No comments:

Post a Comment