Website Vidya
Linux & ServersStep-by-Step Guide

How to Install and Configure KVM on Ubuntu 24.04

Learn how to install KVM on Ubuntu 24.04 LTS with QEMU, libvirt, virt-manager, bridge networking, and virsh command-line hypervisor management.

RR
Rajesh RayLead Systems Educator
Published:
5 min read
PDF Cheat Sheet
How to Install and Configure KVM on Ubuntu 24.04
AI Executive SummaryWebsiteVidya AI

5 min read

Learn how to install KVM on Ubuntu 24.04 LTS with QEMU, libvirt, virt-manager, bridge networking, and virsh command-line hypervisor management.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Checking Hardware Virtualization Support on Your Host CPU
  • Step 2: Installing KVM, QEMU, Libvirt, and Virtualization Tools
Grounded in full engineering runbookWebsiteVidya AI Engine

Enterprise cloud infrastructure, automated CI/CD staging environments, and home-lab virtualization require reliable, bare-metal hypervisor performance. When you install kvm on ubuntu 24.04, you convert the Linux kernel directly into a Type-1 hypervisor that delivers near-native compute speeds, minimal host virtualization overhead, and seamless integration with Linux kernel scheduling.

Unlike hosted Type-2 hypervisors, KVM leverages CPU hardware extensions directly through the Linux kernel. Paired with QEMU hardware emulation, libvirt management APIs, and tools like virt-manager and virsh, KVM provides a modular and robust open-source virtualization platform. This guide covers prerequisite validation, package deployment, permissions management, virtual bridge networking, and virtual machine provisioning.

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Advertisement

Before proceeding, ensure you have the following requirements satisfied:

  • A dedicated server, cloud bare-metal instance, or workstation running Ubuntu 24.04 LTS.
  • An x86-64 processor equipped with Intel VT-x or AMD-V hardware virtualization support.
  • A user account with active sudo administrative privileges.
  • At least 4 GB of system RAM (8 GB or more recommended for hosting concurrent guest virtual machines).

Step 1: Checking Hardware Virtualization Support on Your Host CPU

If the output reports KVM acceleration can be used, your processor is ready. If it displays an error indicating that virtualization is disabled, restart your machine, enter the BIOS/UEFI setup screen, and enable Intel VT-x or AMD SVM.

# Install the cpu-checker utility
sudo apt update
sudo apt install -y cpu-checker

# Run the KVM compatibility check
kvm-ok

# Expected successful output:
# INFO: /dev/kvm exists
# KVM acceleration can be used

Step 2: Installing KVM, QEMU, Libvirt, and Virtualization Tools

KVM operates as a collection of modular tools: KVM provides kernel-level CPU/memory virtualization, QEMU emulates peripheral hardware devices, and libvirt provides unified background daemon control.

Install the core hypervisor stack and management packages via APT.

Advertisement
# Install KVM, QEMU, libvirt daemon, bridge utilities, and client tools
sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager

Core Virtualization Package Breakdown

Understanding each component ensures you can effectively troubleshoot and maintain your hypervisor stack:

Step 3: Verifying the libvirtd Daemon Service and Permissions

The libvirtd service manages virtual machine processes, virtual networking bridges, and storage pools. Ensure that the daemon is enabled and running.

Add your administrative user account to the libvirt and kvm groups so you can manage virtual machines without invoking sudo on every command.

# Verify the active status of libvirtd
sudo systemctl status libvirtd

# Ensure libvirtd starts automatically upon boot
sudo systemctl enable --now libvirtd

# Add your current user to the libvirt and kvm groups
sudo usermod -aG libvirt,kvm $USER

# Apply the new group memberships to your active session
newgrp libvirt

Step 4: Configuring Default NAT Virtual Networking

Libvirt creates a default virtual network switch named default backed by a private NAT subnet (typically 192.168.122.0/24 on the virbr0 bridge device).

Advertisement

Verify that the default network is active and set to autostart upon host boot.

# List all libvirt networks
virsh net-list --all

# If the default network is inactive, start and enable autostart
virsh net-start default
virsh net-autostart default

# Inspect the network configuration
virsh net-info default

Step 5: Creating Your First Virtual Machine via CLI (virt-install)

The virt-install utility provides an automated, headless method for provisioning virtual machines directly from the command line. This is ideal for remote servers without graphical desktop environments.

Download an Ubuntu 24.04 server ISO image to your storage directory and create a virtual machine named ubuntu-server-vm.

