Chapter 6. Class #6 - Virtualization via KVM & the Bash Shell

Table of Contents

Intro to KVM
Installing KVM
KVM Configuration
KVM as a Service
Commands to Manipulate KVM
Securing KVM
Additional Notes & Considerations for KVM
Intro to Bash
Installing Bash
Bash Configuration
Commands to Manipulate Bash
Additional Notes & Considerations for Bash
Reference Material for this Chapter

In this chapter we'll dig into two important topics that have persisted and grown with the advent of the computing age. Virtualization has been around for many years, and today comes in many flavors. The Red Hat version is called KVM, which stands for Kernel Virtual Machine. To quote the Red Hat website:

Virtualization in Red Hat Enterprise Linux 6 is carried out by KVM (Kernel-based Virtual Machine). KVM is a full virtualization solution built into Red Hat Enterprise Linux 6.

--Red Hat Virtualization Guide

We'll also talk about the Bash shell, which is the default command line interactive environment in Red Hat.

Intro to KVM

KVM is Red Hat's choice of hypervisors. It's an open source product, well written, and has a solid foot hold in the industry. We'll consider a basic use and understanding of this technology. For a deeper understanding of this are, consider Red Hat Enterprise Virtualization Wikipedia Article .

Table 6.1. Common Virtualization Terms

Term Description
Physical Machine An actual physical machine with RAM, disk space, etc. This is often the host machine that houses the virtual guests.
Virtual Machine A logical construct that exists in software that provides emulated hardware and/or software capabilities. Installation of an operating system on a VM can run an independent OS and perform work as though it were a physical machine.
Hypervisor A specialized OS that provides virtual machines.
Xen A hypervisor previously available on Red Hat operating systems that was implemented as a modified version of the Linux kernel.
KVM Kernel Virtual Machine, the hypervisor Red Hat currently supports on RHEL6. It is implemented within (as a set of kernel modules) the mainstream Linux kernel.
Host The operating system that runs on a physical machine hosting virtual machines (i.e. the hypervisor).
Guest The operating system that runs on a virtual machine.

The list below outlines the RHEL6 KVM requirements.

  • 64-bit Intel or AMD processor. To confirm, search '/proc/cpuinfo' for the string 'lm' on the flags line.
  • CPU Hardware assisted virtualization extensions (enabled in BIOS). To confirm, search '/proc/cpuinfo/' for the string 'vmx' (for Intel) or 'svm' (for AMD).
  • 64-bit version of RHEL6 (or equivalent). To confirm, look for 'x86_64' in the output of `uname -m`.

Installing KVM

KVM installation is relatively painless. It's possible to install individual components and packages. However, for a comprehensive installation of virtualization tools and processes, the following groups should be installed:[14]

  1. Virtualization
  2. Virtualization Tools
  3. Virtualization Client
  4. Virtualization Platform

KVM Virtualization Components

  1. KVM kernel modules
  2. libvirt
  3. virsh Virtualization Shell
  4. `virt-manager`

KVM Configuration

The default location for KVM configuration files is '/etc/libvirtd'. The individual VM configuration files are in xml format within that directory. The default location for VM images is '/var/lib/libvirtd/images'. Additional locations can be configured for the images.

KVM as a Service

The KVM service is libvirtd. The service follows the typical Red Hat interactive format: `service libvirtd {start|stop|restart|status|etc}`.

Commands to Manipulate KVM

Listed below are several valuable commands for managing virtual machines as well as the hypervisor.

Table 6.2. Valuable VM Management Commands

`virsh list [- -all]` List running VMs. Pass the --all flag to list them all.
`virsh start <vm name or id>` Power on a virtual machine.
`virsh shutdown <vm name or id>` Gracefully shut down a virtual machine.
`virsh destroy <vm name or id>`[a] Power off a virtual machine.
`virsh console <vm name or id>` Connect to a virtual machine console (requires guest configuration).
`virsh autostart <vm name or id>` Set a VM to start at boot.
`virt-edit $vm1 /etc/grub.conf` Edit the grub configuration file within a virtual machine from the host.[b]
`virt-manager` The hypervisor management console.
`virt-viewer` Viewer for a virtual machine.
`virt-clone -o <vm> -n <new-name> -f <new-file> --prompt` Clone an existing virtual machine. [c]
`virsh undefine <domain-id> --remove-all-storage` Deletes a virutal machine along with the storage disks.
CTRL + ALT Release the mouse from a virtual machine console.

[a]

Note the difference between 'shutdown', 'destroy', and 'undefine' regarding VMs. The 'destroy' term is misleading. 'shutdown' requests a graceful shutdown. 'destroy' forces a poweroff, as if the plug had been pulled. 'undefine deletes a VM configuration as well as (optionally) the file(s) on disk. In some instances, if it's necessary to 'destroy' the machine, data loss may result.

[b] Note that the VM must be shut down, and the package libguestfs-tools must be installed.

[c] The --prompt flag can be used and the command will prompt for missing information.


[Note] Difference Between virt-manager & virsh

In general, the `virt-manager` invokes the interface to interact with the hypervisor. The `virsh` series of commands interacts with individual machines.

Securing KVM

KVM by default, as it comes out of the box, is fairly secure. If there are additional hypervisors to be managed, additional ports may need to be opened on the firewall. Also, if additional storage space needs to be added instead of or in addition to the default location, SELinux contexts will need to be considered.

Additional Notes & Considerations for KVM

Lets consider creating additional virtual machines. We went through the step-by-step process using `virt-manager` in our first class. Let's now consider creating a machine from the command line as well as cloning a machine.

Installing a VM via the command line is the fastest way to complete the task. It's actually pretty simple once you know the command as it's shown below. Remember this acronym: 'nrlx'. Those are the only mandatory parameters to the virt-install command. You can add the '--prompt' option, and you'll be prompted for missing information. That's all you'll need to create a VM from the command line. Here's the complete command:

    `virt-install -n s4vm3 -r 768 -l http://192.168.5.250/cblr/links/RHEL_6.0-x86_64/ \
    --disk path=/var/lib/libvirt/images/s4vm1.img -x ks=http://192.168.5.200/vm.ks --prompt`

Here is a listing of the options. Let's talk about each one.

    -n s4vm3
    -r 768
    -l http://192.168.5.250/cblr/links/RHEL_6.0-x86_64/
    --disk path=/var/lib/libvirt/images/kvm_virt1.img
    -x ks=http://192.168.5.200/vm.ks
    --prompt


[14] Run the command `yum -y groupinstall virtualization virtualization-tools virtualization-client virtualization-platform`.