Introduction to qemu

qemu is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V).

This package is known to build and work properly using an LFS-7.4 platform.

Package Information

Qemu Dependencies


GLib-2.36.4, Python-2.7.5, SDL-1.2.15, and X Window System


ALSA-1.0.27, attr-2.4.47, Check-0.9.10, cURL-7.32.0, EsounD-0.2.41, MesaLib-9.2.0, and Cyrus SASL-2.1.26. Note that this optional dependencies list is not comprehensive. See the output of ./configure --help for a more complete list.

User Notes: http://wiki.linuxfromscratch.org/blfs/wiki/qemu

KVM Prerequsites

Before building qemu, check to see if your processor supports Virtualization Technology (VT):

egrep '^flags.*(vmx|svm)' /proc/cpuinfo

If you get any output, you have VT technology (vmx for Intel processors and svm for AMD processors). You then need to go into your system BIOS and ensure it is enabled. After enabing, reboot back to your LFS instance.

Kernel Configuration

Enable the following options in the kernel configuration and recompile the kernel if necessary:

Virtualization: Y
  Kernel-based Virtual Machine (KVM) support: M or Y
  KVM for Intel processors support:           M or Y
  KVM for AMD processors support:             M or Y

The Intel or AMD settings are not both required, but the one matching your system processor is required.

For networking, check that the settings CONFIG_BRIDGE, CONFIG_STP, CONFIG_TUN are enabled and bridge-utils-1.5 is installed.

Installation of qemu

If xorg is not installed in /usr, then the linker needs to be told where it is. For example:

export LIBRARY_PATH=/opt/xorg/lib

Install qemu by running the following commands:

./configure --prefix=/usr                \
            --sysconfdir=/etc            \
            --target-list=x86_64-softmmu &&

To run the built in tests, run make V=1 check.

Now, as the root user:

make install


For convenience you may want to create a symbolic link to run qemu-system-x86_64:

ln -sv qemu-system-x86_64 /usr/bin/qemu

Command Explanations

--target-list=x86_64-softmmu: This option limits the build target to the x86_64 architecture. For other hardware emulation see the --target-list list in configure's help output. Omitting this option will build all architectures.

Configuring qemu

To generate an image, run:

qemu-img create -f qcow2 vdisk.img 10G

Adjust the virtual disk size and image filename as desired. The actual size of the file will be less than specified, but will expand as it is used.



The following instructions assume you have created the optional symbolic link, qemu. Additionally, you must run qemu from an X-Windows based terminal.

To install an operating system, download an iso of your choice or use a pre-intalled cdrom device. For the purposes of this example, use Fedora 16 that is downloaded as Fedora-16-x86_64-Live-LXDE.iso in the current directory. Run the following:

qemu -enable-kvm -hda vdisk.img            \
     -cdrom Fedora-16-x86_64-Live-LXDE.iso \
     -boot d                               \
     -m 384

Follow the normal installation procedures for the chosen distribution. The -boot option specifies the boot order of drives as a string of drive letters. Valid drive letters are: a, b (floppy 1 and 2), c (first hard disk), d (first CD-ROM). The -m option is the amount of memory to use for the virtual machine. If you have sufficient memory (2G or more), 1G is a reasonable value. For computers with 512MB of RAM it's safe to use -m 192, or even -m 128 (the default). The -enable-kvm option allows for hardware acceleeration. Without this switch, the emulation is relatively slow.

To run the newly installed operating system, run:

qemu -enable-kvm vdisk.img -m 384

To add networking to the instance add "-net nic -net user" to the command above. qemu provides a DHCP server for the VM and, depending on the client system, sets up networking though the host.

One problem with the above networking solution is that it does not provide the ability to connect with the local network. To do that, there are several additional steps that need to be done, all as the root user:

  • Set up bridging with bridge-utils-1.5.

  • Allow the host system to forward IP packets.

    sysctl -w net.ipv4.ip_forward=1

    To make this permanent, add the command to /etc/syssysctl.conf:

    cat >> /etc/sysctl.conf << EOF
  • Create scripts for qemu to attach the client network device, usually visible as tap0, to the host bridge.

    cat > /etc/qemu-ifup << EOF
    if [ -n "\$1" ]; then
      # Add new tap0 interface to bridge
      /sbin/ip link set \$1 up
      sleep 0.5s
      /usr/sbin/brctl addif \$switch \$1
      echo "Error: no interface specified"
      exit 1
    exit 0
    chmod +x /etc/qemu-ifup
    cat > /etc/qemu-ifdown << EOF
    if [ -n "\$1" ]; then
      # Remove tap0 interface from bridge
      /usr/sbin/brctl delif \$switch \$1
      echo "Error: no interface specified"
      exit 1
    exit 0
    chmod +x /etc/qemu-ifdown


The backslashes in the abouve script are for convenience for cut/paste operations. The backslashes should not appear in the final scripts.

  • Start qemu with "-net nic -net tap" options.

  • If a connection, such as ssh, from the local network to the client VM is desired, the client should probably be configured with a static IP address.


Installed Program: qemu-ga, qemu-img, qemu-io, qemu-nbd, qemu-system-x86_64
Installed Libraries: None
Installed Directories: /etc/qemu, /usr/share/qemu, /usr/share/doc/qemu

Short Description


implements support for QMP (QEMU Monitor Protocol) commands and events that terminate and originate respectively within the guest using an agent built as part of QEMU.


provides commands to manage QEMU disk images.


is a diagnostic and manipulation program for (virtual) memory media. It is still at an early stage of development.


exports Qemu disk images using the QEMU Disk Network Block Device (NBD) protocol.


is the QEMU PC System emulator.

Last updated on 2013-09-05 10:04:34 -0700