Playing around with KVM on Root Servers
- February 7th, 2010
- Posted in Ubuntu
- By shermann
- Write comment
Right now I’m preparing some tests regarding virtualization without VMWare.
Yesterday I tested LXC (aka Linux Containers) on my local desktop, because this machine is too old to have some AMD/Intel virtualization extensions. Anyways, that worked somehow, but using KVM was the goal.
So, looking at my root server (hosted by Hetzner), checking if this machine is able to carry some KVM machines on it.
It does, so I started to grab some documentations from the Ubuntu Documentation about KVM.
Most of the things are straight forward, but what is not as simple as it should, is to bring up the network to play nicely with the Hetzner system.
When you booked a server in 2008 or before that, you got one static IP address from Hetzner. Regarding the contract, you are able to get more then one IP for your root server, you get a 8IP subnet, where 6 IPs can be used.
So, what I can’t use is a bridged interface directly connected with the main ethernet device (eth0).
Therefore I need a virtual tunnel device (tap device from UML).
So what to do:
- Get your additional ip subnetwork (for this to work, check your Hetzner Robot Login for this)
- sudo apt-get install bridge-utils uml-utilities
- add a tap device to your /etc/network/interface
- add a bridge device to your /etc/network/interface
So point 1. and 2. are straight forward. Adding a tap device to your /etc/network/interface is mostly simple:
/etc/network/interfaces:
auto tap0 iface tap0 inet manual up ifconfig $IFACE 0.0.0.0 up down ifconfig $IFACE down tunctl_user <your user who runs the virtual machines>
Adding the bridge interface is also not complicated:
/etc/network/interfaces:
auto br0 iface br0 inet static address <one address out of the additional ip network, I use the last usable address> netmask <netmask of the additional ip network> bridge_ports tap0
Now, the address is one of your additional ip addresses you got from Hetzner. I used my last usable address. This IP Address on this bridge interface will be your default gateway inside your KVM machines.
The “bridge_ports tap0″ is important, because if you enter here e.g. your main ethernet device (e.g. eth0) it will give you a non accesible system anymore (you need to rescue it, via Hetzner Robot system -> Rescue system and Reboot System).
What does it do: the tap0 device is a tunnel to your eth0 device. And br0 will bridge all IP traffic from your KVM machines to via this bridge to tap0. The tap0 device then uses your default interface to leave your host and vice versa. (to make this understandable for the non technical audience, the reality what is happening under the hood is more complicated)
After that you can use vmbuilder to create your KVM image, according to the Howto on https://help.ubuntu.com/community/KVM. Just give the KVM machine an IP address from the additional IP subnet (not the one you used for the Host Bridge (br0)) and set the default gateway (–gw) to the IP address of your host bridge (br0).

There’s also some documentation for Hetzner on their wiki
which I used a while ago…
http://wiki.hetzner.de/index.php/KVM
Yeah,
but it lacks the “essential” regarding special distributions.
The “persistence” of the configuration was more a problem.
Ah well, and I don’t know which is the original article, the one on the Hetzner Wiki or this one here: http://www.mhampicke.de/wiki/index.php?title=Server:Allgemein:Hetzner_KVM_Setup
I would say the latter, when I read the version history ;)