From: Martin Pitt Date: Tue, 3 Mar 2015 10:46:13 +0000 (+0100) Subject: add vmbr script to launch QEMU with networking on lxcbr0 X-Git-Url: https://piware.de/gitweb/?a=commitdiff_plain;h=289c80c35531673523635032528c07d4b90e6233;p=bin.git add vmbr script to launch QEMU with networking on lxcbr0 --- 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