From 289c80c35531673523635032528c07d4b90e6233 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 3 Mar 2015 11:46:13 +0100 Subject: [PATCH] add vmbr script to launch QEMU with networking on lxcbr0 --- vmbr | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 vmbr diff --git a/vmbr b/vmbr new file mode 100755 index 0000000..292f630 --- /dev/null +++ b/vmbr @@ -0,0 +1,25 @@ +#!/bin/sh +set -e +image="$1" +bridge=lxcbr0 +[ -e "$image" ] || { echo "Usage: $0 [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 -- 2.39.5