On Fri, Oct 05, 2007 at 10:54:17AM +0200, Michael wrote:
> Hi,
>
> I've tried setting up multiple qemu hosts on OpenBSD 4.1 but having
> problems setting up the networking. The first qemu instance works just
> fine with -net nic -net tap but I never were able to get the network
> working with a second or third qemu instance.
>
> The server got a main IP and a small subnet and I would love to either
> set it up in routing mode or bridge the qemu hosts directly to the main
> interface.
>
> I've tried (almost) everything I can imagine and searched the web found
> couldn't find some helpfull information. Maybe someone got a working
> setup and could give me some hints?
>
I use this silly script plus a small C program to open up the the tun
devices and pass them to qemu (makes it possible for me to run qemu
without root privs).
The main trick is getmac() which generates "hopefully" unique mac
addresses per port.
--
:wq Claudio
#!/bin/sh
#
# stupid script to start multiple qemus on a single box
SUDO=/usr/bin/sudo
USER=cjeker
# qemu args
IMAGE=virt.hd
MEMORY=64
FLAGS="-snapshot -nographic"
NICFLAGS="-net nic,vlan=\$id,macaddr=\$mac -net tap,vlan=\$id,fd=\$fd"
usage() {
echo "usage: $0 [-n] [-i image] [-f floppy.fs] instance" 1>&2
exit 2
}
getmac() {
mac="00:bd:`printf %02x $(($RANDOM % 256))`:"
mac="$mac`printf %02x $(($RANDOM % 256))`:"
mac="$mac`printf %02x $(($1 % 256))`:`printf %02x $(($2 % 255 + 1))`"
}
start() {
for id in 0 1 2 3; do
fd=$(($id + 3))
tun=tun$(($1 * 10 + $id))
getmac $1 id
eval "nics=\"$nics $NICFLAGS\""
fds="$fds fdpass -n $fd -f /dev/$tun"
# make sure a tun interface is available
ifconfig $tun > /dev/null 2>&1
if [ $? -ne 0 ]; then
${SUDO} ifconfig $tun link0
fi
done
${SUDO} $fds -u cjeker qemu -m ${MEMORY} ${FLAGS} $nics ${IMAGE}
}
args=`getopt f:i:n $*`
if [ $? -ne 0 ]; then
usage
fi
set -- $args
while [ $# -gt 0 ]; do
case "$1" in
-f) shift
FLAGS="-fda $1 -boot a -monitor stdio"
;;
-i) shift
IMAGE="$1"
;;
-n) FLAGS="-nographic"
echo "DISABLING SNAPSHOT MODE"
;;
--) shift;
break
;;
esac
shift
done
if [ $# -ne 1 ]; then
usage
fi
start $1