Step by step guide for installing KVM on Ubuntu 20.04 and creating a virtual machine using virt-manager
KVM or Kernel-based Virtual Machines are modules in the Linux Kernel that allow users to run Virtual Machines on their systems. It boasts almost bare-metal performance compared to other virtualization software because it is closely related to the Linux kernel.
KVM combined with an API / Toolkit called libvirt is used to create VMs on Ubuntu. Tools such as Virt-Manager (front-end GUI) and Virsh (CLI) are used to simplify VM creation and management.
In this article, we will learn how to install KVM correctly on Ubuntu 20.04 LTS.
Before we begin the installation, we need to ensure that we meet the requirements needed to run the KVM. We need a processor that supports hardware virtualization. If the processor supports hardware virtualization, we must ensure that it is enabled in the BIOS.
To check if your processor supports hardware virtualization, press ctrl + alt + t to open the terminal. We will use a neat command called egrep which uses Regexp to look for text patterns from files. The file that we are looking for information about the CPU is located at / proc / cpuinfo. Paste the following command in the terminal to check hardware virtualization support.
egrep -c '(vmx|svm)' /proc/cpuinfo
If you get an output other than 0, your processor supports hardware virtualization. The output number is no. the core or thread your processor has. The only step left now is to make sure hardware virtualization is enabled in the BIOS.
The process of enabling hardware virtualization now depends on whether you have an Intel or AMD processor. See your motherboard’s manual to find out how to enable virtualization. For Intel Processors, you must enable Virtualization in the BIOS settings. For AMD processors, activate a setting called SVM Mode.
We have now verified that we have a processor that supports hardware virtualization and activated it in the BIOS. Now we can move to Installation.
Open a terminal by pressing ctrl + alt + t keyboard shortcuts. To install KVM paste the following command in the terminal and press enter.
sudo apt-get install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils
Qemu-kvm is a KVM package, while libvirt-daemon-system and libvirt-clients are libvirt toolkit packages. The bridge-utils package is used to configure the Ethernet bridge for the VM.
Verifying the Installation
There are two methods for verifying the success of a KVM installation. Good run
virsh list --all
If you get output as shown above, then KVM is installed correctly on your system. You can now create a VM using the virsh command to create a VM or install a virt-manager GUI tool to create and manage your VM as you wish.
Creating a VM
In this section we will use virt-manager to create and run a VM on Ubuntu 20.04. To install virt-manager on Ubuntu 20.04, run the following command:
sudo apt install virt-manager
After installation is complete, run virt-manager. You will be greeted with the following window.
To create a new VM, you need to click the Create a new virtual machine button.
A pop-up window titled New VM will appear, select the Local installation media (ISO image or CDROM) option and click Continue.
We need an ISO image of the Operating System that our Virtual Machine wants to create. Click browse to select the OS to be installed.
You will be presented with the Choose Storage Volume window, we will now use the default storage set, you can try playing around by creating a new storage set for the virt-manager to use. For now, we will copy the ISO image from the OS to the following directory using the cp command.
sudo cp source_of_iso_file /var/lib/libvirt/images
We need root privileges to copy the ISO to the default set, so we use the sudo command and source_of_iso_file is the OS location you choose. After copying the ISO image directory to libvirt, press the Refresh list volume button. Your ISO OS of choice will appear in the list below, I chose MX-Linux to install.
Select the OS you chose to install and press the Choose Volume button.
After selecting ISO, click Forward in the previous window.
Select the amount of Memory / RAM to be allocated to the VM and the Number of CPU cores in the next window. I recommend allocating at least the minimum number of recommendations required by the OS.
Next, allocate at least the minimum amount of disk space required by the OS. I recommend a minimum of 30 GB for Windows and 20 GB for Linux distributions. Virt-manager will automatically create a Virtual Disk for the OS if the first option is selected.
Tip: You can create your own custom storage with the second option.
You can change the name of the VM on this new screen and confirm the details. Click Finish to begin your OS installation on the virtual disk.
Tip: You can also try changing your VM settings by checking custom configurations before installing options for additional features.
Selesaikan penginstalan OS dengan mengikuti proses penginstalan untuk OS yang dipilih….
After completing the installation, you can start the VM by selecting it and clicking Power on the virtual machine button
Now we have a functional VM that is ready to use.