Network & Systems Architect

Welcome to my little blog. I am mostly techie over here, blogging about networking and system administration topics, but there will also be some Travel Reports from time to time…

How to Setup KVM on Ubuntu Lucid

March 19, 2010Christian Kildau9 Comments

More than a year ago I wrote an article about Xen on Ubuntu Intrepid with the intention of blaming Ubuntu. I also clearly said, that I wouldn’t use Ubuntu anymore. This article turned out to be the most hit one on my blog. Maybe because the Ubuntu community directly links to it. Then, last Summer I wrote an article about alternatives to Xen, but I decided to wait and stay with Xen on my homeserver in the meantime. (Please keep in mind, all I use this for is for my private setups!). Last week I upgraded my Server’s hardware and also wanted to re-install it.

Xen still hasn’t made it into vanilla Kernel, it might make it into 2.6.34 or .35, but even if it does, I think it’s not even going to be close to being production ready. Plus most distributions release their next version in the next weeks/months and are already frozen, so they definitely will not ship with Xen. Well, the only real alternative is KVM. I didn’t like the idea of using KVM for a long time, but since almost every distribution now features KVM as their virtualization technique, I went with it. I also went with Ubuntu again (yeah blame me!). Why? Because their next release has long-term support, and I won’t have the time to upgrade it in the next 12-18 months. And what shall I say… I like it. Installation was kinda tricky on a software Raid0, but I was installing a development release, 1 week before the first Beta… and in the end it did work.

The server runs KVM now and it runs fast and stable. I have 4 virtual machines on it now. Installation of the guests using virt-installer and/or ubuntu-vm-builder was much easier and ended up with working VMs out of the box, whereas xen-create-image ended up with an unusable image on Intrepid, because the default console never showed up without tweaks. libvirt is also nice if you need it, but I really want to point out, that you can run KVM without libvirt just with the ‘kvm’ command!

I tagged this article ‘How-To’, but there are already many good KVM guides out there so I won’t write yet another one. I’ll just post a few hints to get KVM running with a bridged networking using libvirt.

First of all I removed /etc/libvirt/qemu/networks/default.xml to disable the dnsmasq features of libvirt. Then I created an LVM volume group where I wanted to place my machines at, but you can also use simple images on your filesystem. The next thing I did was setting up a bridge in /etc/network/interfaces:

auto br1
iface br1 inet dhcp
        bridge_ports eth1
        bridge_stp off
        bridge_fd 0
        bridge_maxwait 0

You can now simply create your virtual machine with this command:

virt-install -n $hostname -r 512 -c /home/shared/apps/os/ubuntu/lucid-server-amd64.iso --disk path=/dev/virtdisks/bender --network bridge=br1 --vnc --vnclisten= --noautoconsole --os-type linux --os-variant ubuntuLucid --accelerate

Now connect to your host using VNC and install as usual. Another way is to use ‘ubuntu-vm-builder’, but I simply didn’t try… Make sure you limit VNC access to localhost in /etc/libvirt/qemu/$hostname.xml after installation if your network is unsecure.

To make your domain autostart on boot use:

virsh autostart $hostname

This will copy the appropriate xml configuration file to /etc/libvirt/qemu/autostart/.

It’s as simple as that. Way easier than patching a kernel for Xen and all these things. I would have really loved to see Xen in vanilla Kernel a year ago or so, but it didn’t happen and KVM works well enough for me by now… plus you have the benefit of a working power-management.

Take care.

This article has 9 comments
  1. Weboide

    That is a very interesting post, really. Just the only thing, I was looking for more details on the actual commands to build a guest.
    But glad you like KVM ; )

    • Chris

      Well, actually I found the available docs, manpages and other blog posts good enough, that I didn’t want to create a simple duplicate.

  2. G. P. Hinriks

    I would like to give kudos for this short but direct how to. Made my day which has been filled with endless tutorials and bad walkthroughs regarding Xen Hypervisor and Kernel Boot. I’m using Ubuntu 10.04 and I’m currently installing win7 on a virtual machine. Thanks! and have a good one!

  3. Neil

    I’m sure KVM is great but unless you have a new CPU with Virtualisaion support (i.e. if your running old hardware/server) It wont work!

    Correct me if i’m wrong?

    • Chris

      No, you’re right. BUT every CPU less than 5 years old should have virtualization support built in!

      • Tatyana

        TBH, I’m not too upset to see the back of Xen in RHEL.Whilst it works most of the time, I’ve seen far too many bugs over time, particularly on the i386 plfroatm vs the x86_64 plfroatm.KVM is far nicer and most robust from what I’ve seen so far and hardware with virtualisation capabilities is becoming more and more common.

Leave a Reply

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.