]> piware.de Git - bin.git/commitdiff
add vmbr script to launch QEMU with networking on lxcbr0
authorMartin Pitt <martin.pitt@ubuntu.com>
Tue, 3 Mar 2015 10:46:13 +0000 (11:46 +0100)
committerMartin Pitt <martin.pitt@ubuntu.com>
Tue, 3 Mar 2015 10:46:13 +0000 (11:46 +0100)
vmbr [new file with mode: 0755]

diff --git a/vmbr b/vmbr
new file mode 100755 (executable)
index 0000000..292f630
--- /dev/null
+++ b/vmbr
@@ -0,0 +1,25 @@
+#!/bin/sh
+set -e
+image="$1"
+bridge=lxcbr0
+[ -e "$image" ] || { echo "Usage: $0 <image> [options...]" >&2; exit 1; }
+shift
+
+# generate tap setup script
+script=`mktemp --tmpdir qemu.tap.script.XXXXXX`
+/bin/echo -e '#!/bin/sh\nip link set "$1" up\nip link set "$1" master' $bridge > $script
+chmod 755 $script
+
+# find a free MAC adddress
+i=0
+MAC_PREFIX=52:54:00:12:34:
+while [ $i -lt 255 ]; do
+    MAC=$(printf '52:54:00:12:34:%02x' $i)
+    arp -ani $bridge | grep -q $MAC || break
+    i=$((i+1))
+done
+echo "MAC address: $MAC"
+
+sudo qemu-system-x86_64 -enable-kvm -m 2048 -drive file="$image",if=virtio \
+    -net tap,script=$script,downscript=no -net nic,model=virtio,macaddr=$MAC "$@"
+rm $script