KVM On Ubuntu - KVM Logo

Installing and Running KVM on Ubuntu 14.04 Part 3

In part 2 of this series about installing KVM on Ubuntu 14.04 I configured the network. In this part I’ll be installing and configuring KVM.

UPDATE: There’s nothing wrong with the techniques discussed in this article but I now feel that a routed network is simpler to set up and manage so I recommend that set up and have described it here.

Installing and Configuring KVM

Installing KVM is as simple as running this command:

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

That short selection of packages will, however, install everything and the kitchen sink so it’s time to get a cup of tea.

The KVM / libvrit system has all manner of different ways of providing network connectivity to the hosts but the one I prefer is bridging as that allows the hosts to be addressed directly. Modes such as NAT (the default) require the setting up of port forwarding on the host this works but it’s not a clean. In order to use bridging you have to step outside what is offered by KVM / libvirt which is why in part 2 I set up a bridge using iproute2. An alternative is to set up a bridge using Open vSwitch as you would if you were setting up Open Stack.

When KVM is installed it creates a default network with a configuration that looks like this:

<network>
    <name>default</name>
    <uuid>7502c7e0-9b3d-4e0f-8903-6198acdc3acb</uuid>
    <forward mode='nat'/>
    <bridge name='virbr0' stp='on' delay='0'/>
    <mac address='52:54:00:6e:8e:30'/>
    <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
    <range start='192.168.122.2' end='192.168.122.254'/>
    </dhcp>
    </ip>
</network>

I don’t want this network so first start a virsh shell and then execute the following commands (to start a virsh shell just enter the command “virsh”):

net-destroy default
net-undefine default
net-list --all
 Name                 State      Autostart     Persistent
----------------------------------------------------------

The last command simply lists all the networks and confirms that the default network has been removed. Now to install the new network first exit the virsh shell (use the exit or quit command) and then at a command prompt:

nano br0.xml

In the br0.xml file enter the following:

<network>
    <name>br0</name>
    <forward mode='bridge'/>
    <bridge name='br0'/>
</network>

Save and exit and then go back into a vrish shell in order to define the network with the following:

net-define br0.xml
net-autostart br0
net-start br0

Now reboot the host to make sure everything comes up as expected. To check that everything is working as expected run the following commands:

$ virsh net-list --all

 Name                 State      Autostart     Persistent
----------------------------------------------------------
 br0                  active     yes           yes



$ ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
    link/ether 00:18:8b:f7:c5:fc brd ff:ff:ff:ff:ff:ff
    inet6 fe80::218:8bff:fef7:c5fc/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 00:18:8b:f7:c5:fd brd ff:ff:ff:ff:ff:ff
4: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:0e:89:06:d9:0f brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.150/24 brd 192.168.1.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::e:89ff:fe06:d90f/64 scope link
       valid_lft forever preferred_lft forever

What you are looking for is virsh reporting that the bridge is up and active and that the ip command reports that the bridge exists, is up and is correctly configured with eth0 as a slave. In part 4 I’ll be installing the first guest.

Read More