# Download the Ubuntu 24.04 LTS server ISO
sudo wget -P /var/lib/libvirt/images/ https://releases.ubuntu.com/24.04/ubuntu-24.04-live-server-amd64.iso

# Provision a new virtual machine with 2 vCPUs, 4 GB RAM, and 20 GB disk
sudo virt-install \
  --name=ubuntu-server-vm \
  --vcpus=2 \
  --memory=4096 \
  --cdrom=/var/lib/libvirt/images/ubuntu-24.04-live-server-amd64.iso \
  --disk path=/var/lib/libvirt/images/ubuntu-server-vm.qcow2,size=20,bus=virtio,format=qcow2 \
  --os-variant=ubuntu24.04 \
  --network network=default,model=virtio \
  --graphics none \
  --console pty,target_type=serial \
  --extra-args 'console=ttyS0,115200n8 serial'

Step 6: Managing Virtual Machines with virsh

The virsh command-line utility provides comprehensive controls to start, pause, inspect, shut down, and delete virtual machines on KVM hosts.

Review the essential administrative commands below:

# List all running and inactive virtual machines
virsh list --all

# Start a stopped virtual machine
virsh start ubuntu-server-vm

# Connect to the guest serial console
virsh console ubuntu-server-vm

# Gracefully shut down a virtual machine via ACPI
virsh shutdown ubuntu-server-vm

# Forcefully power off an unresponsive virtual machine
virsh destroy ubuntu-server-vm

# Undefine and delete a virtual machine along with its storage
virsh undefine ubuntu-server-vm --remove-all-storage

Step 7: Graphical Management Using Virtual Machine Manager (virt-manager)

In the graphical window, click File > New Virtual Machine. The wizard allows you to select local ISO media, configure virtual CPUs and memory sliders, choose storage formats, and inspect live graphical guest monitors using SPICE or VNC.

Virt-manager also excels at managing remote headless hypervisors over SSH. By selecting File > Add Connection and specifying qemu+ssh://user@remote-hypervisor/system, system administrators can manage enterprise servers located in data centers without installing a heavy desktop environment on the remote host.

# Launch Virtual Machine Manager
virt-manager &

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied.

Cause: The current user account is not a member of the libvirt group, or the active shell session has not reloaded group memberships.

Resolution: Add the user to the libvirt group and re-authenticate your shell session.

sudo usermod -aG libvirt $USER && newgrp libvirt

virt-install: 'os-variant ubuntu24.04 is not supported'.

Cause: The local osinfo-db hardware database is outdated and lacks definitions for Ubuntu 24.04.

Resolution: Update the osinfo database using APT or substitute with --os-variant=ubuntu22.04.

sudo apt update && sudo apt install -y osinfo-db

Guest virtual machines have no Internet connectivity.

Cause: The default libvirt NAT bridge (virbr0) is not active or host IP forwarding is disabled.

Resolution: Start the default network and enable IPv4 packet forwarding in /etc/sysctl.conf.

virsh net-start default && sudo sysctl -w net.ipv4.ip_forward=1

Security Best Practices and Hardening

Isolate guest virtual machine network traffic using dedicated VLANs or restricted virtual bridge networks.

Do not expose QEMU VNC or SPICE graphical consoles on public IP addresses; tunnel graphical display sessions through secure SSH connections.

Keep hypervisor storage pools isolated with strict Unix permissions (chmod 700 /var/lib/libvirt/images) to prevent unauthorized access to virtual disk images.

Enable AppArmor or SELinux profiles for libvirt (sVirt) to enforce kernel-level process confinement between untrusted virtual machine instances.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
Yes. Because KVM is built directly into the Linux kernel as a Type-1 hypervisor, CPU and memory virtualization operate with near-zero overhead, delivering significantly higher I/O throughput and lower latency than hosted Type-2 hypervisors.
Yes. Nested virtualization allows you to run KVM, VirtualBox, or Docker inside a KVM guest. To enable nested virtualization on Intel hosts, set options kvm_intel nested=1 in /etc/modprobe.d/kvm.conf.
QCOW2 is recommended for general virtualization because it supports dynamic thin provisioning, copy-on-write, compression, and snapshotting. RAW format offers slightly faster raw write performance but consumes the entire pre-allocated disk size immediately.
To exit a connected virsh console session back to your host terminal, press Ctrl+].
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout