
Rationale and Options
I want to become more familiar with KVM and the related technologies, so I’ll be using KVM as the basis of running my VM’s
Installing the required packages
My CentOS install was pretty minimal, partly so that I would be able to understand what’s required for the various services that I will be setting up.
I pretty much followed the instructions on this site : http://www.tecmint.com/install-and-configure-kvm-in-linux/ I’ll add my own comments here to describe what’s going on under-the-covers.
1) Check for the ability to run hardware based virtualization
INTEL ONLY
Run this grep command, and ensure that some output is generated. If there is no output, then the CPU does not support hardware based Virtualization.
grep vmx /proc/cpuinfo
What’s being done here?
Linux supports querying the hardware using a special filesystem type called /proc The reason to use a filesystem interface to hardware is that it allows users to use their familiar commands like cd, grep,cat to work with the hardware.
The cpuinfo “file” contains information about the CPU itself. A snipped of output looks like this
sh-4.2# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 45
model name : Intel(R) Core(TM) i7-3820 CPU @ 3.60GHz
stepping : 7
microcode : 0x710
cpu MHz : 1298.250
cache size : 10240 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
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 eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
bogomips : 7204.22
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
The ‘vmx’ string that we’re grepping for is included in the “flags” line. The flags tells us what sorts of things the CPU supports. Among other things this CPU (and Intel Core i7) supports sse2 and vmx. The SSE2 instructions are not related to VIrtualization (https://en.wikipedia.org/wiki/SSE2) but the VMX ones are. Somewhat confusingly, “vmx” is reported by cpuinfo – but these instructions are often called “VT-x” (https://en.wikipedia.org/wiki/X86_virtualization#Intel_virtualization_.28VT-x.29)
If the vmx flag is not shown, it might be disabled in the BIOS.
2) Check to see that the kvm kernel module is loaded
sh-4.2# lsmod|grep kvm
kvm_intel 148081 0
kvm 461126 1 kvm_intel
What’s happening here?
We’re checking to see that the kernel has a “module” called kvm installed and running. Kernel modules are pieces of code that execute in the kernel address space and interact closely with the kernel. Other modules are things like IP,nfs or disk drivers. kernel modules allow developers to extend the functionality of the kernel without having to re-compile the “main” linux kernel. Some kernel modules are dynacmically loadable, meaning that the running machine does not need to be rebooted in order to install and run a module.
The kvm module provides extra virtualization support in the linux kernel. It is part of the set of tools that we need to make virtualization work, but not the only part. The kvm module specifically it allows the QEMU “virtual machine emulator” to directly access the special hardware support (VT-X) on the CPU. See also KVM FAQ
3) Update “yum”
sh-4.2# yum update
Loaded plugins: axelget, fastestmirror, langpacks
repomd.xml | 3.6 kB 00:00:00
base/group | 729 kB 00:00:01
base/primary | 2.5 MB 00:00:02
base/primary_db
.....
vte291 x86_64 0.38.3-2.el7 base 311 k
xcb-util-image x86_64 0.4.0-2.el7 base 15 k
xcb-util-keysyms x86_64 0.4.0-1.el7 base 10 k
Transaction Summary
=======================================================================================================================================
Install 16 Packages (+58 Dependent packages)
Upgrade 772 Packages
Total size: 976 M
Total download size:
What’s happening here?
yum is the default package manager for CentOS. Package managers enable users to update their running software without having to download source code and compile it. Another function of package managers is to ensure that dependencies are met.
Issuing yum, update ensures that the latest packages are installed on the system. Generally speaking, we hope that the latest software fixes more bugs than it introduces.
Yum will connect over the internet to pull down the latest versions and install them. The operation may take several minutes depending on how many packages are installed, how many are out of date, the speed of internet connection and how fast the local storage is.
4) Disable selinux
[root@arches current]# setenforce 0
setenforce: SELinux is disabled
What’s happening here?
SELinux… who knows?… If in doubt, I tend to turn it off.
5) Install qemu tools for kvm
[root@arches current]# # yum install qemu-kvm qemu-img
What’s happening here?
qemu is the main software that actually enables virtualization/emulation. KVM is really just a kernel module that allows user-land processes (the virtual machines) to access the virtualization instructions/support on modern x86 hardware. Without KVM, QEMU would still work, but would not be able to use the hardware assistance from things like VT-X.
The qemu-kvm package contains kvm specific files for qemu. For instance bios.bin, drivers for NICs and VGA drivers. Use the command rpm -ql qemu-kvm to see the list of files in that package.
The qemu-img package contains 3 binary files and two manpages (qemu-img, qemu-nbd). These files provide support for virtualization specific functions on files. such as snapshot, thin-provisioning, converting image formats etc.
6) Install virtualization tools
The above packages (qemu-kvm, qemu-img) provide the infrastructure to run a virtual machine – but do not contain any way to create, or manage them. That’s the job of the libvirt and virsh software suite.
[root@arches current]# yum install virt-manager libvirt libvirt-python libvirt-client
[root@arches current]# yum groupinstall virtualization-client virtualization-platform virtualization-tools
What’s happening here?
Installing more support packages that make working with VM’s and guest OS easier…
libvirt : rpm -ql says “Contains no files”
libvirt-client : virsh,
virt-manager : Tools in python
libvirt-python : Python examples, python-objects (.pyo), compiled shared object (.so)
Use yum group info <groupname> to get list of packages in the group
virtualization-client : virt-install,virt-manager, virt-viewer, virt-top
virtualization-platform : libvirt, libvirt-client, libvirt-cim, libvirt-java (others)
virtualization-tools : libguestfs, libguestfs-tools
7) Restart libvirtd
[root@arches current]# systemctl restart libvirtd
[root@arches current]# systemctl status libvirtd
What’s happening here?
libvirtd is the daemon that manages virtual machines and can also migrate VM’s between hosts.
A working libvirtd should return status similar to this:
[root@arches current]# systemctl status libvirtd
● libvirtd.service - Virtualization daemon
Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2016-01-17 09:56:54 EST; 1min 45s ago
Docs: man:libvirtd(8)