Palegray.net - Code, Linux/BSD, Tech, and more
Home Projects Tutorials Forums About Contact

Debian 6 (Squeeze) KVM Virtualization Howto

Install and Configure KVM and on the Server

Log into your freshly installed Debian 6 system as "root" using the password you assigned during the installation process. To make sure your system is compatible with KVM, issue the following command.

egrep '(vmx|svm)' --color=always /proc/cpuinfo

You should see several lines of output. If you don't see any output at all, your CPU doesn't support hardware virtualization, and you must stop here. Assuming it has the necessary support, you may proceed. Issue the following commands to update your system's package repositories, install any outstanding system updates, installed required packages, and add the "root" user to the "libvirt" group.

apt-get update
apt-get dist-upgrade
apt-get install qemu-kvm libvirt-bin bridge-utils screen console-data console-tools debconf
adduser `id -un` libvirt

Next, adjust your system's "swappiness" parameter. Swap space is virtual memory, which Linux uses to page out infrequently used items stored in memory to disk. In many cases, this can help improve a system's overall memory utilization efficiency. However, for the purposes your server will be fulfilling, it's best to reduce the tendency of the system to swap memory out. Issue the following commands to adjust the "swappiness" kernel parameter and make the change persist through reboots.

sysctl vm.swappiness=0
echo "vm.swappiness=0" >> /etc/sysctl.conf

Next, you'll need to statically assign your server's IP address and create a network bridge for virtual machines. The example that follows would be appropriate for a server that resides on a LAN with a network of 192.168.2.0; you will need to adjust it as necessary to match your network. In particular, pay attention to the "address" parameter (assign an unused address in your network's range), and make sure the "network" and "broadcast" parameters are appropriate for your network. Make sure the "gateway" parameter matches the default gateway for your network.

File: /etc/network/interfaces

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet manual

# Network bridge
auto br0
iface br0 inet static
address 192.168.2.10
network 192.168.2.0
netmask 255.255.255.0
broadcast 192.168.2.255
gateway 192.168.2.1
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0	

Once you've made the required changes, issue the following command to restart networking on your system.

/etc/init.d/networking restart

At this stage, you may log into your system's IP address from your workstation with ssh, using the username "root" and the password you selected during installation. Next, edit your /etc/hosts file to resemble the following example, substituting your server's IP address for "192.168.2.10," your system's hostname in place of "socrates," and your system's domain name for "palegray."

File: /etc/hosts

127.0.0.1        localhost.localdomain        localhost
192.168.2.10     socrates.palegray            socrates

Issue the following command to reboot your system before proceeding.

reboot

Once your system comes back up, log back into it as "root" and issue the following command to create SSH keys on the host.

ssh-keygen -t rsa

Issue the following commands to download a Debian 6 ISO image to your KVM server. This will be used later to create your first KVM guest machine.

cd /var/lib/libvirt/images
wget http://cdimage.debian.org/debian-cd/6.0.0/multi-arch/iso-cd/debian-6.0.0-amd64-i386-netinst.iso

Next, you'll set up a Debian 6 desktop system in a virtual machine running on your workstation. This will serve as the management system for the creation of new virtual machines.

Continue: Install VirtualBox on the Management Workstation
Previous: Install Debian 6 (Squeeze) on the Server