How to Set Up KVM and Cockpit on Ubuntu 24.04

Looking to run virtual machines on your Ubuntu 24.04 system without a desktop GUI? This guide walks you through installing KVM (Kernel-based Virtual Machine) and setting up Cockpit, a browser-based interface for managing VMs, right from your browser.


What Is KVM?

KVM (Kernel-based Virtual Machine) is a full virtualization solution built directly into the Linux kernel. It allows you to run multiple, isolated virtual machines (VMs) using standard Linux tools. Each VM has its own virtualized hardware (CPU, memory, disk, network) and can run Linux, Windows, BSD, or other operating systems.

KVM works in combination with:

  • QEMU – which emulates hardware devices
  • libvirt – which provides an API and CLI for managing VMs
  • VirtIO drivers – for high-performance guest I/O

Key advantages of KVM:

  • Native performance (runs directly on the CPU with hardware virtualization)
  • Part of the Linux kernel (no extra kernel modules or third-party software)
  • Works on headless systems, servers, and desktops
  • Supported by tools like virsh, virt-manager, and Cockpit

Together with Cockpit, KVM turns Ubuntu into a powerful and easy-to-manage virtualization host.


Prerequisites

  • Ubuntu 24.04 LTS (server or desktop)
  • A CPU with Intel VT-x or AMD-V support
  • A user with sudo privileges

  1. Check CPU Virtualization Support

First, verify that your CPU supports virtualization:

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

If the result is 0, your CPU doesn’t support virtualization, and KVM won’t work.


  1. Install KVM and libvirt

Install the core virtualization stack:

sudo apt update
sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients

What These Packages Do:

PackagePurpose
qemu-kvmCore virtualization engine (runs the VMs)
libvirt-daemon-systemManages VMs via the libvirtd service
libvirt-clientsCLI tools like virsh (also used internally by Cockpit)

Add your user to the libvirt and kvm groups:

sudo usermod -aG libvirt,kvm $USER

Log out and log back in to apply the new group memberships.


  1. (Optional) Configure Bridge Networking

To allow your VMs to access your LAN or the internet, create a bridge interface using Netplan.

Edit your Netplan config:

sudo vi /etc/netplan/50-cloud-init.yaml

Example configuration (replace eno1 with your actual network interface):

network:
  version: 2
  ethernets:
    eno1: {}
  bridges:
    br0:
      interfaces: [eno1]
      dhcp4: true
      dhcp6: false
      parameters:
        stp: false
        forward-delay: 0

Apply the config:

sudo netplan apply

Check that br0 received an IP:

ip a

You do not need bridge-utils on Ubuntu 24.04. Netplan and systemd handle bridge creation natively.

For a deeper explanation of bridge networking and why it’s useful for VMs, read this post:
What Is a Bridge Network in Ubuntu 24.04?


  1. Install Cockpit with Virtual Machine Support

To get the most recent version of Cockpit and avoid bugs in older releases, install it via the official Ubuntu backports repository:

. /etc/os-release
sudo apt install -t ${VERSION_CODENAME}-backports cockpit cockpit-machines

Not sure what backports are or when to use them?
Understanding the Backports Repository in Ubuntu 24.04

Open Cockpit in your browser:

https://<your-server-ip>:9090

Login with your Ubuntu username and password.


  1. Create and Manage VMs in Cockpit

Once Cockpit is installed and running, it’s time to create your first virtual machine.

  • Download and Prepare the ISO

Before creating the VM, download an Ubuntu Server ISO and place it in the default libvirt image directory:

wget https://ubuntu.ccns.ncku.edu.tw/ubuntu-cd/24.04.2/ubuntu-24.04.2-live-server-amd64.iso
sudo mv ubuntu-24.04.2-live-server-amd64.iso /var/lib/libvirt/images/

This ISO will be used as the installation source for the VM.

  • Creating a New VM

Here’s how your setup might look in Cockpit when creating a new VM:

Click Create and edit instead of Create and run, so you can fine-tune network settings.

  • Configure Bridge Networking

To ensure your VM gets a LAN IP via DHCP (from your router or upstream network), change the network interface to use your custom bridge br0.

  • Start the VM

After saving, return to the VM summary and click Install. Open the console and begin installing Ubuntu as usual.


  1. Install QEMU Guest Agent (Inside VMs)

For better integration with the host (e.g., IP address reporting):

sudo apt install qemu-guest-agent
sudo systemctl enable --now qemu-guest-agent

Do this inside each Linux VM you install.


Do You Still Need virt-manager?

No, Cockpit replaces virt-manager on headless or remote systems.

virt-manager is a GTK desktop application. You only need it if:

  • You’re on a Linux desktop
  • You want advanced VM snapshot and XML features

For servers, Cockpit is lighter, easier, and fully browser-based.

Leave a Comment

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

Scroll to Top