How to Install KVM on Ubuntu 24.04 Step-by-Step

Hello Readers, in this blog post, we will show you how to install KVM on Ubuntu 24.04 step-by-step.

Kernel-based Virtual Machine (KVM) is a powerful virtualization technology built into Linux. It allows you to create and manage multiple virtual machines (VMs) on your Ubuntu 24.04 system. Follow this step-by-step guide to install KVM and get started with virtualization on your Linux server.

Prerequisites

  • Pre-Install Ubuntu 24.04 Instance (Server or Desktop)
  • A local user with sudo rights.
  • Stable Internet Connection
  • Ensure that your system supports virtualization. You can verify this by checking if your CPU has the necessary virtualization extensions (Intel VT or AMD-V) and if they are enabled in the BIOS.

Note: To enable the Virtualization, you need to go to bios settings of your system and enable Intel VT or AMD-V.

Check for Virtualization Support

$ egrep -c '(vmx|svm)' /proc/cpuinfo

If the output is more than 0, your CPU supports virtualization.

CPU Virtualization Support Check Ubuntu 24.04

1) Update the System

It is highly recommended, start by updating your package list to ensure you have the latest versions. Run the following command from the terminal.

$ sudo apt update && sudo apt upgrade -y

2) Install KVM and Related Packages

KVM and its related packages are available in the default apt repository of Ubuntu 24.04, so for its installation, run

$ sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager -y

This command installs KVM, QEMU, virt-mamager and other tools required to manage virtual machines.

Install KVM On Ubuntu 24.04

After the installation of above packages, start libvirtd service.

3)  Start and Enable Libvirtd service

Start and enable the libvirtd service using following systemctl command.

$ sudo systemctl enable --now libvirtd

Next, check libvirtd service status

Libvirtd Service Status Ubuntu 24.04

If the service is active and running, your installation was successful.

4) Add Your Local User to the KVM and Libvirt Group

For non-root users to manage virtual machines, add your user to the `libvirt` and `kvm` groups:

$ sudo usermod -aG libvirt,kvm $USER

Log out and log back in for these changes to take effect.

Check Local User Groups Using ID Command

5) Create Network Bridge using netplan

To access KVM virtual machines from outside your Ubuntu 24.04 system, you need to map the VM’s interface to a network bridge. While KVM creates a default virtual bridge called virbr0 for testing, it’s not suitable for external connections. To set up a proper network bridge, you should create a configuration file with extension *.yaml in the /etc/netplan directory. This configuration ensures that your VMs can communicate with other devices on the network efficiently.

$ cd /etc/netplan/
$ ls
50-cloud-init.yaml
$

Note : This file name may vary according to your setup but extension will be yaml.

Modify this file and add the following content to it.

$ sudo vi 50-cloud-init.yaml
network:
  renderer: NetworkManager
  ethernets:
    enp0s3:
      dhcp4: false
      dhcp6: false
  # add configuration for bridge interface
  bridges:
    br0:
      interfaces: [enp0s3]
      dhcp4: false
      addresses: [192.168.1.4/24]
      macaddress: 08:00:27:11:3c:a4
      routes:
        - to: default
          via: 192.168.1.1
          metric: 100
      nameservers:
        addresses: [4.2.2.2]
      parameters:
        stp: false
      dhcp6: false
  version: 2

Save and close the file.

Note : Change Interface Name, its macaddress, IP details that suits to your setup.

Netplan Config File Ubuntu 24.04

Apply these changes so that they comes into the affect, run

$ sudo netplan apply

Now, run ‘ip add show’ command to verify the bridge and ip details.

$ ip add show
$ ip route show

Network Bridge IP Details KVM Ubuntu

Great, output above confirms that we have successfully created a network bridge named br0 and has assigned a static IP address to it. Interface for the bridge is ‘enp0s3’.

6) Launch Virt-Manager and Create virtual Machine

Virt-Manager is a graphical interface that makes it easier to create and manage virtual machines.

You can now create and manage your VMs through a user-friendly interface.

  • Open Virt-Manager and click on “Create a New Virtual Machine.”
  • Follow the prompts to specify the installation source, disk space, memory, and CPU settings for your new VM.
  • Complete the setup and start your new virtual machine.

Create VM Using Virt-Manager

Alternate way to create virtual machine is from the command line using virt-install command. This is mostly used on Ubuntu servers where we don’t have desktop environment.

Creating Virtual Machine from Command Line

Use the virt-install command to create a VM, as shown below.

$ sudo virt-install \
--name RockLinuxVM \
--ram 1024 \
--vcpus 2 \
--disk path=/var/lib/libvirt/images/rocklinuxvm.img,size=10 \
--os-variant rocky9 \
--network bridge=br0 \
--graphics vnc,listen=0.0.0.0 \
--cdrom /home/linuxtechi/Rocky-9.3-x86_64-minimal.iso

Note: Adjust these parameters that suits to your setup.

Create KVM VM from Command Line Using Virt-Install

Now start the VNC viewer and connect it your Ubuntu 24.04 on port 5900, as shown below.

VNC-Viewer KVM VM Ubuntu 24.04

Follow the screen instructions and complete the installation.

That’s all from this post, I believe you have found these instructions useful. Feel free to ask if you need further details or assistance with your KVM setup!

Leave a Comment

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