How to qemu kvm
Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.
Last updated: April 4, 2026
Key Facts
- KVM (Kernel-based Virtual Machine) is a Linux kernel module that allows the kernel to function as a hypervisor.
- QEMU is a machine emulator and virtualizer that can emulate hardware, allowing it to run operating systems and programs made for one machine on a different machine.
- When combined, QEMU leverages KVM for hardware-assisted virtualization, offering near-native performance for guest operating systems.
- Virtual machine disk images are typically stored in formats like qcow2 or raw.
- Virt-manager provides a graphical interface for managing QEMU/KVM virtual machines, simplifying creation, configuration, and operation.
What is QEMU/KVM?
QEMU/KVM is a powerful open-source virtualization solution that is deeply integrated into the Linux operating system. It leverages two key components: KVM (Kernel-based Virtual Machine) and QEMU. KVM is a virtualization infrastructure built directly into the Linux kernel, allowing it to act as a hypervisor. This means that KVM can utilize hardware virtualization extensions (like Intel VT-x or AMD-V) present in most modern CPUs to run virtual machines with exceptional performance, close to that of the host machine. QEMU, on the other hand, is a versatile machine emulator and virtualizer. While QEMU can emulate a wide range of hardware on its own, when paired with KVM, it primarily acts as the user-space component. It handles tasks like emulating device peripherals (network cards, disk controllers, graphics adapters) and managing the virtual machine's lifecycle. This combination provides a robust and efficient platform for running multiple operating systems (guests) on a single physical machine (host).
Why Use QEMU/KVM?
The primary advantages of using QEMU/KVM lie in its performance, flexibility, and cost-effectiveness. Because KVM utilizes hardware virtualization, guest operating systems run with minimal overhead, making it suitable for demanding applications, gaming, and server consolidation. QEMU's extensive hardware emulation capabilities mean you can virtualize a wide variety of architectures and devices. Furthermore, as an open-source solution, QEMU/KVM is free to use, distribute, and modify, making it an attractive alternative to proprietary virtualization software. It's ideal for developers testing software on different OSes, system administrators managing server infrastructure, security researchers analyzing malware in isolated environments, or even hobbyists wanting to run different operating systems on their personal computers.
Getting Started with QEMU/KVM
Setting up QEMU/KVM typically involves a few key steps. First, ensure your system's CPU supports hardware virtualization and that it's enabled in your BIOS/UEFI settings. You can usually check this with commands like `egrep -c '(vmx|svm)' /proc/cpuinfo` on Linux; a result greater than 0 indicates support.
Installation:
The installation process varies slightly depending on your Linux distribution. On Debian/Ubuntu-based systems, you would typically use:
sudo apt updatesudo apt install qemu-kvm qemu-utils libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-managerOn Fedora/CentOS/RHEL systems, you would use:
sudo dnf install qemu-kvm qemu-img libvirt-daemon libvirt-client virt-install virt-managerIt's important to add your user to the `libvirt` and `kvm` groups to manage VMs without needing root privileges:
sudo usermod -aG libvirt $USERsudo usermod -aG kvm $USERYou'll need to log out and log back in for these group changes to take effect.
Creating Virtual Machines:
There are several ways to create and manage virtual machines:
- Graphical Interface (virt-manager): This is the most user-friendly method for desktop users. Launch `virt-manager` from your application menu or terminal. Click 'Create a new virtual machine' and follow the wizard. You'll select an installation method (e.g., local ISO image), specify CPU and memory, define storage (creating a new disk image or using an existing one), and configure networking.
- Command Line (virt-install): For scripting or advanced users, `virt-install` is a command-line tool that automates VM creation. It requires more parameters but offers greater control. For example:
virt-install \--name MyVM \--ram 2048 \--vcpus 2 \--disk path=/var/lib/libvirt/images/myvm.qcow2,size=20 \--os-type linux \--os-variant ubuntu22.04 \--network bridge=virbr0 \--graphics spice \--cdrom /path/to/your/os.iso - Direct QEMU Commands: While less common for daily management due to complexity, you can launch QEMU directly with extensive command-line options to specify CPU, memory, storage, network interfaces, and more. This is often used for specific emulation tasks or by developers deeply integrating QEMU into applications.
Disk Image Formats:
QEMU/KVM typically uses disk images to represent the storage for a virtual machine. The most common formats are:
- qcow2 (QEMU Copy-On-Write version 2): This is the recommended format. It supports features like snapshots, thin provisioning (only allocating space as needed), and compression.
- Raw: A simple, unformatted disk image that directly maps to a file. It offers slightly better performance in some scenarios but lacks advanced features like snapshots.
You can create disk images using `qemu-img create -f qcow2 myvm.qcow2 20G`.
Managing Virtual Machines
Once created, virtual machines can be managed through `virt-manager` (start, stop, pause, migrate, view console) or command-line tools like `virsh`. `virsh` is a powerful command-line interface for managing libvirt resources, including virtual machines. You can list VMs with `virsh list --all`, start a VM with `virsh start MyVM`, and shut it down with `virsh shutdown MyVM`.
Networking
QEMU/KVM offers flexible networking options:
- NAT (Network Address Translation): The default for `virt-manager` (using `virbr0`). VMs get IP addresses from a private subnet managed by the host, and outbound traffic is NATted. Simple for basic internet access.
- Bridged Networking: Connects VMs directly to the host's physical network, allowing them to appear as separate devices on the network with their own IP addresses. Requires setting up a network bridge on the host.
- Host-only Networking: Creates a private network between the host and VMs, useful for isolated testing.
Performance Considerations
For optimal performance:
- Ensure KVM is active and that hardware virtualization is used.
- Use the `qcow2` format for disk images, especially if you need snapshots.
- Allocate sufficient CPU and RAM to the VM, but avoid over-allocating.
- For storage-intensive workloads, consider using raw disk images or LVM logical volumes directly.
- Use virtio drivers within the guest OS (if supported) for network and disk I/O, as they provide paravirtualized performance benefits.
QEMU/KVM is a versatile and high-performance virtualization solution that is a cornerstone of cloud infrastructure and personal virtualization setups on Linux.
More How To in Daily Life
Also in Daily Life
More "How To" Questions
Trending on WhatAnswers
Browse by Topic
Browse by Question Type
Sources
- KVM (Kernel-based Virtual Machine) - WikipediaCC-BY-SA-4.0
- QEMU Documentationfair-use
- Virtualization Administration Guide - Red Hatfair-use
Missing an answer?
Suggest a question and we'll generate an answer for it.