Installing and Running a Headless Virtualization Server

In recent years, hardware virtualization has become commonplace in the computing industry and more available to end users. The idea behind it is a noble one. Why invest in allocating more server hardware and not utilize it to its full potential, when instead you can consolidate it all onto one or a few servers and share their resources?

In this article, I focus on full hardware virtualization. This refers to the creation of a virtual machine with enough simulated hardware to act like a real computer with its own operating system. In turn, this virtual machine, or virtual guest, is enabled and running on top of a host machine. The software that controls virtualization is called the hypervisor. The hypervisor runs on the host machine.

Virtualization typically is used to consolidate hardware servers, reduce energy consumption, simplify server management and ease migration/recovery (in the situation of a failure). It sometimes is accomplished with hardware that needs to be accessed remotely, as the hardware may reside in what may not be a local data center. With that in mind, the hardware's operating system also may be configured without a graphical environment (meaning one that also includes a lack of attached monitor and input devices). This commonly is referred to as running headless. This article assumes that you have Secure Shell or SSH access to what will become the host machine.


Prior to configuring the virtual machines, install the appropriate packages from your distribution's package repository. These packages include the libvirt library that provides a simple virtualization API, client-side utilities to access the library and manage the virtual machines, a Python virtual machine installer utility and the userspace components to the kernel-based virtual machine (KVM).

Note: libvirt is an open-source API, dæmon and management utility for managing platform virtualization. KVM is a virtualization infrastructure that turns the Linux kernel into a hypervisor. It requires a processor with hardware virtualization extensions.

Depending on your distribution, the package names may differ. On Red Hat/CentOS, they are labeled as libvirt, libvirt-client, python-virtinst and qemu-kvm. On Debian/Ubuntu, they are labeled as libvirt, libvirt-bin, python-virtinst and qemu-kvm.

Enable the libvirt dæmon to run on all appropriate runlevels at system boot up and manually start the service:

$ sudo /sbin/chkconfig libvirtd on
$ sudo /sbin/service libvirtd start
Starting libvirtd daemon:                   [  OK  ]

View the status of the dæmon and validate that it is running:

$ sudo /sbin/service libvirtd status
libvirtd (pid  2482) is running...

When the libvirt package is installed, /var/lib/libvirt/ is used as the default location for all virtual machines and related files. If you prefer to relocate this to a more redundant and sometimes external piece of storage hardware, you are welcome to do so. However, for this article, I'm going to continue with the default and place the operating system's installation ISO image in the /var/lib/libvirt/boot/ directory path.

Installing a Virtual Machine

Before beginning, view the list of locally installed virtual machines. Assuming that this is following a fresh installation, there shouldn't be any listed:

$ sudo /usr/bin/virsh list --all
 Id    Name                           State

With libvirt, virtual machines are defined by a specially formatted XML file. You can read more on this XML format at the libvirt project site. Fortunately enough, you don't have to touch the XML code and can rely on virt-install. The virt-install utility is used to provision new virtual machines and reduce most if not all complications.

For instance, if you want to define a new virtual machine named CentOS6.5-vm1 with one virtual CPU, 512MB of RAM and so on, you can do so in the following way:

$ sudo /usr/sbin/virt-install \
> --name CentOS6.5-vm1 \
> --description "CentOS 6.5 64 bit VM1" \
> --ram=512 \
> --vcpus=1 \
> --cpu host \
> --hvm \
> --disk path=/var/lib/libvirt/images/centos6.5-vm1,size=3 \
> --cdrom /var/lib/libvirt/boot/CentOS-6.5-x86_64-minimal.iso \
> --graphics vnc

Starting install...
Allocating 'centos6.5-vm1'               | 3.0 GB     00:00
Creating domain...                       |    0 B     00:00
Cannot open display:
Run 'virt-viewer --help' to see a full list of available command
line options. Domain installation still in progress. You can
reconnect to the console to complete the installation process.

The --cpu host option optimizes the CPU properties for the VM by exposing the host's CPU's configuration to the guest, while the --hvm option requests the library for the use of full hardware virtualization. The --cdrom option points to the installer disc image, and the --disk option gives the name (with absolute location) and size (in gigabytes) of the virtual disk. The --graphics option allows VNC access to the virtual machine, which will be utilized later in this article. Other supported options include network configuration, boot priorities and more.


Petros Koutoupis is a software developer at IBM for its Cloud Object Storage division (formerly Cleversafe). He is also the creator and maintainer of the RapidDisk Project. Petros has worked in the data storage industry for more than a decade.