How to Install KVM/QEMU and Virt-Manager on Ubuntu: High-Performance Type-1 Virtualization

Ubuntu tutorial - IT technology blog
Ubuntu tutorial - IT technology blog

If you’re tired of VirtualBox hogging RAM, lagging, or crashing with kernel module errors whenever Ubuntu updates its Linux kernel, it’s time to switch to KVM/QEMU. KVM turns the Linux kernel directly into a bare-metal (Type-1) hypervisor, allowing VM CPU and disk I/O performance to reach roughly 95–98% of native bare-metal speeds.

Quick Start: Spin Up a KVM Virtual Machine with Virt-Manager in 5 Minutes

First, verify whether your CPU supports hardware virtualization (Intel VT-x or AMD-V):

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

If the command returns 1 or higher (typically 4, 8, or 16 depending on your CPU thread count), your system is ready. If it returns 0, enter your BIOS/UEFI settings and enable Intel Virtualization Technology (VT-x) or AMD SVM/SVM Mode.

Next, install KVM, QEMU, libvirt, and the Virt-Manager GUI:

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

Add your current user to the libvirt and kvm groups to manage VMs without root privileges:

sudo usermod -aG libvirt,kvm $USER
newgrp libvirt

Enable and start the libvirtd service so it runs automatically in the background on boot:

sudo systemctl enable --now libvirtd

Run virt-manager in your terminal or launch the Virtual Machine Manager app. Click the computer icon in the top-left corner to create a new VM. Select your installation ISO image, allocate system resources (for example, 4 vCPUs, 4GB RAM, and a 30GB disk), and click Finish. Your VM will boot right into the installer within seconds.

Under the Hood: How Do KVM, QEMU, and Virt-Manager Work Together?

Linux newcomers often mistake these three tools for a single piece of software. In reality, each component handles a dedicated layer:

1. KVM (Kernel-based Virtual Machine)

KVM is a kernel module built directly into Linux. Its primary job is to interface with hardware virtualization extensions (VT-x/AMD-V). KVM allows virtual machine vCPUs to execute instructions directly on the host CPU without an instruction translation layer, minimizing latency.

2. QEMU (Quick Emulator)

KVM only handles CPU and RAM virtualization. It does not emulate keyboards, mice, network cards, or storage buses. Operating in userspace, QEMU fills this gap: it emulates chipsets, peripheral devices, virtual display adapters, and loads the BIOS/UEFI (OVMF) firmware for the VM.

3. Libvirt and Virt-Manager

Running the raw qemu-system-x86_64 command with dozens of verbose flags is tedious and error-prone. The libvirt daemon standardizes all VM, networking, and storage configurations into structured XML files. Meanwhile, Virt-Manager provides a GTK-based desktop interface, letting you create VMs, tweak settings, and take snapshots with point-and-click ease—without touching the underlying configuration files.

Configuring a Bridge Network and Managing VMs Remotely via SSH

By default, KVM guests sit behind a NAT network (the 192.168.122.0/24 subnet via the virbr0 interface). While the VM can access the Internet, other devices on your local network cannot ping or SSH directly into it.

Creating a Linux Bridge to Obtain IPs Directly from Your Router

To assign your VM an IP address on the same local subnet as your LAN (e.g., 192.168.1.x), bind your physical network interface to a virtual bridge using Netplan:

sudo nano /etc/netplan/01-netcfg.yaml

Assuming your physical network interface is enp3s0, update the file contents as follows:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: false
  bridges:
    br0:
      interfaces: [enp3s0]
      dhcp4: true
      parameters:
        stp: false
        forward-delay: 0

Apply the new network configuration:

sudo netplan apply

Open Virt-Manager, select your VM > go to the NIC section. Change Network source from NAT to Bridge device... and enter br0. After a reboot, the VM will receive an IP directly from your router’s DHCP server.

Managing Headless Remote Servers via SSH

You don’t need to install a heavy desktop GUI on your server. If you prefer full command-line management without a GUI, you can check out our guide on headless KVM/QEMU virtualization with virsh. On a staging host running Ubuntu Server 22.04/24.04, simply install qemu-kvm and libvirtd. You can run the entire Virt-Manager GUI locally from your personal laptop.

In Virt-Manager on your laptop, navigate to File > Add Connection. Check Connect to remote host over SSH, enter the server’s username and IP address, and connect. For servers exposed to public networks, you can also set up two-factor authentication (2FA) for SSH to secure your remote access. Libvirt will automatically tunnel the socket over SSH—keeping communication secure while saving hundreds of megabytes of RAM on the server.

Production Best Practices and Tips

  • Always prioritize VirtIO: When configuring virtual disk hardware, set the bus to VirtIO instead of SATA. Likewise, configure the network adapter as virtio rather than e1000. VirtIO uses paravirtualization drivers, boosting disk read/write throughput from ~180MB/s to over 500MB/s on NVMe drives. If you are installing a Windows guest, download the virtio-win ISO from Fedora to load the storage drivers during setup.
  • Choose QCOW2 over RAW: QCOW2 features thin provisioning (allocating space only as needed), built-in compression, and near-instantaneous snapshots taking just 1–2 seconds. Stick with RAW only if you are running rigorous database benchmarks where squeezing out the last 2–3% of IOPS is critical.
  • Fixing Permission Denied errors with ISO images: Because the QEMU process runs under the libvirt-qemu user, it cannot read ISO files stored in home directories like /home/user/Downloads. The cleanest fix is to move the ISO to libvirt’s managed pool directory:
sudo mv ~/Downloads/ubuntu.iso /var/lib/libvirt/images/
sudo chown libvirt-qemu:kvm /var/lib/libvirt/images/ubuntu.iso
  • Handy virsh commands to keep in your toolkit: Useful when the Virt-Manager GUI freezes or when writing automation bash scripts:
virsh list --all                                                      # Check status of all VMs
virsh start vm-ubuntu                                                # Start virtual machine
virsh shutdown vm-ubuntu                                             # Graceful ACPI shutdown
virsh destroy vm-ubuntu                                              # Force power-off if VM hangs
virsh snapshot-create-as --domain vm-ubuntu --name "before-update"    # Create a backup snapshot

The combination of KVM/QEMU and Virt-Manager perfectly balances raw performance with ease of use. If you are running multiple VMs on resource-constrained hardware, consider optimizing RAM on Ubuntu with zRAM and swap to prevent out-of-memory issues. Lighter than VirtualBox and more flexible than VMware Workstation, this stack is well worth mastering for anyone working regularly with Linux.

Share: