Install Fedora in a VM

You can install Fedora in a virtual machine using KVM/QEMU on Linux or VirtualBox on any platform, then boot from the Fedora ISO to complete a normal installation.

You need a safe sandbox

You broke your main system trying to compile a custom kernel, or you need to test a new Fedora release without risking your daily driver. Or maybe you just want to run a specific legacy app in isolation. A virtual machine gives you a clean slate. You can snapshot, break things, and restore in seconds. This guide covers the standard Fedora way using KVM/QEMU, which is faster and more integrated than proprietary alternatives.

How KVM and QEMU work together

KVM turns the Linux kernel into a hypervisor. The guest OS runs on real hardware, just with a thin layer managing access. This means near-native performance. QEMU provides the device emulation for things the hardware cannot virtualize directly, like the network card or disk controller. libvirt is the daemon that manages the VMs, and virt-manager is the GUI wrapper that talks to libvirt.

Think of libvirt as the traffic controller and QEMU/KVM as the engine. You install the stack, point it at an ISO, and the kernel handles the heavy lifting. KVM uses hardware virtualization extensions (Intel VT-x or AMD-V) to run guest code directly on the CPU. QEMU steps in only when the guest tries to access a device that needs emulation, such as a legacy IDE controller or a specific USB device. This split architecture gives you the speed of hardware virtualization with the flexibility of full emulation.

Fedora's release cadence is 6 months. The N-2 release goes EOL when N+1 ships. Plan your VM upgrades on that cycle. Use dnf system-upgrade inside the guest to move between releases, not dnf upgrade. They are different commands. dnf upgrade --refresh is for weekly maintenance. dnf system-upgrade crosses major release boundaries.

Install the virtualization stack

Install the virtualization group package. This pulls in KVM, QEMU, libvirt, and virt-manager in one transaction.

sudo dnf install @virtualization
# Install the full virtualization group including KVM, QEMU, libvirt, and virt-manager
sudo systemctl enable --now libvirtd
# Start the libvirt daemon and enable it to run at boot
sudo usermod -aG libvirt $(whoami)
# Add your user to the libvirt group to manage VMs without sudo

Log out and back in for the group change to take effect. Group membership is evaluated at login. Running newgrp libvirt in the current shell works for testing, but logging out ensures all future sessions inherit the permission.

Log out and back in. Group changes do not apply to active sessions.

Download and verify the ISO

Get the latest Fedora Workstation or Server ISO from the official download page. Always verify the checksum before installing. A corrupted download often causes silent failures during partitioning or kernel installation.

sha256sum Fedora-Workstation-Live-x86_64-*.iso
# Calculate the hash of your downloaded ISO to verify integrity

Compare the output to the checksum listed on the download page. The hash must match exactly.

Compare the hash to the official checksum. A mismatch means a corrupted download, not a broken system.

Create the VM with virt-install

virt-install creates the VM definition and starts the installer. The os-variant flag tells libvirt which Fedora version you are installing. This auto-configures the installer for the correct partitioning scheme and kernel parameters. Using the wrong variant can cause the installer to fail or create a suboptimal disk layout.

sudo virt-install \
  --name fedora-test \
  --memory 4096 \
  --vcpus 2 \
  --disk size=20,bus=virtio \
  --os-variant fedora-rawhide \
  --cdrom /path/to/Fedora-Workstation-Live-x86_64-41.iso \
  --graphics spice \
  --network network=default
# Create a VM named fedora-test with 4GB RAM, 2 CPUs, and a 20GB virtio disk
# Use the correct os-variant for your ISO version to auto-configure installer settings
# spice graphics provides better clipboard and resolution support than vnc
# Attach to the default libvirt network for NAT internet access

The --disk bus=virtio flag is important. VirtIO is a paravirtualized disk driver. It bypasses the emulation overhead of IDE or SCSI controllers and delivers much higher I/O performance. Fedora guests include the virtio drivers by default. If you install an older OS that lacks VirtIO support, you must change bus=virtio to bus=ide or bus=sata.

