Skip to main content
Home/Blog/KVM Installation Guide | Linux Virtualization Setup
Virtualization

KVM Installation Guide | Linux Virtualization Setup

Master KVM virtualization with this comprehensive step-by-step installation and configuration guide for enterprise environments.

KVM Installation Guide | Linux Virtualization Setup

To install KVM on Fedora or a RHEL-family host, check virtualization support, install qemu-kvm, libvirt, and virt-install with dnf, start the available libvirt service or sockets, and run sudo virt-host-validate. Package groups and GUI tools vary by distribution. Before you start, check that the CPU exposes hardware virtualization with grep -E -c '(vmx|svm)' /proc/cpuinfo.

That is the summary an AI overview gives you. The rest of this guide is what it can't: the order the steps actually have to happen in, what each package really does, how to read virt-host-validate output, the difference between the legacy libvirtd daemon and the newer modular sockets, and a copy-paste path from a bare host to a running VM. This is a rewrite of an older version of this article that documented Fedora Core 14, yum, and service libvirtd start — all long since replaced.

The install path at a glance

Every successful KVM setup follows the same five steps in the same order. Skip the verification and you find out something is wrong only when a VM refuses to start.

KVM installation step flow Five sequential stages: check virtualization support, install the virtualization group, enable the libvirtd service, validate the host with virt-host-validate, then create a VM. A marker moves left to right across the stages. From bare host to running VM 1 Check support /proc/cpuinfo 2 Install dnf @virtualization 3 Enable systemctl libvirtd 4 Validate virt-host-validate 5 Create VM virt-install

Step 1: Confirm hardware virtualization is available

KVM needs a CPU with hardware virtualization extensions — Intel VT-x (flag vmx) or AMD-V (flag svm). Check for them:

grep -E -c '(vmx|svm)' /proc/cpuinfo

Any number greater than 0 means the extensions are present (the count is roughly one per logical core). If you get 0, the feature is almost always just disabled in firmware. Reboot into your BIOS/UEFI setup and enable the option named Intel Virtualization Technology / VT-x, AMD-V, or SVM Mode, then boot back into Linux and re-run the check.

You can also confirm the KVM kernel modules are loadable:

lsmod | grep kvm

You should see kvm plus either kvm_intel or kvm_amd.

Step 2: Install the virtualization packages

On Fedora, the @virtualization package group is a convenient option:

sudo dnf install -y @virtualization

Group contents vary by distribution. The main components are:

PackageRole
qemu-kvmThe hypervisor. Runs the VM and uses the KVM kernel modules for near-native CPU speed.
libvirtManagement daemon (libvirtd), API, and the virsh CLI. The layer everything else talks to.
virt-installCommand-line VM creation — scriptable, ideal for automation and headless servers.
virt-managerGraphical VM manager and console (desktop only).
virt-viewerLightweight SPICE/VNC console client for connecting to a guest display.

For a core setup, install the packages explicitly:

sudo dnf install -y qemu-kvm libvirt virt-install

Step 3: Enable and start the libvirt service

The hypervisor tooling is installed but idle until you start the management daemon. On the vast majority of systems, one command enables it at boot and starts it now:

sudo systemctl enable --now libvirtd

Confirm it's running:

systemctl status libvirtd

Modular libvirt (newer Fedora and fresh RHEL 9): recent releases split the single libvirtd daemon into per-driver daemons activated by systemd sockets. If enable --now libvirtd reports the unit is masked or missing, enable the modular sockets instead:

for drv in qemu network nodedev nwfilter secret storage; do
  sudo systemctl enable --now virt${drv}d.socket
done

Either approach leaves you with a working libvirt — the modular sockets simply start each driver on demand rather than all at once.

Step 4: Add your user to the libvirt group

