summaryrefslogtreecommitdiff
path: root/qemu-start
blob: 323df4b6fd33a9051a0ba373c9a2a757b4c210ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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=${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