Simple Virtualization With Ubuntu 16.04 Linux and KVM

Sure, VirtualBox is a popular solution for quick and easy virtualization on Linux, but KVM can provide a more robust and efficient solution with minimal configuration. With the use of tools like Virt-Manager, it can be just as easy to use.

Ubuntu 16.04 running in a virtual machine

Configure Ubuntu To Host

Graphical Bridged Networking

Before setting Ubuntu to host virtual machines, it’s a good idea to set up bridged networking. Using bridged networking instead of KVM’s built-in virtualized networking interface allows virtual machines to exist on the local network along with physical machines. The easiest way to do this is by using Network Manager.

To begin, right click on the Network Manager applet in the menu bar or open it from the programs menu.
Either way, the goal is to get to the listing of network connections. Once there, click Add. You will be presented with a menu in which you can select the connection type. Select Bridge under the Virtual section and click Code.

You will then see a configuration window for the new bridge. You can configure it however you like, including the name, but ensure that Automatically connect... and All users... are checked under the General tab.

Under the IPv4 tab, there are settings for configuring the network interface. If you want simplicity, make sure that Method: is set to DHCP. If you want a static IP address, feel free to configure it.

Back at the Bridge tab, click Add to link the bridge to a network device. Again, you will get a window asking you to select the type of connection. Ethernet is probably the one you’re looking for, unless you need some sort of special configuration.

After clicking, Create, you will see another configuration window. Under Device select the network interface that you want to bridge. Like the bridge configuration, make sure that Automatically connect... and All users... are checked under the General tab. When that’s done, click save. Safe the bridge as well.

Back on the Network Connections window, delete the existing connection that was added to the bridge.

At this point, Network Manager should pick up the changes and apply them. If not, try restarting it with Systemd.

$ sudo systemctl restart networking

If all else fails, restart the computer.

Manual Bridged Networking

The first step to getting a network bridge working manually on Ubuntu is to install the bridge utils package.

$ sudo apt-get install bridge-utils

The bridge-utils package provides utilities for creating and managing network bridges. The main one needed here the brctl utility.

$ sudo brctl addbr br0
$ sudo ip addr show
$ sudo brctl addif br0 eth0

The commands above use set up the basics for the bridge. First, brctl adds the bridged interface br0. The second command looks up the IP addresses of the interfaces currently in use. Pick the one your system is actually using. In this guide, it will be referred to as eth0. The last line establishes the bridge between br0 and eth0.

Now that that is set up, it’s time to add the bridge details to the network interface configuration. To do so, open up the configuration as root, like in the command below.

$ sudo vim /etc/network/interfaces

In order to use the bridge, make sure that your configuration looks similar to the one below, substituting eth0 for the name of your interface.

# Establishing which interfaces to load at boot and establish the loopback
auto lo br0
iface lo inet loopback

# Set the existing interface to manual to keep it from interfering with the bridge via DHCP
iface eth0 inet manual

# Create the bridge and set it to DHCP.  Link it to the existing interface.
iface br0 inet dhcp
bridge_ports eth0

When the changed are completed, save the configuration and exit the text editor. Everything should be set for the bridge to work. Nothing else will change in terms of normal use. There will only be bridged interface available for the applications that use it. In order for the bridge to take effect, restart networking with Systemd.

$ sudo systemctl stop network-manager
$ sudo systemctl disable network-manager
$ sudo systemctl restart networking

Set Up KVM and Virt-Manager

A couple more packages are needed to get KVM and Virt-Manager running, so install those now.

$ sudo apt-get install qemu-kvm libvirt-bin virt-manager

Once the packages are done installing, it’s a good idea to add a user to the libvirtd group, so that they can manage the VM. If not, it can be done as root, but that’s probably not the best idea.

$ sudo adduser username libvirt
$ sudo adduser username libvirt-qemu

After the user has been added to the libvirtd group, they must log out and back in in order for the new group permissions to take effect.


After logging back in as that user, you can open up Virt-Manager and begin setting up virtual machines. It’s usually under the System with the full name Virtual Machine Manager. On opening the program, you’ll see a window like the one below. To create a new virtual machine, click the icon with the monitor and the flash of light.

Virt-Manager creation screen on Ubuntu

Next, select the first option to install from an ISO. Of course, if you want to use one of the other options, you can, but the ISO is probably the easiest for setting up quickly with a clean install. The following screen, seen below, will prompt you to select either an ISO image or a physical CD or DVD. Which is entirely up to you. It will also try to automatically detect the operating system on the medium. You can manually correct it if it’s wrong.

Virt-Manager .iso select screen

The next screen will allow you to select the amount of RAM and the number of CPU cores that you want available to the new VM. The amounts are entirely up to you, but make sure to select enough for the applications you plan to run on it.

Virt-Manager CPU and RAM selection screen

The following screen is similar to the one preceding it, but concerns the hard drive space. Again, ensure that you allow enough space.

Virt-Manager hard drive creation screen

The last screen will allow you to double-check the settings that you entered and name the VM. It will also have a drop down that will allow you to select the network interface. By default, it should have selected the bridge that you configured earlier. If not, select it from the menu. When you’re sure everything is the way you want it, click finish.

Virt-Manager finalization screen

That’s it. Your new virtual machine will start up as though it were booting into the install ISO that you selected. Just run through the install process and reboot when prompted at the end. The virtual machine will reboot, and you will have a working install on the new VM. The Virt-Manager GUI provides the interface that you need to start, stop, and view your virtual machine as well as managing creation and deletion of other VMs. Enjoy using the full power of KVM just as easily as you would VirtualBox.