KVM is an open source virtualization technology built into the Linux kernel. It allows you to run multiple isolated client virtual mach...
KVM is an open source virtualization technology built into the Linux kernel. It allows you to run multiple isolated client virtual machines based on Linux or Windows. Each client machine 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 that will be used as development environments for different applications.
1. Prerequisites
To run a client with more than 2GB of RAM, you must have a 64-bit host system.
Before proceeding with the installation, make sure 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 vendor 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
After the installation is complete, check that your system can run the 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 is dependent on your motherboard and processor type. Configure your system BIOS according to your motherboard's documentation.
2. Installing 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 program that provides hardware emulation for KVM hypervisors
- libvirt-daemon-system - configuration file for running the libvirt daemon as a system service
- libvirt-clients - software used to manage the virtualization platform
- bridge-utils - Command line tool for configuring network bridges
- 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 libvirt
Once 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 that remembers the name of the currently logged-in user.
Log out, and log back in so that the user group is refreshed.
3. Network Setup
During the libvirt installation, a bridge device called "virbr0" is created by default. This device uses NAT to connect clients to the outside world.
Run the brctl utility to list the current bridges and the interfaces they connect to.
brctl show
Output:
bridge name bridge id STP enabled interfaces virbr0 8000.52540089db3f yes virbr0-nic
"virbr0" bridge does not have any physical interfaces added to it. The "virbr0-nic" is a virtual device that does not have any traffic passing through it. 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.
4. Creating a Virtual Machine
Now that KVM is installed on your Ubuntu desktop, let's go ahead and create our first virtual machine together. We can do this from the command line or by using the virt-manager application.
Download the ISO image of the operating system you want to install and follow the steps below to create your virtual machine.
- Type "Virtual Machine Manager" in the search bar and click on the icon to launch the application.
- After the application starts, click on "File" -> "New Virtual Machine" from the top menu:
- A new window will be displayed. Select "Local install media" and click on the "Forward" button.
- Provide the path to your ISO image and click the Forward button.
- On the next screen, select the memory and CPU settings for the VM. Click Forward.
- Next, select "Create a disk image for the virtual machine" and choose the disk space size for the virtual machine. Click Forward.
- Enter the name of your virtual machine and click "Finish".
- The virtual machine will start and a new window will open.
From here, you can follow the actions on the screen to complete the installation of the operating system.
Once the OS is installed, you can access it from virt-manager, using ssh or using the Serial Console interface.
5. Summary
We showed you how to install KVM on an Ubuntu 20.04 system, and now you can create Windows or Linux clients.
COMMENTS