QEMU/KVM Installation Guide
QEMU is a generic open-source machine emulator and virtualizer. When combined with KVM (Kernel-based Virtual Machine), it provides near-native performance for virtual machines on Linux.About QEMU and KVM
QEMU is a flexible emulator that can:
- Emulate different CPU architectures
- Run virtual machines with various operating systems
- Work with or without hardware acceleration
- Provides hardware virtualization support
- Allows QEMU to run VMs at near-native speed
- Requires CPU virtualization extensions (Intel VT-x or AMD-V)
Prerequisites
System Requirements- Linux operating system
- 64-bit CPU with virtualization extensions (Intel VT-x or AMD-V)
- Sudo/root access for installation
- Basic command-line knowledge
Checking Virtualization Support
Before installing KVM, verify your CPU supports virtualization extensions:If this command returns no output, your CPU doesn’t support virtualization extensions or they’re disabled in BIOS. You can still use QEMU without KVM, but performance will be significantly slower.
Interpreting the results
Interpreting the results
- vmx: Intel VT-x virtualization technology
- svm: AMD-V virtualization technology
Installing QEMU and KVM
Install QEMU
Install the QEMU emulator:This installs the core QEMU packages for various architectures.
Testing QEMU
You can test QEMU with pre-built images from the QEMU Testing wiki.
Creating a Virtual Disk
QEMU supports various disk image formats:- raw: Simple binary image (compatible but large)
- qcow2: QEMU’s native format (flexible, supports snapshots)
- vmdk: VMware format
- vdi: VirtualBox format
Create a qcow2 disk:
Understanding the command
Understanding the command
qemu-img create: Creates a new disk image-f qcow2: Specifies the format (qcow2 is recommended)debian9.img: Name of the image file3G: Size of the virtual disk (3 gigabytes)
Installing an Operating System
Start Installation
Boot the VM with the ISO attached:
Command breakdown
Command breakdown
qemu-system-x86_64: 64-bit x86 emulator-m 2048: Allocate 2048 MB (2 GB) RAM-hda debian9.img: Attach the virtual disk as the primary hard drive-cdrom file.iso: Attach the ISO as a CD-ROM-boot d: Boot from CD-ROM (d = CD-ROM drive)
Running the Installed System
After installation, boot from the hard disk:The
-boot d option is removed, so QEMU boots from the hard disk by default.Using Physical CD/DVD
To use a physical CD-ROM or DVD:Enabling KVM Acceleration
If you installed KVM, enable it for better performance:KVM acceleration can improve VM performance by 10-20x compared to pure emulation.
Common QEMU Options
Useful QEMU command-line options
Useful QEMU command-line options
Memory and CPUStorageNetworkingDisplayBoot Options
Disk Image Management
Check image information:
Convert image formats:
Resize disk:
Networking Configuration
User-mode networking (NAT):
Bridge networking:
Next Steps
After mastering basic QEMU usage:- libvirt: Use
virt-managerfor graphical VM management - Snapshots: Take VM snapshots with qcow2 format
- Networking: Configure advanced network topologies
- Performance: Optimize VMs with virtio drivers
- Cloud Images: Use cloud-init images for automation
Troubleshooting
VM is very slow- Ensure KVM is installed and
-enable-kvmis used - Check that virtualization is enabled in BIOS
- Allocate more RAM with
-m - Try
-cpu hostfor better CPU passthrough
- Try different display options:
-display sdlor-display gtk - Check that X11 is running if on Linux desktop
- Use
-nographicfor serial console only
- Verify
-net nic -net useris specified - Check firewall settings on host
- Try different network modes
Additional Resources
This tutorial is based on content from Fortinux