Monday, December 13, 2010

Running debian-mips in Qemu (Two NICs)

Note: The host system is Ubuntu and guest is Debian (mips) in the example below.

In this example, eth0 of the host and guest are through the one NIC while eth1 of host and guest are through other NIC. There is a DHCP server running somewhere that gives IP to eth0 of host as well as eth0 of the guest. I run a DHCP server on eth1 of the host to give IP to eth1 of the guest.

To install Debian in QEMU, use this (creating the qcow file is being left as an exercise to the reader, if you can't do even that, don't bother reading further):
wget http://ftp.debian.org/debian/dists/Debian5.0.6/main/installer-mips/current/images/malta/netboot/initrd.gz
wget http://ftp.debian.org/debian/dists/Debian5.0.6/main/installer-mips/current/images/malta/netboot/vmlinux-2.6.26-2-4kc-malta

qemu-system-mips -M malta -kernel vmlinux-2.6.26-2-4kc-malta -initrd initrd.gz -hda Linux.qcow -append root=/dev/ram c                                            onsole=ttyS0 -nographic
I tried with several other machine types beside Malta but they did not work. QEMU just hung there.

The  interfaces file on host (/etc/network/interfaces) needs to be configured to use two bridged interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo  eth1 br1 br0 eth0
iface lo inet loopback
#iface eth0 inet dhcp

iface br0 inet dhcp
        bridge_ports eth0
        bridge_maxwait 0

iface br1 inet static
        bridge_ports eth1
        bridge_maxwait 0
        address 192.168.41.4
        netmask 255.255.255.0
        broadcast 192.168.41.255
        network 192.168.41.0


iface eth1 inet static
        address 0.0.0.0

iface eth0 inet static
        address 0.0.0.0

QEMU if up file (/etc/qemu-ifup) looks like this:
#!/bin/sh
echo "Executing /etc/qemu-ifup" Args= $*
echo "Bringing up $1 for bridged mode..."
sudo /sbin/ifconfig $1 0.0.0.0 promisc up


if [ $1 = "tap0" ]; then
echo "Adding $1 to br0..."
sudo /usr/sbin/brctl addif br0 $1
fi


if [ $1 = "tap1" ]; then
echo "Adding $1 to br1..."
sudo /usr/sbin/brctl addif br1 $1
fi


sleep 2


Note: Make sure that brctl shows this information:
$brctl show
bridge name bridge id STP enabled interfaces
br0 8000.000c29b09c78 no eth0 tap0
br1 8000.000c29b09c82 no eth1 tap1

if not then use this command to add tap interfaces:
brctl addif br0 tap0
brctl addif br1 tap1

To run use this:
qemu-system-mips -m 256 -M malta -kernel vmlinux-2.6.26-2-4kc-malta -hda Linux.qcow -append "root=/dev/hda1 console=ttyS0" -nographic -net nic,macaddr=00:16:3e:00:00:01,vlan=0 -net tap,vlan=0 -net nic,macaddr=00:16:3e:00:00:02,vlan=1 -net tap,vlan=1

Tip: If you encounter dns related issues, its easier to use opendns as the name server. You /etc/resolve.conf can look like this  to use opendns as the name server:
domain localdomain
search localdomain
nameserver 208.67.222.222