Ubuntu 12.04 KVM Virtualization

Here a quick quide on how to install KVM, libvirt and virtual machines. This has been tested with Hetzner, Softlayer and OVH and should work with all major dedicated server providers.

You will need extra IP addresses for the virtual machines, so make sure to order an extra subnet for your server.

1. Install the needed packages

apt-get install qemu-kvm libvirt-bin

2. Enable ip_forward by adding the following line to /etc/sysctl.conf

net.ipv4.ip_forward=1

Activate the change by running

sysctl -p

3. Configure libvirt for your additional subnet

Enter virsh by typing virsh in the command line. To make changes to the default network with the net-edit command, you first have to destroy the network and then start it again, otherwise net-edit won’t save the changes.

virsh # net-destroy default Network default destroyed

virsh # net-edit default Network default XML configuration edited.

Change the configuration so that it looks similar to the one below. The value for ip address is the network address of your subnet. If for example you have been provided with an additional subnet 192.0.32.8/29 the network address is 192.0.32.8.

default 1088e3f8-3b59-11e0-bcfb-001372333e54

Start the network again.

virsh # net-start default

4. You can now install your virtual machines. The easiest way to install a virtual machine is from an iso image with the Virtual Machine Manager. The iso image should be placed into /var/lib/libvirt/images/.

cd /var/lib/libvirt/images/ wget http://releases.ubuntu.com/precise/ubuntu-12.04-server-amd64.iso

Then start virt-manager on your computer, connect to the server and install the virtual machines.

After installing the VM you will need to update its network configuration so it can connect to the internet. Make sure to set the gateway to your servers main ip address, to add a line pointopoint with the same ip address and to set the netmask to 255.255.255.255. Here an example of /etc/network/interfaces:

The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 192.0.32.9 netmask 255.255.255.255 network 192.0.32.9 broadcast 192.0.32.9 gateway 174.0.14.1 pointopoint 174.0.14.1

If you have troubles with DNS also check if /etc/resolv.conf exists and if it contains a valid nameserver.

Ubuntu 12.04 KVM Virtualization
Share this