How to install Kvm on Ubuntu 20.04

s2 0

KVM
(Kernel-based Virtual Machine) is an open source virtualization technology that is integrated into the Linux kernel. With KVM to run multiple Linux or Windows virtual guest machines. Each guest is completely isolated from the others and has its own operating system and dedicated virtual hardware such as CPU (s), memory, network interfaces and storage.

This guide provides instructions for installing and configuring KVM on the Ubuntu 20.04 desktop. We will also show you how to create virtual machines that can be used as a development environment for various applications.

requirements

To run guests with more than 2 GB of RAM, you need a 64-bit host system.

Before proceeding with the installation, make sure that your Ubuntu host computer supports KVM virtualization. The system should have either an Intel processor with VT-x (vmx) or an AMD processor with AMD-V (svm) technology support.

Do the following grep
Command to check if your processor supports hardware virtualization:

grep -Eoc '(vmx|svm)' /proc/cpuinfo

If the CPU supports hardware virtualization, the command outputs a number greater than zero that corresponds to the number of CPU cores. Otherwise, if the issue is 0 This means that the CPU does not support hardware virtualization.

On some machines, the manufacturers may disable the virtual technology extensions in the BIOS.

To check if VT is enabled in the BIOS, use the kvm-ok Tool that is included in the scope of delivery. Enter the following commands as root or user with sudo privileges to install this cpu-checker Package that the kvm-ok Command:

sudo apt updatesudo apt install cpu-checker

After the installation, check that your system can run hardware accelerated KVM virtual machines:

kvm-ok

If the processor virtualization function is not disabled in the BIOS, the output looks something like this:

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

Otherwise, the command is printed and an error message and, optionally, a short message to activate the extension are output. How you enable AMD-V or VT technology depends on your motherboard and processor type. Consult your motherboard documentation for information on configuring your system BIOS.

Install KVM on Ubuntu 20.04

Run the following command to install KVM and additional virtualization management packages:

sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager
  • qemu-kvm – Software that provides hardware emulation for the KVM hypervisor.
  • libvirt-daemon-system – Configuration files to run the libvirt daemon as a system service.
  • libvirt-clients – Software for managing virtualization platforms.
  • bridge-utils – a set of command line tools for configuring Ethernet bridges.
  • virtinst – a set of command line tools for creating virtual machines.
  • virt-manager – An easy-to-use GUI interface and supportive command line utilities for managing virtual machines through libvirt.

As soon as the packages are installed, the libvirt daemon will start automatically. You can check it out by typing:

sudo systemctl is-active libvirtd
active

In order to be able to create and manage virtual machines, you have to add your user to the groups “libvirt” and “kvm”. To do this, enter:

sudo usermod -aG libvirt $USERsudo usermod -aG kvm $USER

$USER is an environment variable that contains the name of the currently logged on user.

Sign out and sign back in to update group membership.

Network setup

During the installation process a bridge with the name “virbr0” is created. This device uses NAT to connect guests’ computers to the outside world.

You can use the … brctl Tool to list the current bridges and the interfaces they are connected to:

brctl show
bridge name	bridge id		      STP enabled	interfaces
virbr0		  8000.52540089db3f	yes		      virbr0-nic

The bridge “virbr0” has no additional physical interfaces. “Virbr0-nic” is a virtual device through which no data traffic is routed. The sole purpose of this device is to avoid changing the MAC address of the “virbr0” bridge.

This network setup is suitable for most Ubuntu desktop users, but it has limitations. If you want to access the guests from outside the local network, you have to create a new bridge
and configure it so that the guest computers can connect to the outside world through the host’s physical interface.

Create virtual machines

Now that KVM is installed on your Ubuntu desktop, it’s time to create the first VM. This can be done either from the command line or with the virt-manager Use.

Download the ISO image of the operating system you want to install and do the following to create your virtual machine:

  1. Enter “Virtual Machine Manager” in the activity search bar and click the icon to launch the application.

  2. After the application has started, click in the top menu on “File” -> “New virtual machine”:

  3. A new window will appear. Select “Local Installation Media” and click the “Forward” button.

  4. Provide your ISO image path and click the Next button.

  5. On the next screen, select the VM’s memory and CPU settings. Click Forward.

  6. Next, select “Create a disk image for the virtual machine” and select the size of the VM’s storage space. Click Forward.

  7. Enter a name for your virtual machine name and click Finish.

  8. The VM will start and a new window will open:

    From here, you can follow the on-screen instructions to complete the operating system installation.

After installing the operating system, you can use the virt-manager Application, via ssh or via the Serial console
Interface.

diploma

We showed you how to install KVM on Ubuntu 20.04 systems. You are now ready to create your Windows or Linux guest computers. For more information on KVM, see the KVM documentation
Page.

If you have any questions please leave a comment below.

Tags: