From 489d488547b8ebf9b7da059fdc11d01bdce61b3f Mon Sep 17 00:00:00 2001 From: Colin Patrick Mccabe Date: Thu, 7 Jun 2012 14:06:50 -0700 Subject: [PATCH] Add vm-common.sh, remove vbridge.sh Using -net socket is much more convenient than setting up the bridge and tap interfaces. Signed-off-by: Colin McCabe --- vbridge.sh | 38 -------------------------------------- vm-common.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 38 deletions(-) delete mode 100755 vbridge.sh create mode 100644 vm-common.sh diff --git a/vbridge.sh b/vbridge.sh deleted file mode 100755 index f59ee33..0000000 --- a/vbridge.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash -xe - -# -# Create tun and bridge interfaces for qemu. -# - -TAP=tap0 -BR=br0 - -die() { - echo $@ - exit 1 -} - -up() { - /sbin/tunctl -b -t $TAP - /sbin/ifconfig $TAP up - /sbin/brctl addbr $BR - /sbin/brctl addif $BR $TAP - /sbin/ifconfig $BR 192.168.123.1 netmask 255.255.255.0 - /sbin/ifconfig $BR up -} - -down() { - /sbin/ifconfig $BR down - /sbin/ifconfig $TAP down - /sbin/brctl delbr $BR - /sbin/tunctl -d $TAP -} - -ARG="x$1" -if [ $ARG == "xup" ]; then - up -elif [ $ARG == "xdown" ]; then - down -else - die "must specify either up or down." -fi diff --git a/vm-common.sh b/vm-common.sh new file mode 100644 index 0000000..d702b80 --- /dev/null +++ b/vm-common.sh @@ -0,0 +1,40 @@ +die() { + echo $@ + exit 1 +} + +run_vm() { + ID=$1 + shift + NARGS=$@ + ADMIN_PORT=`expr 2232 + $ID` + MID_BYTE=`printf "%02X" $ID` + MAC_ADDR="F0:DE:$MID_BYTE:58:B2:69" + /sbin/modprobe kvm kvm_intel kvm_amd || die "modprobe failed" + echo "running qemu with ssh port $ADMIN_PORT, vnc ID $ID" + VNC_EFFECTIVE_PORT=`expr 5900 + $ID` + echo "see output with vncviewer 127.0.0.1:$VNC_EFFECTIVE_PORT" + qemu-kvm \ + -daemonize \ + -vga std \ + -redir tcp:$ADMIN_PORT::22 \ + -vnc 127.0.0.1:$ID \ + -net nic,vlan=0,model=e1000 \ + -net user,vlan=0,net=10.0.2.0/8,host=10.0.2.2,hostname=vm$ID \ + -net nic,vlan=1,macaddr=$MAC_ADDR,model=e1000 \ + -net socket,vlan=1,mcast=230.0.0.1:1234 \ + $NARGS || die "qemu invocation failed." +} + +# Tap stuff (currently unused): +#-net nic,vlan=0,macaddr=$MAC_ADDR,model=e1000 \ +#-net tap,vlan=0,ifname=tap0,downscript=no,script=no \ + +# To add to /etc/hosts in VMs: +# 192.168.123.10 vm0.local vm0 +# 192.168.123.11 vm1.local vm1 +# 192.168.123.12 vm2.local vm2 +# 192.168.123.13 vm3.local vm3 +# 192.168.123.14 vm4.local vm4 +# 192.168.123.15 vm5.local vm5 +# 192.168.123.16 vm6.local vm6 -- 1.6.6.rc1.39.g9a42