--- /dev/null
+#!/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