In this article, you'll learn how easy it is to create a Linux Kernel-based virtual machine, or KVM, virtualization host. KVM can provide a good foundation for Linux-based virtualization. You'll also learn how to install Windows and Ubuntu as virtualized operating systems in the KVM-virtualized environment.
I use Ubuntu Server in this tip. Other Linux distributions will work; however, the names of configuration files used may be different.
Networking with KVM Virtualization
On a server where virtualization is used, you can have more virtual machines than you have network boards. Therefore, a solution needs to be implemented for the virtual machines to share network boards in your server. To make this possible, you need to create a virtual network bridge. To do this, you need to redefine the contents of the /etc/network/interface file as in the follow example (figure 1). This code is meant to replace all contents that you currently have in this file, but you must modify it to reflect the number of network cards in your server:
Requires Free Membership to View
Figure 1: To provide network access for all virtual machines, you need a network bridge:
auto lo
iface lo inet loopback
auto br0
iface br0 inet static
address 192.168.1.99
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.254
bridge_ports eth0
bridge_fd 0
bridge_hello 2
bridge_maxage 12
bridge_stop off
The /etc/network/interface file makes sure that when you reboot your server or restart your network, a device with the name br0 is created to replace the eth0 device. This device is meant to use the eth0 as its physical backend, as specified by the line bridge ports eth0. After creating the configuration file in this way, use sudo /etc/init.d/networking restart to restart our network. Your network is now ready to handle KVM virtual machines.
Configuring KVM on Ubuntu Server
Perform the following steps to set up your server for virtualization (the procedure described here is supported on Ubuntu Server 8.04 and later):
- Install all software necessary (the KVM and QEMU packages) for KVM virtualization. As root, use the command
apt-get install kvm qemu libvirt-bin. - After installing these software packages, make sure that the kvm kernel module is loaded. Use lsmod to determine if this is the case (
lsmod | grep kvm) and if the module is not loaded, install it usingmodprobe kvm.
Next, you have to do some additional preparation. This preparation involves preparing the libvirt tools which you will use to create virtual machines. First, you need to add the user account you want to use for KVM management purposes to the libvirtd group. You can do this using the sudo adduser And that's it! Your Ubuntu Server is now ready for the installation and operation of guest operating systems. The next section describes how to install Windows as a guest operating system.
Installing Windows as a guest operating system on KVM Is the kvm command complaining about the lack of support for virtualization on your CPU? You probably haven't switched virtualization support on in your system BIOS yet. Restart your machine, enter the system BIOS and make sure that virtualization support is on. Typically, you'll find this in the advanced section of your BIOS configuration and the option that you are looking for has a name like vm, vt or just virtualization.
You now have your virtualized Windows machine. That was easy, wasn't it? Next, we'll have a look at how to install Ubuntu as a guest on top of your Ubuntu Server virtualization host.
Installing Ubuntu Server as a guest operating system on KVM If you are having problems installing Ubuntu or another Linux distribution as a guest operating system, the graphical menu that most boot loaders display nowadays before starting the installation could be the reason. Try a nongraphical installation program such as the Ubuntu netboot mini.iso file instead. This will help you install any Linux distribution without problems.
Summary About the author: Sander van Vugt is an author and independent technical trainer, specializing in Linux since 1994. van Vugt is also a technical consultant for high availability (HA) clustering and performance optimization, as well as an expert on SUSE Linux Enterprise Desktop 10 (SLED 10) administration. This was first published in August 2008
Before installing Windows as your first guest operating system, you should ask yourself exactly what you want to do with the virtual machines. Is your server running in a data center and are you accomplishing all tasks (including installation of the virtual machines) remotely? If so, you can run it without a graphical user interface. But if you want to be able to manage the virtual machine(s) from the physical server itself, it's a good idea to install a GUI on the server. The procedure described below assumes that you do have some graphical interface that can be used to display the Windows installation interface. You can also use an SSH session with graphical support from a workstation to do this.
dd if=/dev/zero of=/var/lib/virt/windows.img bs=1M count=8192
kvm -m 512 -cdrom /dev/cdrom -boot d windows.img
kvm -m 512 -cdrom /dev/cdrom windows.img
After reading the previous section about installing Windows as a guest operating system in KVM, you probably can already guess how to install an instance of virtualized Ubuntu. Fundamentally, there are no differences between installing Windows or Ubuntu: You create a virtual disk and install Ubuntu Server on that. Assuming that the installation CD is in an ISO image with the name ubuntu.iso, you can use the following procedure:
dd if=/dev/zero of=/var/lib/virt/ubuntu.img bs=1M count=4096
kvm -m 256 -cdrom /isos/ubuntu.iso -boot d /var/lib/virt/ubuntu.img
kvm -m 256 ubuntu.img
In this article, you have learned how to set up Ubuntu Server as a KVM host and install some virtual machines in it. This helps you evaluating the next generation virtualization solution that runs purely from a Linux kernel, but allows you to virtualize almost any operating system.
Virtualization Strategies for the CIO

Join the conversationComment
Share
Comments
Results
Contribute to the conversation