From 69afa1b8b067231c0daec9bd255763b7a3fc245b Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 26 Jun 2013 19:47:18 +0200 Subject: Add helper for starting QEMU --- qemu-start | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100755 qemu-start (limited to 'qemu-start') diff --git a/qemu-start b/qemu-start new file mode 100755 index 0000000..ff9b62a --- /dev/null +++ b/qemu-start @@ -0,0 +1,88 @@ +#!/bin/sh + +# fails because script is missing: -netdev tap,id=qnet0 +# http://wiki.qemu.org/Documentation/Networking +# https://wiki.archlinux.org/index.php/QEMU#Tap_networking_with_QEMU + +[ $# -lt 1 ] || \ +case $1 in +ISO=*.iso) + ISO="$(echo "$1" | sed 's/^ISO//')" + shift + ;; +*.iso|*.img|*.qcow2|'') + ISO="$1" + shift + ;; +esac + +: ${ISO=/usr/share/virtualbox/ubuntu-12.04.1-desktop-amd64.iso} +case $ISO in +*.iso) + set -- -cdrom "$ISO" "$@" + ;; +*.img|*.qcow2) + set -- -hda "$ISO" "$@" + ;; +'') # do not add cdrom/hdd + ;; +*) + echo "Unknown ISO extension: $ISO" + exit 1 + ;; +esac + +#hp=/dev/hugepages/qemu-$(uuidgen) +hp=/dev/hugepages/qemu +if [ -e "$hp" ]; then + echo "Hugepage already exists, not using it" + hp= +elif grep '^HugePages_Total: *0$' /proc/meminfo -q; then + echo "No HugePages available, not using it" + hp= +elif mkdir "$hp" ;then + echo "Enabling hugepages: $hp" + set -- -mem-path "$hp" "$@" +else + hp= +fi + +[ -z "$hp" ] || trap "rmdir $hp" EXIT + +# ssh -p 2222 localhost +usernet=,hostfwd=tcp:127.0.0.1:2222-:22 + +if [ -z "${NET-x}" ]; then + echo "Not using a network" +elif [ "$NET" = "br" ] && [ -e /sys/class/net/brqemu0 ]; then + echo "Using brqemu0" + set -- "$@" \ + -netdev bridge,br=brqemu0,helper=/usr/lib/qemu/qemu-bridge-helper,id=hn0 \ + -device virtio-net,netdev=hn0 +elif [ "$NET" = "tap" ] && [ -e /sys/class/net/tapqemu0 ]; then + # see http://felipec.wordpress.com/2009/12/27/setting-up-qemu-with-a-nat/ + gw=10.0.4.1 + echo "Using tap - gw $gw" + [ -n "$NONET" ] || \ + ip link show tapqemu0 | grep -q 'state UP' || \ + sudo ifconfig tapqemu0 $gw/24 up + set -- "$@" \ + -netdev tap,id=qnet0,ifname=tapqemu0,script=no \ + -device virtio-net,netdev=qnet0 +elif [ "$NET" = "user" ]; then + echo "Using user" + set -- "$@" \ + -netdev user,id=qnet0$usernet \ + -device virtio-net,netdev=qnet0 +fi + +qemu-system-x86_64 \ + -enable-kvm -m 2G -smp threads=2 \ + -vga std -no-quit -display sdl \ + "$@" + +# I am stupid, I need brctl before doing this. Also, create /etc/qemu/bridge.conf +# possibly helpful for bridging: https://bbs.archlinux.org/viewtopic.php?id=147134 +# -netdev bridge,helper=/usr/lib/qemu/qemu-bridge-helper,id=hn0 \ +# -device virtio-net,netdev=hn0 \ +# note: virtio-net is an alias for virtio-net-pci -- cgit v1.2.1