How to Install KVM on Ubuntu 24.04

This article explains how to install KVM on Ubuntu 20.04.

KVM (Kernel-based Virtual Machine) is an open-source complete virtualization solution for Linux systems, including Ubuntu. Like VirtualBox and VMware Workstation, KVM is a virtualization infrastructure for the Linux kernel that turns it into a hypervisor.

Since KVM is part of the Linux kernel, it benefits from its features, security, and updates.

If you can’t install VirtualBox or VMware Workstation virtualization solutions on Ubuntu machines, you can try KVM instead. After installing, use the KVM module to install and run multiple virtual machines (guest) on Linux servers.

These virtual machines can be managed via the virt-manager graphical user interface or virt-install & virsh CLI commands.

Check KVM Support on Ubuntu

Not all systems can install and run the KVM modules. If you’re running a server that isn’t compatible, KVM can’t be used on it.

To check, run the commands below to install a CPU checker tool on Ubuntu Linux.

sudo apt install cpu-checker
sudo kvm-ok

After installing the above commands, check the CPU compatibility with KVM. If KVM is compatible, you should get the message that KVM acceleration can be used.

INFO: /dev/kvm exists
KVM acceleration can be used

if KVM isn’t compatible with your system, you’ll get a message that reads

INFO: Your CPU does not support KVM extensions
KVM acceleration can NOT be used

The message above shows you can’t run KVM.

Install KVM Packages

If step 1 is good, run the commands below to install KVM packages to enable full virtualization functionality on Ubuntu via the Linux kernel.

sudo update
sudo apt install qemu-kvm virt-manager libvirt-clients bridge-utils libvirt-daemon-system virtinst

After installing the KVM modules, run the commands below to start and enable it to start automatically when the system boots.

sudo systemctl start libvirtd
sudo systemctl enable libvirtd

Add a User to libvirt and KVM Groups

When you install KVM on Ubuntu, you should also add your user account to the libvirt and KVM groups. Doing this will allow you to create and manage the Virtual machines on your system.

Run the command below to add your account to these groups.

sudo usermod -aG libvirt $USER
sudo usermod -aG kvm $USER

Create New VMs

Now that the server is configured open the KVM virtual machine manager and create a new virtual guest machine.

First, connect to the server, then create a new machine by clicking New Virtual Machine.

KVM desktop dashboard

Then, choose how to install the guest machine. You can use local ISO media or install it via network / PXE.

After selecting the OS file, continue to create a setup of a local disk, system memory, and other settings.

When you’re done, boot the VM to install Ubuntu

That should do it!

Conclusion:

  • KVM provides an efficient and powerful virtualization solution for Ubuntu 20.04 users.
  • It allows creating and managing multiple virtual machines, leveraging the Linux kernel’s capabilities.
  • Users can choose from various installation sources, including local ISOs and network installations.
  • Adding user accounts to the appropriate groups ensures smooth management of virtual machines.
  • With tools like virt-manager, users can easily configure and monitor their virtual environments.
  • KVM is a robust alternative for users unable to utilize VirtualBox or VMware, emphasizing performance and integration with Linux systems.

Frequently Asked Questions

What is KVM and how does it work on Ubuntu?

KVM, or Kernel-based Virtual Machine, is an open-source virtualization solution that turns the Linux kernel into a hypervisor. It allows users to run multiple virtual machines on a Linux system, leveraging the kernel's features for performance and security.

How can I check if my CPU supports KVM?

To check if your CPU supports KVM, install the CPU checker tool using 'sudo apt install cpu-checker' and then run 'sudo kvm-ok'. If KVM is supported, you will see a message indicating that KVM acceleration can be used.

What packages do I need to install KVM on Ubuntu?

To install KVM on Ubuntu, you need to install several packages, including 'qemu-kvm', 'virt-manager', 'libvirt-clients', and 'bridge-utils'. You can do this by running 'sudo apt install qemu-kvm virt-manager libvirt-clients bridge-utils libvirt-daemon-system virtinst'.

How do I add my user to the KVM group?

To manage virtual machines after installing KVM, you need to add your user account to the 'libvirt' and 'KVM' groups. You can do this by running 'sudo usermod -aG libvirt $USER' and 'sudo usermod -aG kvm $USER'.

Can I create a virtual machine using KVM on Ubuntu?

Yes, once KVM is installed and configured, you can create a virtual machine using the KVM virtual machine manager. Simply open the manager, click on 'New Virtual Machine', and follow the prompts to set up your new guest machine.

Categories:

Leave a Reply

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