How to Install KVM on Ubuntu 20.04

KVM, (kernel-based Virtual Machine) is a free and opensource virtualization platform for the Linux kernel. When installed on a Linux system, it becomes a Type-2 hypervisor.

In this article, we look at how you can install KVM on Ubuntu 20.04 LTS.

Step 1: Check Virtualization Support in Ubuntu

Before installing KVM on Ubuntu, we are first going to verify if the hardware supports KVM. A minimum requirement for installing KVM is the availability of CPU virtualization extensions such as AMD-V and Intel-VT.

To check whether the Ubuntu system supports virtualization, run the following command.

$ egrep -c '(vmx|svm)' /proc/cpuinfo

An outcome greater than 0 implies that virtualization is supported. From the output below, we have confirmed that our server is good to go.

Check Virtualization Support in Ubuntu
Check Virtualization Support in Ubuntu

To check if your system supports KVM virtualization execute the command:

$ sudo kvm-ok

If the “kvm-ok” utility is not present on your server, install it by running the apt command:

$ sudo apt install cpu-checker

Now execute the “kvm-ok” command to probe your system.

$ sudo kvm-ok
Check KVM Support in Ubuntu
Check KVM Support in Ubuntu

The output clearly indicates that we are on the right path and ready to proceed with the installation of KVM.

Step 2: Install KVM on Ubuntu 20.04 LTS

With the confirmation that our system can support KVM virtualization, we are going to install KVM, To install KVM, virt-manager, bridge-utils and other dependencies, run the command:

$ sudo apt install -y qemu qemu-kvm libvirt-daemon libvirt-clients bridge-utils virt-manager

A little explanation of the above packages.

  • The qemu package (quick emulator) is an application that allows you to perform hardware virtualization.
  • The qemu-kvm package is the main KVM package.
  • The libvritd-daemon is the virtualization daemon.
  • The bridge-utils package helps you create a bridge connection to allow other users to access a virtual machine other than the host system.
  • The virt-manager is an application for managing virtual machines through a graphical user interface.

Before proceeding further, we need to confirm that the virtualization daemon – libvritd-daemon – is running. To do so, execute the command.

$ sudo systemctl status libvirtd
Check libvritd Status
Check libvritd Status

You can enable it to start on boot by running:

$ sudo systemctl enable --now libvirtd

To check if the KVM modules are loaded, run the command:

$ lsmod | grep -i kvm

From the output, you can observe the presence of the kvm_intel module. This is the case for Intel processors. For AMD CPUs, you will get the kvm_intel module instead.

Check KVM Modules in Ubuntu
Check KVM Modules in Ubuntu

Step 3: Creating a Virtual Machine in Ubuntu

With KVM successfully installed, We are now going to create a virtual machine. There are 2 ways to go about this: You can create a virtual machine on the command-line or using the KVM virt-manager graphical interface.

Create a Virtual Machine via Command Line

The virt-install command-line tool is used for creating virtual machines on the terminal. A number of parameters are required when creating a virtual machine.

Here’s the full command I used when creating a virtual machine using a Deeping ISO image:

$ sudo virt-install --name=deepin-vm --os-variant=Debian10 --vcpu=2 --ram=2048 --graphics spice --location=/home/Downloads/deepin-20Beta-desktop-amd64.iso --network bridge:vibr0 

The --name option specifies the name of the virtual machine – deepin-vm The --os-variant flag indicates the OS family or derivate of the VM. Since Deepin20 is a derivative of Debian, I have specified Debian 10 as the variant.

To get additional information about OS variants, run the command

$ osinfo-query os

The --vcpu option indicates the CPU cores in this case 2 cores, the --ram indicates the RAM capacity which is 2048MB. The --location flag point to the absolute path of the ISO image and the --network bridge specifies the adapter to be used by the virtual machine. Immediately after executing the command, the virtual machine will boot up and the installer will be launched ready for the installation of the virtual machine.

Create a Virtual Machine via virt-manager

The virt-manager utility allows users to create virtual machines using a GUI. To start off, head out to the terminal and run the command.

$ virt manager

The virtual machine manager window will pop open as shown.

KVM Virtual Machine Manager
KVM Virtual Machine Manager

Now click the monitor icon to start creating a virtual machine.

Create a Virtual Machine in KVM
Create a Virtual Machine in KVM

On the pop-up window, specify the location of your ISO image. In our case, the ISO image is located in the ‘Downloads’ folder in the home directory, so we’ll select the first option – Local Install Media ( ISO image or CDROM). Next, click the ‘Forward’ button to continue.

Choose Local Install Media
Choose Local Install Media

In the next step, browse to the ISO image on your system and directly below, specify the OS family that your image is based on.

Choose ISO Image
Choose ISO Image

Next, select the memory capacity and the number of CPUs that your virtual machine will be allocated, and click ‘Forward’.

Choose Memory and CPU for VM
Choose Memory and CPU for VM

And finally, in the last step, specify a name for your virtual machine and click on the ‘Finish’ button.

Set Virtual Machine Name
Set Virtual Machine Name

The creation of the virtual machine will take a few minutes upon which the installer of the OS you are installing will pop open.

Creating Virtual Machine
Creating Virtual Machine

At this point, you can proceed with the installation of the virtual machine.

Virtual Machine Installation
Virtual Machine Installation

And that’s how you go about installing KVM hypervisor on Ubuntu 20.04 LTS.

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

6 thoughts on “How to Install KVM on Ubuntu 20.04”

  1. Thanks for this most helpful tutorial. I suppose they must go out of date fairly frequently, as I had previously followed another guide, but was unable to find the libvirt repositories using their method.

    As of 13-September-20202, your method works for me.

    Here are some suggestions to help make things a little smoother for newbies like me:

    1. After the “sudo systemctl status libvirtd” command, please mention that the user should use “q” to get back to the command prompt.
    2. The command to run vert manager, “$ virt manager“, is missing a hyphen, and should be: “$ virt-manager“.

    Thanks again,
    Henry

    Reply
  2. Hi, great guide, another typo when we are checking the kvm module for amd you wrote that we should get kvm_intel and not kvm_amd.

    Reply
  3. Little typo in:

    “To check if the KVM modules are loaded, run the command:”

    $ smod | grep -l kvm
    

    but must be:

    $ smod | grep -i kvm
    

    as shown in the picture below it.

    Reply

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.