How To Install And Set Up KVM On Ubuntu 18.04 LTS / Ubuntu 17.10

0

KVM is a hypervisor software which helps you run a multiple guest operating systems on a Linux machine with the help of hardware virtualization extensions.

KVM supports the wide variety of guest operating system’s such as Linux, Windows, Solaris, Haiku, REACT OS and much more. You can manage virtual machines using the command line or available graphical tools.

Virt-Manager (Virtual Machine Manager) is the most widely used graphical application for managing KVM based virtual machines, and it supports creating, editing, starting and stopping KVM-based virtual machines, as well as the live or cold migration of guest machines between hosts.

Prerequisites

KVM Support

As said earlier, KVM will work only if the CPU has the support of hardware virtualization, either Intel VT or AMD-V.

To find whether your CPU supports VT features, run the following command.

egrep '(vmx|svm)' /proc/cpuinfo | wc -l

Output:

4

If the above command returns nonzero, then your hardware supports VT else it does not.

Bridged Networking

A bridged network is a dedicated network card to a virtual machine which helps guest machines to connect outside the network, and this must be set up before creating a virtual machine using Virtual Manager.

You can either use /etc/network/interfaces or Netplan to configure bridged networking for KVM.

Here, we will use /etc/network/interfaces file to configure bridged networking so that VMs can be accessed from external machines.

Install bridge-utils package using the apt command.

sudo apt-get install -y bridge-utils resolvconf

Edit interface file to create a bridge br1, this should be executed on KVM host.

sudo nano /etc/network/interfaces

My machine has only one network card (ens33). So, I have created a bridge using the single network card. Make changes to the interfaces file according to your environment.

Static IP:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

#Bridge  Name #
auto br1

# Bridge Information #
iface br1 inet static
bridge_ports ens33
bridge_stp off
bridge_fd 9
# Bride IP #
address 192.168.1.10
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 192.168.1.1
dns-nameservers 8.8.8.8

DHCP IP: (Only if your environment has the DHCP server).

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

#Bridge Name #
auto br1

# Bridge Information #
iface br1 inet dhcp
bridge_ports ens33

Bring up the bridge.

sudo ifup br1

OR

Restart the network service.

sudo service networking restart

Install KVM

Update the repository cache.

apt-get update

Install the below packages for KVM set up.

sudo apt-get install -y qemu-kvm qemu virt-manager virt-viewer libvirt-bin
  • qemu-kvm = Kernel-based Virtual machine. QEMU uses it for CPU virtualization.
  • qemu = CPU emulator
  • virt-viewer – Graphical console

User Accounts

Ensure users who are creating virtual machines belong to the libvirt group. Use id command to check the user details.

id raj

Output:

uid=1000(raj) gid=1000(raj) groups=1000(raj),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),116(lpadmin),126(sambashare),129(libvirt)

If you are creating new users, then add them to libvirt group.

sudo useradd -m -d /home/vino -s /bin/bash -G libvirt vino

Create Virtual Machine

Once you have installed KVM and other tools, it is all set to start our first virtual machine. Run virt-manager command in the terminal and bring up the Virtual Machine Manager

sudo virt-manager

OR

Activities >> Search for Virtual Machine Manager.

Install And Set Up KVM On Ubuntu 18.04 - Start Virtual Machine Manager
Install And Set Up KVM On Ubuntu 18.04 – Start Virtual Machine Manager

Once it is opened, right-click on localhost(QEMU) and then click on New. The Virtual Machine Manager will start a wizard to create a new virtual machine.

Install And Set Up KVM On Ubuntu 18.04 - Creare New Virtual Machine
Install And Set Up KVM On Ubuntu 18.04 – Creare New Virtual Machine

Step 1: You will be asked to choose how you would like to install the operating system. Here I decided to install it from ISO image or CD-ROM.

Install And Set Up KVM On Ubuntu 18.04 - New VM - Installation Method
Install And Set Up KVM On Ubuntu 18.04 – New VM – Installation Method

Step 2: Browse to the location of ISO image and select the ISO image. The new machine wizard will try to detect operating system based on ISO, if not, manually choose an operating system type and version.

Install And Set Up KVM On Ubuntu 18.04 - New VM - Installation Media
Install And Set Up KVM On Ubuntu 18.04 – New VM – Installation Media

Step 3: Configure CPU and Memory resource for the virtual machine.

Install And Set Up KVM On Ubuntu 18.04 - New VM - CPU & Memory Information
Install And Set Up KVM On Ubuntu 18.04 – New VM – CPU & Memory Information

Step 4: Here, mention the amount of storage you want to assign to a virtual machine.

Install And Set Up KVM On Ubuntu 18.04 - New VM - Storage Information
Install And Set Up KVM On Ubuntu 18.04 – New VM – Storage Information

Step 5: On this page, you will get the summary of all settings. Select the bridged adaptor we created earlier to allow a virtual machine to communicate outside networks. Click on Finish.

Install And Set Up KVM On Ubuntu 18.04 - New VM - Summary
Install And Set Up KVM On Ubuntu 18.04 – New VM – Summary

Step 6: Virtual Machine Manager will start to create a virtual machine depends on our input.  Once VM is created, Virtual Machine Manager will start the console for OS installation.

The following screenshot shows a VM running on Ubuntu 18.04:

Install And Set Up KVM On Ubuntu 18.04 - New VM Running
Install And Set Up KVM On Ubuntu 18.04 – New VM Running

Manage Virtual Machine

With the Virtual Machine Manager, you can perform VM’s life cycle actions such as start, power off, reset, clone, and migration by right-clicking on the selected virtual machine.

Install And Set Up KVM On Ubuntu 18.04 - Virtual Machine Manager
Install And Set Up KVM On Ubuntu 18.04 – Virtual Machine Manager

You can manage a virtual machine by clicking the info icon in the virtual machine console. Here you can add, remove, and modify devices connected to a virtual machine.

Install And Set Up KVM On Ubuntu 18.04 - Managing Virtual Machine
Install And Set Up KVM On Ubuntu 18.04 – Managing Virtual Machine

That’s All.

You might also like