-
Notifications
You must be signed in to change notification settings - Fork 39
/
qemu-launcher.sh
executable file
·139 lines (118 loc) · 4.54 KB
/
qemu-launcher.sh
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#! /usr/bin/bash
# Author: Jakub Klinkovský (Lahwaacz)
# https://github.com/lahwaacz
function print_usage() {
echo "usage: $0 <VM name>"
}
## Generate name of TAP interface to create
function get_tap_name() {
for (( i=0; i<$tap_limit; i++ )); do
local name="tap$i"
if [[ ! -d "/sys/class/net/$name" ]]; then
echo "$name"
break
fi
done
}
# do not run as root
if [[ $EUID -eq 0 ]]; then
echo "This script is not supposed to be run as root." >&2
exit 1
fi
# parse command line arguments
if [[ -z $1 ]]; then
print_usage
exit 1
else
vm_name="$1"
fi
sudo_args=("-Ap" "Enter your root password (QEMU launcher script)")
username=$(whoami)
tap_limit=10 # maximum number of TAP interfaces created by this script
tap_nic=$(get_tap_name)
br_nic="br0-qemu" # bridge interface name (will be created)
wan_nic="wlan0" # WAN interface name (for NAT)
case "$vm_name" in
btrfs)
sudo "${sudo_args[@]}" qemu-tap-helper.sh "$username" "$tap_nic" "$br_nic" "$wan_nic" up
qemu-system-x86_64 \
-name "$vm_name" \
-monitor stdio \
-enable-kvm -smp 2 -cpu host -m 1024 \
-vga qxl -spice port=5931,disable-ticketing \
-drive file="/home/lahwaacz/virtual_machines/archlinux-btrfs.raw",if=virtio,cache=none -boot once=c \
-net nic,model=virtio,macaddr=$(qemu-mac-hasher.py "$vm_name") -net tap,ifname="$tap_nic",script=no,downscript=no,vhost=on \
-usbdevice tablet
sudo "${sudo_args[@]}" qemu-tap-helper.sh "$username" "$tap_nic" "$br_nic" "$wan_nic" down
;;
virtarch)
sudo "${sudo_args[@]}" qemu-tap-helper.sh "$username" "$tap_nic" "$br_nic" "$wan_nic" up
qemu-system-x86_64 \
-name "$vm_name" \
-monitor stdio \
-enable-kvm -smp 2 -cpu host -m 1024 \
-vga qxl -spice port=5931,disable-ticketing \
-drive file="/home/lahwaacz/virtual_machines/archlinux.raw",if=virtio,cache=none -boot once=c \
-net nic,model=virtio,macaddr=$(qemu-mac-hasher.py "$vm_name") -net tap,ifname="$tap_nic",script=no,downscript=no,vhost=on \
-usbdevice tablet
sudo "${sudo_args[@]}" qemu-tap-helper.sh "$username" "$tap_nic" "$br_nic" "$wan_nic" down
;;
winxp)
sudo "${sudo_args[@]}" qemu-tap-helper.sh "$username" "$tap_nic" "$br_nic" "$wan_nic" up
qemu-system-i386 \
-name "$vm_name" \
-monitor stdio \
-enable-kvm -smp 2 -cpu host -m 1024 \
-vga qxl -spice port=5930,disable-ticketing \
-drive file="/home/lahwaacz/virtual_machines/winxp.raw",if=virtio,cache=none -boot order=c \
-net nic,model=virtio,macaddr=$(qemu-mac-hasher.py "$vm_name") -net tap,ifname="$tap_nic",script=no,downscript=no,vhost=on \
-usbdevice tablet \
-soundhw ac97 \
-localtime
sudo "${sudo_args[@]}" qemu-tap-helper.sh "$username" "$tap_nic" "$br_nic" "$wan_nic" down
;;
liveiso)
if [[ -z "$2" ]]; then
echo "You must specify the ISO file as a second argument." >&2
exit 1
fi
qemu-system-x86_64 \
-name "$vm_name" \
-monitor stdio \
-enable-kvm -smp 2 -cpu host -m 1024 \
-vga virtio \
-display gtk,gl=on \
-drive file="$2",if=virtio,media=cdrom -boot once=d \
-net nic -net user \
-usbdevice tablet
;;
liveiso-efi)
if [[ -z "$2" ]]; then
echo "You must specify the ISO file as a second argument." >&2
exit 1
fi
if [[ ! -e "/usr/share/ovmf/x64/OVMF_CODE.fd" ]]; then
echo "File /usr/share/ovmf/x64/OVMF_CODE.fd does not exist. Is the package ovmf installed?" >&2
exit 1
fi
qemu-system-x86_64 \
-bios /usr/share/ovmf/x64/OVMF_CODE.fd \
-name "$vm_name" \
-monitor stdio \
-enable-kvm -smp 2 -cpu host -m 1024 \
-vga virtio \
-display gtk,gl=on \
-drive file="$2",if=virtio,media=cdrom -boot once=d \
-net nic -net user \
-usbdevice tablet
;;
*)
echo "Unknown VM name specified: $vm_name" >&2
exit 1
;;
esac
### frequently/previously used options:
## user-mode networking
# -net nic,model=virtio -net user
## user-mode networking with redirect (localhost:2222 -> 10.0.2.15:22)
# -net nic,model=virtio -net user -redir tcp:2222:10.0.2.15:22