Virtualization on Linux
Virtualization on Linux
Using KVM and libvirt
Using KVM and libvirt
Matt Surico
Long Island Linux Users Group 11 March, 2014
What will we talk about?
What will we talk about?
● Rationalizing virtualization ● Virtualization basics
● How does it work under Linux? ● Setting up a virtual host
Why virtualize? - Part 1
Why virtualize? - Part 1
Why virtualize? - Part 2
Why virtualize? - Part 2
Other reasons to virtualize
Other reasons to virtualize
● Ease of creating new servers (cloning) ● Ad-hoc projects (proof of concept)
● Experimentation with new distributions ● Self-Instructional situations
Virtualization Architecture
Virtualization Architecture
● One key component is the hypervisor.
● A hypervisor is software (or hardware, or even
firmware) that creates an interface between a
guest operating system and a virtual host so that virtual machines can be run.
● The hypervisor's job is to create and/or to
present a virtual operating platform to the virtual machine (an abstraction).
Hypervisor Diagrams
Hypervisor Diagrams
● We will briefly look at two general types of
hypervisors:
– Native (aka “Bare Metal”, or “Type 1”) – Hosted (aka “Type 2”)
Bare Metal Hypervisor
Bare Metal Hypervisor
Hosted Hypervisor
Hosted Hypervisor
KVM
KVM
● Simply put, this allows the Linux kernel to be a
hypervisor
● Has been in the kernel mainline since 2.6.20
● Contains virtualization extensions (Intel VT and
AMD-V), and loadable kernel modules (kvm.ko plus either kvm-intel.ko or kvm-amd.ko)
● Exposes the /dev/kvm interface to a host running
libvirt
libvirt
● C library with package bindings for many other languages like
Ruby, Java, python, perl, etc.
● A toolkit for managing virtualization ● Provides:
– Remote management using TLS encryption and x509 certificates
– Remote management authenticating with Kerberos and SASL
– Local access control using PolicyKit
– Zero-conf discovery using Avahi multicast-DNS
– Management of virtual machines, virtual networks and storage
libvirt diagram
How to check your CPU
How to check your CPU
● Use /proc/cpuinfo and look at the flags. There are different flags for Intel vs. AMD
● Intel
– vmx = Intel VT-x (basic virtualization) - required
– ept = Extended Page Tables
– vpid = decreases TLB flushes during context switching between
guests
● AMD
– svm = AMD SVM (basic virtualization) - required
Building the demo
Building the demo
● We'll take a brief walk through the steps taken to
prepare the laptop for today's demo
– Verify the CPU will work – Add storage to laptop
– Install CentOS 6.4 (the host OS) – Include virtualization packages
● Once these steps are done, virtual machines can
Build: CPU/RAM
Build: CPU/RAM
● The CPU in the laptop is AMD A4-3305M (dual core, 800 MHz, 512 KB cache) ● The command used to check the processor was:
[matt@aquila ~]$ grep flags /proc/cpuinfo | uniq
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx
mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc rep_good nonstop_tsc extd_apicid aperfmperf pni monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt cpb npt lbrv svm_lock nrip_save pausefilter
● Laptop has 3 GB RAM
● FYI: Home machine (dedicated virtual host) has Intel(R) Core(TM) i5-3570K CPU,
Build: Adding storage
Build: Adding storage
● Laptop has a single internal hard drive, dual boot
Ubuntu 13.04 and “a certain proprietary OS that came with the laptop.”
● Current hard drive didn't have enough space to setup
a third operating system plus the virtual disks for multiple VMs
● Used an external USB 3.0 drive (500 GB)
● Allows for total removal of the storage to operate the
Build: Partitioning storage
Build: Partitioning storage
During the installation of CentOS 6.4, the external drive showed up as /dev/sdb, so it was partitioned as such:
● /dev/sdb1 = /boot (1 GB) ● /dev/sdb2 = swap (4 GB)
● /dev/sdb3 = Physical Volume for LVM (the rest of the
drive)
– vg_kvm = Volume Group (~460 GB) – 334 GB allocated to logical volumes
Build: Logical Volumes
Build: Logical Volumes
[matt@aquila ~]$ sudo lvs vg_kvm LV VG Attr LSize libvirtKVMLV vg_kvm -wi-ao--- 300.00g rootKVMLV vg_kvm -wi-ao--- 15.00g usrKVMLV vg_kvm -wi-ao--- 15.00g varKVMLV vg_kvm -wi-ao--- 4.00g
● /dev/mapper/vg_kvm-libvirtKVMLV on /var/lib/libvirt type ext4 ● /dev/mapper/vg_kvm-rootKVMLV on / type ext4
● /dev/mapper/vg_kvm-usrKVMLV on /usr type ext4 ● /dev/mapper/vg_kvm-varKVMLV on /var type ext4
Build: CentOS installation
Build: CentOS installation
● CentOS 6.4 installed with “Virtual Host”
profile.
● Also added some other graphical
convenience packages
● Important: under Virtualization, pick
“Virtualization Tools”
Working with VMs
Working with VMs
Several Open Source tools available:
● virsh: command line, provided by libvirt ● Virtual Machine Manager: GUI
● oVirt: web application
Networking
Networking
● One or more virtual networks may be
created within the virtual host
● Virtual machines may be outfitted with one
or more virtual NICs
● The dnsmasq lightweight server provides
DNS and DHCP services for the virtual network
Networking: libvirt
Time for a demo!
Time for a demo!
What we'll see:
● Use of virsh and virt-manager
● Creating and managing VMs (including
cloning)
● Creating and managing virtual networks ● Provisioning additional storage for VMs