LinuxCommandLibrary

qemu

Emulate different computer systems

TLDR

Boot from image emulating i386 architecture

$ qemu-system-i386 -hda [image_name.img]
copy

Boot from image emulating x64 architecture
$ qemu-system-x86_64 -hda [image_name.img]
copy

Boot QEMU instance with a live ISO image
$ qemu-system-i386 -hda [image_name.img] -cdrom [os_image.iso] -boot d
copy

Specify amount of RAM for instance
$ qemu-system-i386 -m 256 -hda [image_name.img] -cdrom [os-image.iso] -boot d
copy

Boot from physical device (e.g. from USB to test bootable medium)
$ qemu-system-i386 -hda [/dev/storage_device]
copy

SYNOPSIS

qemu-system-[arch] [options] [disk_image]
Example: qemu-system-x86_64 -m 2G -smp 2 -drive file=./my_vm.qcow2,if=virtio -enable-kvm

PARAMETERS

-m <size>
    Sets the RAM size for the virtual machine (e.g., 512M, 2G).

-cpu <model>
    Specifies the CPU model for the guest (e.g., host, kvm64, qemu64).

-smp <cpus>
    Configures the number of virtual CPUs and their topology (e.g., 2, cores=2,threads=1).

-drive <options>
    Defines a virtual disk drive, specifying file, interface, format (e.g., file=disk.img,if=virtio,format=qcow2).

-netdev <options>
    Configures a network backend device (e.g., user,id=net0; tap,id=net1,ifname=tap0).

-device <dev_type>
    Adds a virtual device to the guest, such as a network card or USB controller.

-M <machine>
    Selects the machine type or chipset architecture (e.g., pc, q35, virt).

-enable-kvm
    Enables KVM acceleration for near-native performance on Linux hosts.

-vnc <display>
    Starts a VNC server for remote graphical access (e.g., :0, 127.0.0.1:1).

-display <type>
    Selects the graphical display backend (e.g., sdl, gtk, none, vnc).

-usb
    Enables USB support for the virtual machine.

-cdrom <path>
    Attaches an ISO image as a virtual CD-ROM drive.

-boot <order>
    Sets the boot device order (e.g., d=CD-ROM, c=hard disk, n=network).

DESCRIPTION

QEMU (Quick EMUlator) is a powerful, open-source virtualization and emulation solution. It operates in two primary modes: full system emulation, where it can run an entire operating system (e.g., Linux, Windows) for various architectures (x86, ARM, PowerPC) on a different host architecture, providing cross-architecture virtualization. Its other mode is user-mode emulation, allowing it to run programs compiled for a different CPU architecture directly on the host. When used on a Linux host with a compatible processor, QEMU can leverage the KVM (Kernel-based Virtual Machine) module to achieve near-native performance by directly utilizing the host's CPU virtualization extensions (e.g., Intel VT-x, AMD-V). This makes QEMU a fundamental component for running virtual machines, developing cross-platform software, and security research.

CAVEATS

QEMU's performance without KVM acceleration can be significantly slower, as it relies on pure software emulation. KVM requires specific CPU virtualization extensions (Intel VT-x or AMD-V) enabled in the host's BIOS/UEFI. The command-line interface for QEMU can be complex and verbose, especially for advanced configurations. Exposing network ports or devices without proper security considerations can pose risks to the host system.

OPERATING MODES

QEMU primarily operates in two distinct modes: System Emulation, where it emulates a complete machine (CPU, memory, devices) allowing an operating system to run. This mode supports cross-architecture virtualization (e.g., running an ARM OS on an x86 host). The second mode is User-mode Emulation, which allows QEMU to run single processes compiled for a different CPU architecture directly on the host operating system, without emulating a full system.

HISTORY

QEMU was originally written by Fabrice Bellard and first released in 2003. It quickly gained popularity as an open-source alternative to commercial virtualization solutions. Its integration with the Linux KVM module in 2007 significantly boosted its performance, transforming it into a high-performance virtualizer. QEMU remains under active development by a large community, serving as a core component in many cloud platforms, embedded systems development, and research environments.

SEE ALSO

qemu-img(1), kvm(7), virsh(1), libvirt(3)

Copied to clipboard