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 Deepin 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.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

19 Comments

Leave a Reply
  1. Network Boot (PXE) missing, from my new installation, Ubuntu 20.04, 20.10. Did I miss anything? Thanks and very much appreciate it.

    Reply
  2. 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.

    simple feedback – you meant the latter “kvm_intel” to say “kvm_amd“.

    Reply
  3. I got this error while trying to follow this guide so I had to stop until I resolve this issue and move on to following the rest of the guide. this is for Ubuntu 20.10.

    jd@jd-MacBookPro:~$ sudo apt install -y qemu qemu-kvm libvert-daemon libvirt-clients bridge-utils
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package libvert-daemon

    jd@jd-MacBookPro:~$ sudo systemctl status libvirtd
    Unit libvirtd.service could not be found.

    jd@jd-MacBookPro:~$ sudo systemctl enable –now libvirtd
    Failed to enable unit: Unit file libvirtd.service does not exist.

    any suggestions to get through this ?

    Reply
  4. There is minor correction required (very minor). In the “Create a Virtual Machine via virt-manager” section the highlighted portion shows command as virt manager ( actually it should be virt-manager, “-” is missed”

    Reply
  5. what is the safe way to shut down? I’ve installed MX-Linux several times, every time I wish to leave I go to the shut down from the virt interface checked to boot on host startup. I get message shut down failed.

    Thanks for the help

    scott

    Reply
  6. 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
  7. 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
  8. 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...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.