Virtualization on the command line with KVM

Slashdot it! Delicious Share on Facebook Tweet! Digg!
© Michael Rolands -

© Michael Rolands -

Quick Start

KVM, with its small yet great set of command-line tools, lets you quickly start virtual machines without having to click through cumbersome menus.

Virtual machines are just practical. You can use virtual computers to test new distributions, start Windows or revive older operating systems. One of the most popular open source virtualization software tools goes by the somewhat unwieldy name "Kernel-based Virtual Machine" (KVM [1] for short). Although primarily driven by Red Hat, it's the preferred virtualization solution in almost all major distributions.

Division of Labor

KVM consists of several components (Figure 1). The base is the kernel module that ensures that the virtual machine can access the actual hardware efficiently without getting in the way. This kind of a manager is called a hypervisor [2] or virtual machine manager (VMM). As of version 2.6.20, the KVM module is a standard component of the Linux kernel, which makes it a part of every current distribution.

Figure 1: The KVM module provides the necessary infrastructure for virtual machines.

In the "old days," the module services loaded virtualization software and most distributions used QEMU [3]. The program is considerably older then KVM and would build a complete PC, inclusive of processors. Nowadays, QEMU can use the KVM module and, thus, the physical PC's vital hardware components. The result is a considerably faster execution of the operating systems and programs that QEMU launches.

Some current distributions separate QEMU and its helper programs into multiple packages. OpenSUSE users need only the kvm package; but for Ubuntu 13.04 you need the qemu (or qemu-system ) package from Software Center. If in doubt, search for the kvm package for your distribution in the package manager.


The installation itself is easy as pie. All you need is to integrate the KVM package through package manager. However, you can start a virtual machine easily if you simply meet a couple requirements on the actual computer.

First, the processor must be an Intel or AMD model that supports virtualization with special command extensions. Intel calls this technology VT; AMD calls it AMD-V. Most desktop and notebook processors in the past five years support this technology. An exception is a particularly underperforming processor, such as some from the Atom series. Intel provides its own list [4] of compatible architectures.

To test whether your PC supports virtualization, use the lsmod | grep kvm command, which should output two lines, one beginning with kvm and another with kvm_intel or kvm_amd , depending on your setup. If these two lines don't show up, you can try starting the module manually with the following two commands for Intel processors:

$ sudo modprobe kvm
$ sudo modprobe kvm_intel

You may also first need to activate the functions in the computer's BIOS or the firmware. If the CPU lacks the hardware virtualization functionality, you can still start the virtual machine, but the guest system it runs will crawl along at a snail's pace.

Next, you need as much main memory as possible, because now it needs to accommodate not only the host operating system but also the virtual machine. The absolute minimum is 2GB. However, the more RAM you have, the more virtual machines of memory-hungry operating systems you can start. Pay particular attention to the requirements of the host operating system. If you want to run 64-bit programs later in the virtual machine, the host Linux needs to be 64-bit. You can run 32-bit programs on a 64-bit host, but not the other way round.

Finally, test that QEMU is correctly installed by using the qemu -version command. If you get an error message in place of a version number, try qemu-kvm -version instead. Some distributions, openSUSE among them, call the associated QEMU qemu-kvm , in which case substitute qemu with qemu-kvm .

Buy this article as PDF

Express-Checkout as PDF

Pages: 5

Price $0.99
(incl. VAT)

Buy Ubuntu User

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content