Watch the console. If the installer hangs, check the os-variant flag. Wrong variants cause partitioning failures.

Integrate the guest agent

Once Fedora is running inside the VM, install the QEMU guest agent. This daemon runs inside the guest and communicates with the host over a virtual channel. It enables clipboard sharing, dynamic display resolution, accurate shutdown signals, and IP address reporting. Without the agent, the host cannot see the guest's internal state.

sudo dnf install qemu-guest-agent
# Install the agent for clipboard sharing and graceful shutdown
sudo systemctl enable --now qemu-guest-agent
# Enable the service so the host can query the guest state

Config files in /etc/ are user-modified. Files in /usr/lib/ ship with the package. Edit /etc/. Never edit /usr/lib/. If you need to tweak the guest agent behavior, check /etc/sysconfig/qemu-ga or the systemd drop-ins, not the package defaults.

Install the guest agent immediately. Without it, the host cannot detect the guest IP or trigger a clean shutdown.

Manage snapshots

Snapshots let you save the VM state and disk at a specific point. You can revert to a snapshot if an upgrade breaks the system or an experiment goes wrong. This is the superpower of virtualization.

virsh snapshot-create-as fedora-test pre-upgrade --description "Before major update"
# Create a named snapshot before risky operations
virsh snapshot-list fedora-test
# View available snapshots for the VM
virsh snapshot-revert fedora-test pre-upgrade
# Revert the VM to the specified snapshot state

Snapshots work best with qcow2 disk images, which is the default format for libvirt. Raw disk images do not support internal snapshots. Always verify the disk format before relying on snapshots.

Snapshot the system before the upgrade. Future-you will thank you.

Verify the setup

Check that the VM is running and that the guest agent is communicating. The domifaddr command queries the guest agent for the IP address. If the agent is not installed or not running, this command returns nothing.

virsh list --all
# List all VMs and their current state
virsh domifaddr fedora-test
# Query the guest agent for the IP address of the specified VM

Run virsh domifaddr. If it returns an IP, the agent is working. If it returns nothing, check the guest service status.

Common errors and fixes

Permission denied on libvirt socket

The error error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied means your user is not in the libvirt group. You likely ran usermod but did not log out.

Fix: Log out and log back in. Verify with groups. Your output must include libvirt.

Nested virtualization fails

If you try to run a VM inside a VM, you may see kvm: internal error: process exited unexpectedly or the guest fails to detect KVM. Nested virtualization must be enabled on the host.

Check the status:

cat /sys/module/kvm_intel/parameters/nested
# Check if nested virtualization is enabled for Intel CPUs
# Replace kvm_intel with kvm_amd for AMD processors

If the output is N or 0, enable it by adding options kvm_intel nested=1 to /etc/modprobe.d/kvm.conf and reloading the module. Some BIOS settings also control virtualization extensions. Ensure VT-x or AMD-V is enabled in the firmware.

Disk space exhaustion

The default storage pool is /var/lib/libvirt/images. If your root partition is small, VM disks can fill the host disk. This causes VM crashes and host instability.

Fix: Create a dedicated storage pool on a larger partition or external drive. Use virt-manager or virsh pool-create-as to define the pool, then attach VM disks to that pool.

Check permissions before blaming the kernel. 90% of VM errors are user group issues.

Choose your tool

Use KVM with QEMU when you need near-native performance and deep Linux integration.

Use VirtualBox when your host is Windows or macOS and you cannot run KVM.

Use virt-manager when you prefer a graphical wizard for creating and managing VMs.

Use virt-install when you want a reproducible command-line workflow or automation.

Use qemu-guest-agent when you need clipboard sharing, dynamic resolution, or IP reporting from the host.

Stay on the default libvirt network when you just need internet access for the guest.

Switch to a bridge network when the guest needs a dedicated IP on your physical LAN.

Where to go next