How to install KVM on Ubuntu

KVM (Kernel-based Virtual Machine) is the leading open source virtualisation technology for Linux. It installs natively on all Linux distributions and turns underlying physical servers into hypervisors so that they can host multiple, isolated virtual machines (VMs). KVM comes with no licenses, type-1 hypervisor capabilities and a variety of performance extensions which makes it an ideal candidate for virtualisation and cloud infrastructure implementation.

KVM hypervisor enables full virtualisation capabilities. It provides each VM with all typical services of the physical system, including virtual BIOS (basic input/output system) and virtual hardware, such as processor, memory, storage, network cards, etc. As a result, every VM completely simulates a physical machine.

KVM is available as a Linux kernel module. It plugs directly into the kernel’s code and allows it to function as a hypervisor. Every VM runs as a separate Linux process under systemd, with dedicated virtual hardware resources attached.  KVM can only be used on a processor with hardware virtualisation extensions, such as Intel-VT or AMD-V.

In our example we use Ubuntu 20.04

1. Execute the following command to install the required packages:

$ sudo apt -y install bridge-utils cpu-checker libvirt-clients libvirt-daemon qemu qemu-kvm

2. Execute the following command to make sure your processor supports virtualisation capabilities:

$ kvm-ok

The output of this command is pretty straightforward and clearly indicates whether KVM can be used or not:

INFO: /dev/kvm exists
KVM acceleration can be used

Create a vm using virt-install CLI

Before runing the CLI, please download the right iso file to /var/lib/libvirt/isos/ )

virt-install \
  --name ubuntu1804 \
  --ram 2048 \
  --disk path=/var/lib/libvirt/images/u19.qcow2,size=8 \
  --vcpus 2 \
  --os-type linux \
  --os-variant generic \
  --console pty,target_type=serial \
  --cdrom /var/lib/libvirt/isos/ubuntu-18.04.4-live-server-amd64.iso

Please feel free to update the above values as your needs.

Leave a Reply

Your email address will not be published. Required fields are marked *