QEMU is a machine emulator. It comes in a number of different flavors, each of which can emulate a processor architecture and a number of boards built using that architecture. For example, we have the following:
- qemu-system-arm: ARM
- qemu-system-mips: MIPS
- qemu-system-ppc: PowerPC
- qemu-system-x86: x86 and x86_64
For each architecture, QEMU emulates a range of hardware, which you can see by using the option—machine help. Each machine emulates most of the hardware that would normally be found on that board. There are options to link hardware to local resources, such as using a local file for the emulated disk drive. Here is a concrete example:
$ qemu-system-arm -machine vexpress-a9 -m 256M -drive
file=rootfs.ext4,sd -net nic -net use -kernel zImage -dtb vexpress-
v2p-ca9.dtb -append "console=ttyAMA0,115200 root=/dev/mmcblk0" -
serial stdio -net nic,model=lan9118 -net tap,ifname=tap0
The options used in the preceding command line are:
- -machine vexpress-a9: Creates an emulation of an ARM Versatile Express development board with a Cortex A-9 processor
- -m 256M: Populates it with 256 MiB of RAM
- -drive file=rootfs.ext4,sd: Connects the SD interface to the local file rootfs.ext4 (which contains a filesystem image)
- -kernel zImage: Loads the Linux kernel from the local file named zImage
- -dtb vexpress-v2p-ca9.dtb: Loads the device tree from the local file vexpress-v2p-ca9.dtb
- -append "...": Supplies this string as the kernel command-line
- -serial stdio: Connects the serial port to the terminal that launched QEMU, usually so that you can log on to the emulated machine via the serial console
- -net nic,model=lan9118: Creates a network interface
- -net tap,ifname=tap0: Connects the network interface to the virtual network interface tap0
To configure the host side of the network, you need the tunctl command from the User Mode Linux (UML) project; on Debian and Ubuntu, the package is named uml-utilites:
$ sudo tunctl -u $(whoami) -t tap0
This creates a network interface named tap0 which is connected to the network controller in the emulated QEMU machine. You configure tap0 in exactly the same way as any other interface.
All of these options are described in detail in the following chapters. I will be using Versatile Express for most of my examples, but it should be easy to use a different machine or architecture.