分类: LINUX
2010-08-26 16:40:25
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.
Starting from version 0.10.0 (0.11 is still considered unstable), Qemu can be built with GCC 4.
If you are installing Qemu <= 0.9.1, install the latest version of GCC 3:
Once the emerge finished, you can install qemu with emerge. The ebuild will automatically switch gcc temporarily.
Starting from Qemu 0.10.3, the following packages:
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="i386 ppc ppc64 x86_64"
QEMU_USER_TARGETS="arm i386 x86_64"
If you want to have any graphical output, you should use the sdl library by adding its flag to build :
app-emulation/qemu-softmmu sdl
You can use the kqemu kernel module accelerator by doing the following:
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:
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:
Linux Kernel Configuration: Enable TUN/TAP support |
Device Drivers ---> |
Load TUN/TAP module:
Setting up a bridge on the host machine for two guests (Example)
Create a tun device as follows (2.4 kernel)
Manually set up IP information for br0
Static IP:
bridge_br0="eth0"
config_eth0=( "null" )
config_br0=( "192.168.0.1/24" )
RC_NEED_br0="net.eth0"
brctl_br0=( "setfd 0" "sethello 1" "stp off" )
routes_br0=( "default gw 192.168.0.254" )
Dynamic IP:
bridge_br0="eth0"
config_eth0=( "null" )
config_br0=( "dhcp" )
dhcpcd_br0="-t 10"
RC_NEED_br0="net.eth0"
brctl_br0=( "setfd 0" "sethello 1" "stp off" )
Add net.br0 to the default runlevel
Add this iptables rule to your firewall
Restart the network
Create a guest-ifup script
#!/bin/bash
#
# Argument $1 will be the name of the interface (tun0, tun1, ...)
if test $(/sbin/ifconfig | grep -c $1) -gt 0; then
/sbin/brctl delif br0 $1
ifconfig $1 down
fi
/sbin/ifconfig $1 0.0.0.0 promisc up
/sbin/brctl addif br0 $1
/usr/bin/tunctl -u root -t $1
exit 0
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:
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)
%vmnet ALL=(ALL) NOPASSWD: /sbin/ifconfig, /sbin/brctl, /usr/bin/tunctl
Now change the guest-ifup script to call the commands using sudo.
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:
KERNEL=="tun", NAME="net/%k", MODE="0660", OPTIONS+="ignore_remove"
Change that rule so that it sets the group of the tun device to be that of our new group:
KERNEL=="tun", NAME="net/%k", GROUP="vmnet", MODE="0660", OPTIONS+="ignore_remove"
The change won't take effect until the next boot, so in the meantime you can do
to get things working immediately.