Run a complete VM with just 4 commands
QEMU is a machine emulator and virtualizer. It can emulate entire systems, including CPU, memory, and devices — running any OS on any CPU architecture.
- QEMU emulates every CPU instruction in software.
- Works on any host CPU, regardless of architecture.
- Very slow performance — good for testing, debugging, or simulation.
- QEMU offloads CPU execution to hardware via KVM (Kernel-based Virtual Machine).
- Performance close to native (up to 10× faster).
- Requires CPU virtualization support:
| Vendor | Feature | Description |
|---|---|---|
| Intel | VT-x (vmx) |
Hardware virtualization for Intel CPUs |
| AMD | AMD-V (svm) |
Hardware virtualization for AMD CPUs |
qemu-img create -f qcow2 win11.img 30Gqcow2format supports snapshots, compression, and dynamic sizing.
qemu-system-x86_64 \
-enable-kvm \
-cpu host \
-m 6G \
-smp 4 \
-hda win11.img \
-boot d \
-cdrom windows_11.isoNotes:
-enable-kvm→ Use hardware acceleration.-boot d→ Boot from CD-ROM for OS installation.-smp 4→ Allocate 4 CPU cores.-m 6G→ Allocate 6 GB RAM.
qemu-system-x86_64 \
-enable-kvm \
-cpu host \
-m 6G \
-smp 4 \
-device qxl-vga \
-hda win11.img \
-boot c \
-spice port=5905,addr=127.0.0.1,disable-ticketing=on \
-device virtio-serial-pci \
-chardev spicevmc,id=vdagent,debug=0,name=vdagent \
-device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \
-display noneWhat this does:
- Uses QXL video driver for better graphics performance.
- Enables SPICE remote desktop for high-speed display and clipboard sharing.
- Adds SPICE agent for mouse sync, clipboard, and resolution change.
sudo apt install virt-viewer
remote-viewer spice://127.0.0.1:5905Install SPICE Guest Tools: https://www.spice-space.org/download.html
| Option | Description |
|---|---|
-hda win10.img |
Simple legacy method to attach a disk |
-drive file=win10.img,format=qcow2 |
Recommended modern syntax (supports snapshots) |
Use -drive syntax — it’s more flexible and supports multiple disks easily.
You can emulate or expose specific CPU models:
qemu-system-x86_64 -enable-kvm -cpu Haswell -m 6G -smp 4 -hda win11.img -boot c-cpu EPYC→ emulate AMD CPU-cpu Haswell→ emulate Intel CPU-cpu host→ pass host CPU features directly- You can even emulate 32-bit CPUs on a 64-bit host.
Check all options:
qemu-system-x86_64 -cpu help| Mode | Description | Visibility | Example |
|---|---|---|---|
| user | Built-in NAT mode (no root needed) | VM behind NAT | -nic user,model=virtio-net-pci |
| bridge | Connects VM to host LAN (same network) | Visible on LAN | -nic bridge,br=br0,model=virtio-net-pci |
| tap | Direct virtual Ethernet interface | Fastest | -netdev tap,id=n0,ifname=tap0 -device virtio-net-pci,netdev=n0 |
| Device | Layer | Use Case |
|---|---|---|
| TUN | Layer 3 (IP) | Used by VPNs for IP tunneling |
| TAP | Layer 2 (Ethernet) | Used for VMs, bridges, and containers |
Think of:
- TAP → virtual Ethernet cable
- TUN → virtual IP pipe
Create a TAP device manually:
sudo ip tuntap add dev tap0 mode tap user $USERExample:
-device virtio-net-pci,netdev=n0 -netdev user,id=n0,hostfwd=tcp::2222-:22Maps:
- Host port 2222 → Guest port 22
Then you can SSH into the VM:
ssh -p 2222 [email protected]- QEMU without KVM → universal but slow (pure software).
- QEMU with KVM → near-native performance (hardware-accelerated).
- QXL + SPICE → better graphics, mouse sync, clipboard sharing.
- qcow2 → supports snapshots and compression.
- VirtIO → faster disk and network drivers.
- Create and run a VM → with just 4 commands