By default, managing the system-wide VMs (qemu:///system) requires root. Add your account to the libvirt group so virsh and virt-manager work without sudo on every command:

sudo usermod -aG libvirt $USER

Group membership only applies to new login sessions, so log out and back in — or apply it to the current shell immediately:

newgrp libvirt

Step 5: Validate the host

This is the step the old guides skipped and the one that saves you the most debugging. virt-host-validate runs a checklist against your host and tells you exactly what is ready and what is not:

sudo virt-host-validate

Healthy output looks like this (abridged):

  QEMU: Checking for hardware virtualization                    : PASS
  QEMU: Checking if device /dev/kvm exists                      : PASS
  QEMU: Checking if device /dev/kvm is accessible               : PASS
  QEMU: Checking for cgroup 'cpu' controller support            : PASS
  QEMU: Checking for device assignment IOMMU support            : WARN (No ...)

Everything reporting PASS means KVM is ready. The one WARN you can usually ignore is the IOMMU line — that only matters for PCI passthrough (handing a physical GPU or NIC to a VM). For ordinary virtual disks and virtual NICs it is irrelevant.

Pre-flight checklist

Before creating VMs, confirm all of the following:

  • grep -E -c '(vmx|svm)' /proc/cpuinfo returns a number greater than 0
  • The required virtualization packages installed without errors
  • systemctl status libvirtd (or the modular sockets) shows active/running
  • groups lists libvirt for your user (after re-login)
  • sudo virt-host-validate shows PASS on hardware virtualization and /dev/kvm
  • virsh net-list --all shows the default network (activate it if inactive: sudo virsh net-start default)

Build your first VM

With the host validated, create a VM from the command line with virt-install. Here is a complete, working example that boots an installer ISO:

sudo virt-install \
  --name fedora-vm \
  --memory 4096 \
  --vcpus 2 \
  --disk size=20 \
  --cdrom /var/lib/libvirt/images/Fedora-Workstation-Live.iso \
  --os-variant fedora40 \
  --network network=default \
  --graphics vnc

That provisions a VM named fedora-vm with 4 GB of RAM, 2 vCPUs, a 20 GB qcow2 disk, the default NAT network, and a VNC console. SPICE is unavailable in some RHEL configurations. To find the right value for --os-variant (it tunes the virtual hardware for the guest OS), query the OS database:

osinfo-query os | grep -i fedora

Prefer a wizard? Install virt-manager if it is not already present, launch it, click Create a new virtual machine, and walk through the same choices graphically.

Building virt-install commands by hand is fiddly — the flags are many and the ISO/os-variant details are easy to get wrong. This interactive builder generates the exact virsh and provisioning commands for you:

Loading tool...

Confirm the VM is running

Once the guest is up, list it and manage it with virsh:

# List all VMs (running and stopped)
virsh list --all

# Start / shut down / reboot
virsh start fedora-vm
virsh shutdown fedora-vm

# Open the graphical console
virt-viewer fedora-vm

If you skipped the libvirt group step and see permission errors, prefix these with sudo or connect explicitly with virsh -c qemu:///system list.

Command quick reference

Everything in this guide, in one place:

TaskCommand
Check CPU virtualization support`grep -E -c '(vmx
Install core packagessudo dnf install -y qemu-kvm libvirt virt-install
Install headless (no GUI)sudo dnf install -y qemu-kvm libvirt virt-install
Enable + start the daemonsudo systemctl enable --now libvirtd
Enable modular socketssudo systemctl enable --now virtqemud.socket virtnetworkd.socket
Add user to libvirt groupsudo usermod -aG libvirt $USER
Validate the hostsudo virt-host-validate
List guest OS variantsosinfo-query os
Create a VMsudo virt-install --name NAME --memory MB --vcpus N --disk size=GB --cdrom ISO --os-variant VARIANT
List VMsvirsh list --all
Start / stop a VMvirsh start NAME / virsh shutdown NAME
Default network statusvirsh net-list --all

Where KVM keeps its files

When you need to inspect or back up configuration:

  • VM and network definitions: /etc/libvirt/ (XML for each domain, plus qemu.conf)
  • Virtual disk images: /var/lib/libvirt/images/ (the default storage pool)
  • Logs: /var/log/libvirt/ — per-VM logs live under qemu/

Configuration should be changed with virsh edit NAME rather than by hand-editing the XML, so libvirt validates and reloads it correctly.

Next steps

You now have a validated KVM host and a running VM. From here:

For another dedicated-host hypervisor setup, see the XenServer installation guide.

Frequently Asked Questions

Find answers to common questions

To optimize KVM performance on Fedora, particularly concerning CPU and memory management, several key configurations and best practices must be implemented. First, ensure that your host system supports hardware virtualization (Intel VT-x or AMD-V) and that it is enabled in the BIOS. This can significantly enhance KVM performance by allowing the hypervisor to run virtual machines more efficiently.

Next, consider configuring CPU pinning, which binds virtual CPUs (vCPUs) of your virtual machines to specific physical CPUs on the host. This reduces context switching and can enhance performance, especially for CPU-intensive workloads. You can achieve this by editing the XML configuration of your VM using virsh edit <vm-name> and setting the <vcpu> section to specify the CPU cores allocated to the VM.

Memory management is also crucial. It’s advisable to use huge pages, which can improve memory performance by reducing the overhead associated with managing large amounts of memory. You can enable huge pages in Fedora by adding the following line to your /etc/sysctl.conf:

mmap_min_addr = 65536

Then, allocate huge pages by adding the following to your /etc/default/grub:

GRUB_CMDLINE_LINUX="... hugepages=4G"

After updating the grub configuration, run grub2-mkconfig -o /boot/grub2/grub.cfg and reboot your system.

Additionally, consider configuring the balloon driver (virtio-balloon) for dynamic memory management in your VMs. This allows the hypervisor to adjust the memory allocated to a VM based on demand, which can prevent resource starvation and improve overall system performance.

Finally, regularly monitor your KVM environment using tools like virt-top or htop to track resource usage and identify any bottlenecks in CPU or memory allocation. By applying these optimizations, you can significantly enhance the performance of your KVM host and the virtual machines running on it.

When setting up NFS for KVM on Fedora, SELinux (Security-Enhanced Linux) configurations play a crucial role in ensuring secure and efficient operation. By default, SELinux is set to 'enforcing' mode, which can restrict access to NFS mounts unless properly configured. This can lead to issues where KVM cannot access the shared storage, resulting in failures when creating or managing virtual machines.

To configure SELinux for NFS, you need to set the appropriate context for the NFS share. First, ensure that the NFS server exports the shared directory with the correct SELinux context. You can set the context using the semanage command. For example:

semanage fcontext -a -t nfs_t '/path/to/nfs/share(/.*)?'
restorecon -R /path/to/nfs/share

This command ensures that the NFS share is labeled for NFS access. Additionally, you need to allow NFS-related SELinux booleans. Use the following commands to set the necessary booleans:

setsebool -P nfs_export_all_rw 1
setsebool -P allow_nfsd_anon_write 1

These commands permit NFS to handle read and write requests and allow anonymous users to write to the exported directories. After making these changes, restart the NFS service to apply the new settings:

systemctl restart nfs-server

Troubleshooting SELinux-related issues can be done using audit2why or audit2allow, which help interpret SELinux denial messages. For example, check SELinux logs in /var/log/audit/audit.log for any AVC (Access Vector Cache) denials related to NFS. You can run:

audit2why < /var/log/audit/audit.log

This command will provide a human-readable explanation of the denial. If necessary, you can create custom policies to allow specific access. However, it's essential to ensure that any changes do not compromise security. Regular audits of SELinux settings and access logs will help maintain a secure KVM environment while ensuring proper access to NFS shares.

Configuring firewall settings for KVM is crucial to ensure secure remote management and seamless migration of virtual machines. Fedora uses firewalld as the default firewall management tool, which provides a dynamic way to manage firewall rules.

To begin, you need to open the necessary ports for KVM management and VM migration. The essential ports include:

  • TCP port 16509 for libvirt management (used by virt-manager)
  • TCP port range 49152-49261 for live migration

You can enable these ports with the following commands:

f firewall-cmd --zone=public --add-port=16509/tcp --permanent
firewall-cmd --zone=public --add-port=49152-49261/tcp --permanent

After adding these ports, reload the firewall to apply the changes:

f firewall-cmd --reload

In addition to opening ports, it is also advisable to create a dedicated firewall rule for virt-manager that allows only trusted IP addresses to connect to the management interface. This can be done by creating a specific rule:

f firewall-cmd --zone=public --add-rich-rule='rule family=

Optimize Your Virtual Infrastructure

VMware, Hyper-V, or cloud VMs — our team helps you get the most from your virtualization investment.