QEMU – Overview
QEMU is an emulator and vitualization tool like VMware, KVM, VirtualBox, and Xen did. It emulates hardware, but with more options available. QEMU is available to emulates some hardware architectures, including embedded system. Processor architecture supported by QEMU are: x86, ARM, MIPS, etc.
How it work
QEMU is like any virtualization tools, dividing resource for native OS (the host) and virtual machine (guest). It support virtualization with Xen Hypervisor or Linux KVM modules. With KVM, QEMU can emulate x86, server and embedded PowerPC, and also S390.
As result of resource division, there will be a decreasing in performance both on host and guest system. However, QEMU use dynamic translation to translate machine code of guest to host which makes the performance good enough.
QEMU has two operating mode, which are:
- User Mode Emulation – QEMU can emulate own Linux process which is compiled to a CPU on different CPU.
- Full System Emulation – QEMU emulate whole system, including every resource (suh as processor and peripheral). This mode is useful to do some debugging and code testing on virtual machine. Using QEMU we can run some virtual machines simultaneously on a host (of course we should measure the resource needed).
Running Kernel Image
You can read this article to run a simple Debian for ARM distribution.
Playing with Arguments
Following are arguments that can be used for running a system.
|Specifying amount of RAM||-m x||X is the amount of RAM in MB|
|Use initial ramdisk||-initrd PATHANDFILENAME|
|Add additional disks||-hdb DISK2 -hdc DISK3 -hdd DISK4|
|Add cdrom drive||-cdrom FILE||FILE can be ISO or /dev/cdrom on UNIX|
|Disable graphic||-nographic||Useful for emulate a headless raspi or to route the output directly to terminal|
|Make QEMU exits when the system reboot||-no-reboot|
|Pass argument to kernel||-append “KERNEL OPTIONS”||the kernel OPTIONS will be discussed on next section.|
Following are arguments that can be passed to kernel (the one QEMU boot).
|Specify what partition of disk will be the root partition||root=DEVICE|
|Specify what file to run after kernel is loaded||init=FILE|
|Prevent QEMU from simply freeze when the kernel is panic||panic=x||x is the number of seconds before rebooting. Usefule with the -no-reboot option|
|Specify default console device for the output.||console=DEVICE|
In this section we will discuss about creating a disk image for QEMU. It is recommended to use Linux. The general syntax for creating a disk is:
qemu-img create <FILENAME> <SIZE>
Where <FILENAME> is filename and path if you don’t want to create the image on current directory. The size is written in numerical value followed by size unit in:
- k or K for Kilobyte (1024 byte)
- m or M for Megabyte (1025 kb)
- g or G for Gygabyte (1024m mb)
The created file contain 0 (zero) and mean nothing to system.
To format a disk, we can use UNIX & Linux utility:
- EXT2 => mkfs.ext2 <FILENAME>
- EXT3 => mkfs.ext3 <FILENAME>
We can also mounting <FILENAME> to modify it.linux, qemu, slackware, windows