QEmu

Qemu allows the emulation of multiple architectures (ARM systems, IA-32 (x86) PCs, AMD64 PCs, MIPS R4000, Sun's SPARC sun3, and PowerPC (PReP and Power Macintosh)) on your computer. You can use it to install Windows or many other OSes inside your Linux-based environment.

Ebuild starting from version 0.10.3
Starting from Qemu 0.10.3, the following packages:


 * app-emulation/qemu
 * app-emulation/qemu-softmmu
 * app-emulation/qemu-user

have been unified into a single app-emulation/qemu package. The following documentation does not yet reflect that change, so make sure you apply all the USE flags to the correct package.

Two new USE_EXPAND variables are used, and they include all possible flags by default. Add them in your Portage configuration file to tweak them:


 * QEMU_SOFTMMU_TARGETS defines the targets for the full system emulation. This mode allows you to emulate a complete machine and to install a different OS on another architecture.
 * QEMU_USER_TARGETS defines the targets for the user space emulation. This mode allows you, for instance to run a program compiled for Linux ARM in your Linux x86_64 environment.

Installation
If you want to have any graphical output, you should use the sdl library by adding its flag to build :

Kernel module accelerator
You can use the kqemu kernel module accelerator by doing the following:


 * Add kqemu after app-emulation/qemu sdl in ;
 * Emerge kqemu using GCC 3
 * Load the kernel module using the following command:

To use kqemu with your user account, you must add it to the qemu group :

For a 64 bit architecture, you must use the following command in order to get Qemu to work:

Using the emulated OS with ethernet and a valid IP
Qemu provides basic networking functionality by default (-net user), but this does not work with things that need root access, such as ping. To use your host's ethernet connection over the emulated OS you'll need to use TUN/TAP.

You must enable TUN/TAP in your kernel by using the following configuration option:

Load TUN/TAP module:

Making a bridge
Setting up a bridge on the host machine for two guests (Example)

Create a tun device as follows (2.4 kernel)

Create br0

Manually set up IP information for br0

Static IP:

Dynamic IP:

Add net.br0 to the default runlevel

Add this iptables rule to your firewall

Restart the network

Using TUN/TAP interface as the root user
Create a guest-ifup script

Alternative TUN/TAP using Gentoo's /etc/conf.d/net
Configuration of interface can be offloaded to Gentoo's universal network configuration scripts.

Don't forget to create net.vm0 symlink to net.lo.

Call your machine like that:

Using TUN/TAP interface as a normal user
The above example creates the TUN/TAP interface as the root user. If you want to run qemu as a normal user then the tap interface needs to be owned by a normal user. To achieve this you need to:


 * Run tunctl -u to create a tap device owned by
 * The user running qemu needs to have read/write permissions to /dev/net/tun

Creating a group to simplify things
To simplify the process of running qemu as a user we'll create a group vmnet that will have permissions to create the tap network interface, configure the interface and have access to /dev/net/tun.

Then add all the users that should be able to run qemu to the group

Finally we'll allow the group to call the specific commands without passwords (assuming we'll use sudo for this)

Now change the guest-ifup script to call the commands using sudo.

Setting group permissions on /dev/net/tun
Now to set read/write permission for the group vmnet on /dev/net/tun. The permissions on /dev/net/tun are controlled by a rule in /etc/udev/rules.d/50-udev.rules that looks like this:

Change that rule so that it sets the group of the tun device to be that of our new group:

The change won't take effect until the next boot, so in the meantime you can do

to get things working immediately.

GUI to setup vm (optional)
This step is optional! If you prefer a gui to setup the virtual machine you can install aqemu.

Install Windows XP
Use the location of your cd drive.

This starts QEmu using the time from the linux box, windows_xp.img as the hard disk file, /dev/cdrom as the CD, 384 MB of memory (a good minimum for XP) and will boot from the CD.

You can also install from an iso image file.