Setting Up KVM Virtualization

KVM virtualization is included in the 2.6 Linux kernel, so all recent distributions support it without the need to install a custom kernel. However, it depends on the CPU supporting either the Intel VT or AMD-V virtualization extensions in order to run virtual systems at a reasonable speed.

On some systems, these extensions are disabled in the BIOS by default. Enabling them requires booting the system from the console, entering the BIOS menu and finding the option to turn on virtualization extensions. In some cases the system must then be fully shut down and started up again for this change to take effect.

Also, the host system should have LVM setup and have plenty of free space in its volume group, so that Cloudmin can create VM disk images as logical volumes.

For KVM instances to access the host system's network, you must setup a network bridge. These instructions assume that your host system has only one network interface, and it is eth0 .

Setting up a Host System Running Webmin

If your host system is running Webmin 1.554 or later, the network bridge can be created using the Webmin UI as follows :

  1. Go to Networking -> Network Configuration -> Network Interfaces, and select the ** Activated at Boot** tab.
  2. Click on eth0 and change the IPv4 address to No address configured. Remember the current IP address and netmask, as they will be needed in the next step. Click the Save button.
  3. Click Add a new bridge, and fill in the IP address and netmask that used to be assigned to eth0.
  4. In the Connect bridge to interface field select eth0, then click Create.
  5. Return to the main page of the Network Configuration module, and click on Routing and Gateways . Find the current default IPv4 gateway from the Active configuration tab, and enter it on the Boot time configuration tab with br0 selected as the interface.
  6. Go back to the main page of the Network Configuration module, and click the Apply Configuration button.

Setting up a Fedora, CentOS or Redhat Host System

To setup a Redhat-based system to host KVM instances, the steps to follow are :

  1. SSH in as root and install the KVM packages with the command yum install kvm qemu qemu-img parted
  2. In the /etc/sysconfig/network-scripts directory, copy ifcfg-eth0 to ifcfg-br0.
  3. Edit the new file and change the DEVICE line to DEVICE=br0.
  4. In the same file, remove the HWADDR line, and change the TYPE line to TYPE=Bridge
  5. Edit the ifcfg-eth0 file, and at the bottom add the line BRIDGE=br0
  6. Apply the network settings with the command service network restart . This should be done at the console, as it will break network access to the host system if anything goes wrong.
  7. To enable cgroups support for CPU limits, run
    yum install libcgroup
    /etc/init.d/cgconfig start
    chkconfig cgconfig on
  8. If you want to prevent IP spoofing, install EBtables with the command yum install ebtables

Note that the eth0 device will no longer have an IP address; the br0 device has the IP after bridging is operational.

Setting up a Debian or Ubuntu Host System

  1. SSH in as root and install the KVM packages with the command apt-get install kvm qemu parted
  2. Edit the /etc/network/interfaces file and change it to be like :
    auto eth0 lo br0
     
    iface lo inet loopback
     
    iface eth0 inet manual
     
    iface br0 inet static
       address 192.168.1.1
       netmask 255.255.255.0
       broadcast 192.168.1.255
       network 192.168.1.0
       gateway 192.168.1.10
       bridge_ports eth0
       bridge_fd 9
       bridge_hello 2
       bridge_maxage 12
       bridge_stp off
  3. Apply the network settings with the command /etc/init.d/networking restart or by rebooting . This should be done at the console, as it will break network access to the host system if anything goes wrong.
  4. To enable cgroups support for CPU limits, run
    apt-get install cgroup-bin
    /etc/init.d/cgconfig start
    update-rc.d cgconfig defaults
  5. If you want to prevent IP spoofing, install EBtables with the command apt-get install ebtables

Adding a New Host System

  1. Install Webmin on the host system, if it isn't already.
  2. Create a directory for storing KVM instance image files, typically /kvm . This can be located anywhere on the system though.
  3. Add the host system to Cloudmin at Add System -> Add physical system, if it isn't already.
  4. Go to Host Systems -> KVM Host Systems, click the Register a system for KVM hosting link and select your new host machine.
  5. Enter the directory you want to use for storing KVM instances, an IP range to allocate to virtual systems, and a DNS domain to add new systems to.
  6. Click the Register button.