2010年7月4日星期日

Setup QEMU under Ubuntu 8.04

1. Install QEMU package

2. Setup network bridge

2.1 install uml-utilities and bridge-utils package
2.2 setup bridge configuration:

In /etc/network/interfaces file, add the following lines:

iface br0 inet dhcp
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off

auto br0

2.3 Disable Ubuntu roaming function for eth0

In the terminal, type network-admin. And then set eth0 to use "Static IP address".
Assign IP, subnet mask and gateway to eth0. After that, you should see the setting in /etc/network/interfaces file.
For example:

iface eth0 inet static
address 192.168.1.100
netmask 255.255.0.0
gateway 192.168.1.254

auto eth0

Then edit /etc/network/interfaces file to comment the line "auto eth0":

#auto eth0

2.4
Since we want to add default gateway to the bridge interface,
we can create a shell script in the /etc/network/if-up.d folder:

#! /bin/sh

#Not for loopback!
if [ "$IFACE" != "lo" ]; then
/sbin/route add -host 192.168.251.1 gw 192.168.252.254 dev $IFACE
fi

In the above script, route will be ran for each interface when network service is started.
You can adjust it to fit your situation.

3. Prepare qemu script for network bridge

In /etc/qemu-ifup file, add the following lines:

echo "Executing /etc/qemu-ifup"
echo "Bringing up $1 for bridged mode..."
sudo /sbin/ifconfig $1 0.0.0.0 promisc up
echo "Adding $1 to br0..."
sudo /usr/sbin/brctl addif br0 $1
sleep 2

4. Restart network service

sudo /etc/init.d/network restart

Normally, there is no IP for eth0 and br0 has a IP address.

5. Prepare system disk image

6. run Qemu

use qemu command to start the simulation. For example:

sudo qemu -hda sysimage.img -net nic,model=rtl8139 -net tap -serial /dev/ttyS0

-hda sysimage.img = the disk image (sysimage.img) is mapped to hda
-net,model=rtl8139 = use rtl8139 network card for the simulator (input)
-net tap = use TAP/TUN dirver (output), this dirver is already connected to the network bridge
-serial /dev/ttyS0 = enable serial port emulation and map guest's serial port to the host's port (/dev/ttyS0)

7. You can use "ping" command to check the network connection.

If the guest Linux system cannot detect the serial port, we can use "modprobe 8250" command and then you see the following output:

Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16450

That means qemu will use 16450 chip set to emulate serial port for the guest linux system.

沒有留言: