KVM is a free and open source virtualization tool for Linux like operating systems. When we install KVM on a Ubuntu Server then it becomes Type-2 KVM hypervisor. Minimum requirement for KVM is that server should have CPU virtualization extensions like Intel-VT and AMD-V. KVM is also known as Kernel based virtual machine because during KVM installation a kernel module (kvm-intel.ko / kvm-amd.ko) is loaded into the kernel.
In this article, we will demonstrate how to install and configure KVM hypervisor on Ubuntu 20.04 LTS server. We are assuming you already have freshly installed Ubuntu 20.04 LTS Server. Let’s deep dive into the KVM installation steps:
Step 1) Confirm Whether Server Support Hardware Virtualization
Login to your Ubuntu 20.04 LTS server and run following grep command,
[email protected]:~$ grep -E -c "vmx|svm" /proc/cpuinfo 2 [email protected]:~$
Above output confirms that server supports hardware virtualization. If the output is not greater than zero then reboot your server, go to its bios settings and enable VT technology.
If you wish to verify whether your server is capable of running KVM virtual machines then install “kvm-ok” utility using below apt command,
[email protected]:~$ sudo apt install -y cpu-checker
Once the “cpu-checker” package is installed, run “kvm-ok” command and verify its output
[email protected]:~$ kvm-ok INFO: /dev/kvm exists KVM acceleration can be used [email protected]:~$
Above output confirms that KVM based virtual machines can be installed on our server.
Step 2) Install KVM, virt-manager and bridge-utils
Run the beneath apt command to install KVM, bridge-utils, virt-manager and other kvm dependencies.
[email protected]:~$ sudo apt install -y qemu qemu-kvm libvirt-daemon bridge-utils virt-manager virtinst
Once all the packages have been installed successfully, verify whether KVM module is loaded into loaded or not using lsmod command,
[email protected]:~$ lsmod | grep -i kvm kvm_intel 286720 0 kvm 663552 1 kvm_intel [email protected]:~$
Step 3) Start and verify libvirtd service
When we install KVM then libvirtd service get started automatically, run below command to verify its status,
[email protected]:~$ sudo systemctl status libvirtd.service
Output above command would look like below,
In case libvirtd service is not started by any reason then run following command to start and enable it
[email protected]:~$ sudo systemctl enable libvirtd --now
Step 4) Setup Network Bridge for KVM Virtual Machines
In this step, we will configure a network bridge for KVM VMs so that VMs can be accessed from outside. Though a virtual bridge “virbr0” is created automatically when we install KVM, but this is only used for testing purpose.
To create a network bridge, we need edit the file “/etc/netplan/00-installer-config.yaml” Following is the content of my server’s file before making the changes.
[email protected]04:~$ cat /etc/netplan/00-installer-config.yaml
Add network bridge entries, remove IP from enp0s3 interface and assign the same IP to the network bridge(br0). After making the changes, content of the file would look like below:
[email protected]:~$ sudo vi /etc/netplan/00-installer-config.yaml # This is the network config written by 'subiquity' network: ethernets: enp0s3: dhcp4: no dhcp6: no version: 2 bridges: br0: interfaces: [enp0s3] addresses: [172.20.10.9/28] gateway4: 172.20.10.1 nameservers: addresses: [22.214.171.124, 126.96.36.199]
Run “netplan apply” command to activate the bride br0 and to make above changes into the effect.
[email protected]:~$ sudo netplan apply [email protected]:~$
Run below commands to …