qemu

virtualizationLinux/Unix
The qemu command is one of the most frequently used commands in Linux/Unix-like operating systems. qemu Quick Emulator, a generic machine emulator and virtualizer

Quick Reference

Command Name:

qemu

Category:

virtualization

Platform:

Linux/Unix

Basic Usage:

qemu [options] [arguments]

Common Use Cases

    Syntax

    qemu-system-[arch] [options] [disk_image]

    Options

    Option Description
    -hda file Use file as the hard disk image
    -cdrom file Use file as the CD-ROM image
    -boot [a|c|d|n] Boot from floppy (a), hard disk (c), CD-ROM (d), or network (n)
    -m size Set the amount of RAM in megabytes
    -smp n Set the number of CPU cores
    -enable-kvm Enable KVM hardware virtualization
    -vga type Select video card type (std, cirrus, vmware, qxl, etc.)
    -netdev type,id=id Configure a network backend
    -device driver,netdev=id Configure a network device
    -nographic Disable graphical output
    -snapshot Write to temporary files instead of disk image files
    -monitor dev Redirect monitor to a character device
    -cpu model Set CPU model
    -usb Enable USB driver
    -spice option Enable SPICE remote desktop protocol

    Examples

    How to Use These Examples

    The examples below show common ways to use the qemu command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    qemu-system-x86_64 -hda disk.img -m 2048
    Boot a virtual machine with disk.img as the hard drive and 2048MB of RAM.
    qemu-system-x86_64 -cdrom ubuntu.iso -boot d -m 4096
    Boot from an Ubuntu ISO image with 4GB of RAM.
    # Advanced Examples Advanced
    qemu-system-x86_64 -hda disk.img -m 4096 -smp 4 -vga std Run a VM with 4GB RAM, 4 CPU cores, and standard VGA graphics. qemu-system-x86_64 -hda disk.img -m 2048 -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::2222-:22 Set up port forwarding from host port 2222 to guest port 22 (for SSH). qemu-system-x86_64 -hda disk.img -hdb data.img -m 2048 Use multiple disk images (disk.img as primary, data.img as secondary). qemu-system-x86_64 -enable-kvm -hda disk.img -m 4096 Enable KVM hardware acceleration for better performance. qemu-img create -f qcow2 new-disk.qcow2 20G Create a new qcow2 format disk image of 20GB size. qemu-img convert -f raw -O qcow2 disk.raw disk.qcow2 Convert a raw disk image to qcow2 format. qemu-img resize disk.qcow2 +10G Resize a disk image, adding 10GB to its size. qemu-img snapshot -l disk.qcow2 List snapshots in a qcow2 disk image.

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    QEMU (Quick Emulator) is a powerful open-source machine emulator and virtualizer that can run operating systems and programs for one machine on a different machine. It's capable of emulating various hardware architectures, including x86, ARM, MIPS, PowerPC, SPARC, and many others. QEMU operates in two primary modes: 1. Full System Emulation: QEMU emulates a full computer system, including processors and peripherals. This allows running complete operating systems for different architectures. 2. User Mode Emulation: QEMU can run individual programs compiled for a different instruction set architecture than the host machine. Key features of QEMU include: - Cross-platform compatibility: Run programs from one architecture on another - Hardware acceleration via KVM (Kernel-based Virtual Machine) on Linux hosts - Support for various virtual disk formats (raw, qcow2, vmdk, vdi, etc.) - Snapshot capability for system state preservation - Live migration of virtual machines - Device emulation for various network cards, graphics adapters, storage controllers, etc. - Extensible through a plugin architecture - Integration with libvirt and other virtualization management tools QEMU is particularly useful for: - Development and testing of software for different architectures - Operating system development and debugging - Creating isolated environments for software testing - Legacy system emulation for running older software - Server virtualization in environments where hardware acceleration is not available - Embedded system development and testing While QEMU provides excellent emulation capabilities, when used as a virtualizer (with KVM on Linux), it can approach near-native performance, making it suitable for production virtualization workloads. QEMU is a foundational technology that powers many other virtualization solutions. For example, it's used by the Android Emulator for mobile app development, and it's a core component of many cloud computing infrastructures. The command-line interface for QEMU can be complex due to its many options and capabilities. Typically, users interact with QEMU through higher-level tools like virt-manager, libvirt, or specialized wrappers that simplify the configuration process.

    Related Commands

    These commands are frequently used alongside qemu or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the qemu command works in different scenarios.

    $ qemu
    View All Commands