How to Create a Virtual Machine with KVM on Ubuntu 20.04

How to Create a Virtual Machine with KVM on Ubuntu 20.04

Kernel-based Virtual Machine (KVM) is a module build directly into the Linux kernel that allows the operating system to act as a hypervisor (software to create virtual machines).

1. Check virtualization support

Before installing KVM on Ubuntu, we need to check first whether the hardware used supports KVM. The minimum requirement for a KVM installation is the availability of a CPU virtualization extension such as Intel-VT or AMD-V.

Check if the CPU supports virtualization:

If the result is not 0 it means the hardware supports virtualization. But if not, the hardware doesn’t support virtualization or the feature hasn’t been enabled in the BIOS.

Install cpu-checker:

Run kvm-ok to check if it supports KVM:

The results show that the hardware supports KVM.

2. Install KVM

Install KVM, virt-manager, bridge-utils, and other dependencies:

Installed package functions:

  • qemu (quick emulator): application that perform hardware virtualization.
  • qemu-kvm: the main package of KVM.
  • libvirt-daemon: virtualization daemon.
  • bridge-utils: create a bridge connection for the network.
  • virt-manager: application for virtual machine management with a graphical interface.

To be able to set up a virtual machine without root access, put the user in the libvirt and libvirt-qemu group.

Qemu configuration:

Change the values of user and group to be the user you are using:

Restart Ubuntu:

Check if the virtualization daemon is running:

Check if the KVM module is loaded:

3. Create a Virtual Machine

Run Virtual Machine Manager, then click File-> New Virtual Machine menu.

Select Local install media (ISO image or CDROM) for OS installation from ISO or CDROM.

Then Forward.

Create a new virtual machine
Create a new virtual machine

Click Browse … to select the ISO image.

Choose installation media
Choose installation media

The Choose Storage Volume window will open. Click the + button to create Create storage pool.

Enter Name for the storage pool name, Type for dir: Filesystem Directory, and Target Path for the folder location ISO file storage.

Then Finish.

Create storage pool
Create storage pool

Select the ISO image you want to use.

Then click Choose Volume.

Choose volume
Choose volume

Then Forward.

The question appears as in the image below, answer Yes, and check Don’t ask about these directories again.

Search permissions
Search permissions

Enter the amount of memory and CPU you want to use.

Memory & CPU settings
Memory & CPU settings

To create storage for the virtual machine, check Enable storage for this virtual machine.

Click Create a disk image for the virtual machine and enter the storage space. Image files are stored in Default Storage Pool, in the /var/lib/libvirt/images folder.

Or click Select or create custom storage, then click Manage … to create a new storage pool and custom storage.

Storage
Storage

After creating a Storage Pool for storage, create a new volume.

Then click Volumes +.

Choose storage volume
Choose storage volume

Enter Name, and Max Capacity.

Then Finish.

Create storage volume
Create storage volume

Then Choose Volume.

Then Forward.

Then Finish.

Ready to begin the installation
Ready to begin the installation

If successful, the virtual machine starts immediately.

Virtual machine running
Virtual machine running

Click the button i. Show virtual hardware details, to display and manage the hardware of the virtual machine.

By default, the virtual network used is NAT, the virtual machine can connect to the internet, and can also connect to Host OS.

Virtual machine hardware
Virtual machine hardware

If you found this article helpful and would like to support my work, consider making a donation through PayPal. Your support helps me continue creating useful content and tutorials. Thank you!

Donate via PayPal: https://paypal.me/musaamin

Leave a Reply

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