KVM (Kernel-based Virtual Machine) is an open source virtualization technology built into the Linux kernel. It allows you to run multiple isolated guest virtual machines based on Linux or Windows. Each client has its own operating system and dedicated virtual hardware, such as CPU(s), memory, network interface and storage.
This guide provides instructions on how to install and configure KVM on Ubuntu 20.04. We will also show you how to create virtual machines, which will be used as development environments for different applications.
To run a guest with more than 2GB of RAM, you must have a 64-bit host system.
Before proceeding with the installation, make sure that your Ubuntu host supports KVM virtualization. This system must have an Intel processor that supports VT-x (vmx) or an AMD processor that supports AMD-V (svm) technology.
Enter the following grep
command to see if your blow supports hardware virtualization:
grep -Eoc '(vmx|svm)'/proc/cpuinfo
If your CPU supports hardware virtualization, this command will print a number greater than 0, which represents the number of CPU cores. Otherwise, if the output is 0, it means that this CPU does not support hardware virtualization.
On some machines, virtualization technology may be disabled by the manufacturer in the BIOS.
To check if VT is enabled in the BIOS, use the kvm-ok
tool, which is included in the cpu-checker
package. Run the following command as root or another user with sudo privileges to install this package:
sudo apt update
sudo apt install cpu-checker
Once the installation is complete, check whether your system can run a hardware accelerated KVM virtual machine:
kvm-ok
If the processor virtualization capability is not disabled in the BIOS, the command will print out:
INFO:/dev/kvm exists
KVM acceleration can be used
Otherwise, this command will print a failure message and a short message about how to enable the component. The process of enabling AMD-V or VT technology depends on your motherboard and processor type. Configure your system BIOS according to your motherboard documentation information.
Run the following command to install KVM and additional virtualization management software packages:
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager
qemu-kvm
-A software program that provides hardware simulation for the KVM hypervisor libvirt-daemon-system
-configuration file to run libvirt daemon as a system service libvirt-clients
-software used to manage the virtualization platform bridge-utils
-command line tool to configure network bridge virtinst
-command line tool for creating virtual machines virt-manager
-Provides an easy-to-use graphical interface and supports command-line tools for managing virtual machines through libvirtOnce the package is installed, the libvirt daemon will start automatically. You can verify it by running the following command:
sudo systemctl is-active libvirtd
Output:
active
To create and manage virtual machines, you need to add your users to the "libvirt" and "kvm" user groups. enter:
sudo usermod -aG libvirt $USER
sudo usermod -aG kvm $USER
$USER
is an environment variable used to remember the name of the currently logged in user.
Log out and log in again so that the user group is refreshed.
During the libvirt installation process, a bridge device called "virbr0" is created by default. This device uses NAT to connect the client to the outside world.
Run the brctl
tool to list the current bridges and the interfaces they are connected to:
brctl show
Output:
bridge name bridge id STP enabled interfaces
virbr0 8000.52540089db3f yes virbr0-nic
"Virbr0" bridge does not add any physical interface. "Virbr0-nic" is a virtual device without any traffic passing through. The only purpose of this device is to avoid modifying the MAC address of the "virbr0" bridge.
The network settings are suitable for most Ubuntu desktop users, but there are limitations. If you want to access the client from the outside local network, you need to create a new bridge and configure it so that the client can connect to the outside world through the host's physical interface.
Now that KVM is installed on your Ubuntu desktop, let's create the first virtual machine together. We can use the virt-manager
application from the command line.
Download the ISO image of the operating system you want to install and follow the steps below to create your virtual machine:
Enter "Virtual Machine Manager" in the search bar and click the icon to launch the application.
After the application is launched, click "File" -> "New Virtual Machine" from the top menu:
A new window will be displayed. Select "Local install media" and click the "Forward" button.
Provide your ISO image path, and click the Forward button.
On the next screen, select the memory and CPU settings of the virtual machine VM. Click Forward.
Next, select "Create a disk image for the virtual machine" and select the disk space size of the virtual machine. Click Forward.
Enter your virtual machine name and click "Finish".
The virtual machine starts, and a new window will open:
From here, you can follow the instructions on the screen to complete the operating system installation.
Once the operating system is installed, you can access it from virt-manager
, using ssh or using the Serial Console interface.
We show you how to install KVM on Ubuntu 20.04 system. Now you can create Windows or Linux clients. To find more information about KVM, browse: KVM Documentation Page.
Recommended Posts