Adding KVM to an Ubuntu Desktop Machine

Installation of KVM Packages

For the following setup, we will assume that you are deploying KVM on a 64 bit desktop machine that supports hardware virtualization. First, open a terminal and:

sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils

After the installation, you need to logout and then relogin so that you becomes a member of the libvirtd group. The members of this group can run virtual machines.

Testing Your Install

You can test if your install has been successful with the following command:

virsh -c qemu:///system list

At which point you should see something like:

 Id Name                 State

If on the other hand you get something like this:

libvir: Remote error : Permission denied
error: failed to connect to the hypervisor

Something is wrong (perhaps you did not relogin) and you probably want to fix this before you move on. The critical point here is whether or not you have write access to /var/run/libvirt/libvirt-sock. Check those permissions with:

sudo ls -la /var/run/libvirt/libvirt-sock

The sock file should have permissions similar to:

srwxrwx— 1 root libvirtd 0 2011-07-05 21:17 /var/run/libvirt/libvirt-sock

Install virt-manager (graphical user interface)
On a desktop computer you probably want to install a GUI tool to manage virtual machines.

sudo apt-get install virt-manager

To launch KVM/VirtManager:

Applications -> System Tools -> Virtual Machine Manager.

At that point you can begin creating virtual machines, but you might want to enable Bridged networking first.

Enable Bridged Networking

In it’s basic form (what you’ve installed so far) you guest machines will only support NAT networks. That means it will be like you have a router between your virtual machines and your local network. That may be what you want if you want ot isolate your virtual machines, but if you want to share files with other machines on your networks with samba you will need to enable Bridged networking.

To do that, you will need to make changes to the /etc/network/interfaces file on your host machine. So, open a terminal and

sudo cp /etc/network/interfaces /etc/network/interfaces.bak
gksudo gedit /etc/network/interfaces

Assuming your host machine has a fixed ip address, xx.yy.zz.ww; edit the file to create something like this:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
        address xx.yy.zz.ww
        network xx.yy.zz.0
        broadcast xx.yy.0.255
        gateway xx.yy.zz.nn
        bridge_ports eth0
        bridge_stp off
        bridge_fd 0
        bridge_maxwait 0 

Creating Virtual Machines

Launch KVM/VirtManager:

Applications -> System Tools -> Virtual Machine Manager.

Next double-click on “localhost (System)”

Create a new virtual machine by pressing the top left Create a new virtual machine toolbar button.

  1. First, download an ISO cd image of some OS you want to run. For Ubuntu, you can find these at:
  2. Double click on the name of the host. The Status column should read Active
    Right click on the name of the host, and select New
    This will start a wizard to guide you through the rest of your VM creation
    Enter your virtual machine details
  3. Name: yourVirtualMachinename
  4. Choose Local install media (ISO image or CDROM), or you can use another method if you know what you’re doing
  5. Click Forward
  6. Locate your install media
    Use ISO image or DVD
    If you are using an ISO, browse to find the ISO you downloaded earlier and select it.
    Then select the matching OS Type

  7. Click Forward
  8. Choose Memory and CPU settings
    Memory (RAM): 512MB (your choice)
    CPUs: 1 (your choice)
  9. Click Forward
  10. Select Enable storage for this virtual machine
  11. Select Create a disk image on the computer’s hard drive
    8 GB is the default
    To speed up VM creation, you can unselect Allocate entire disk now
  12. Forward
  13. Ready to begin installation
    Confirm the details
  14. Click Finish

You should now see the OS installation proceed within a virt-manager window. Complete the installation and reboot. Note: a Windows XP guest install reboots in the middle. When it does it may fail to find the install DVD/CD, If so go to the view menu on the virtual console, and select Details. Then make sure the DVD drive is still connected.

If your VM is fails to start when you reboot it after the install is finished, and you’re getting an error message like,

error starting domain monitor socket did not show up. connection refused

you can find more info in the log files. The log should be in /var/log/libvirt/qemu/$your-vm-name.log. This will show generated qemu command line, and any error output qemu throws.

One easy way to get this error is to build your virtual machine using a CD/DVD and then eject that CD/DVD without also telling virt-manager to disconnect from your host’s CD/DVD drive.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: