forked from ASoft-se/Gentoo-HAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_w_qemu.sh
executable file
·87 lines (77 loc) · 2.3 KB
/
test_w_qemu.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
#!/bin/bash
echo $0 Got arguments: $*
netscript="-nic user,model=virtio"
DISK=kvm_lxgentootest.qcow2
disktype="
-device ahci,id=ahci
-device ide-hd,drive=d1,bus=ahci.0
"
USEEFI=""
VNC="-vnc 127.0.0.1:22 -k sv"
VGA=""
memorygb=2
POSITIONAL=()
while (($#)); do
case $1 in
-netdev)
# use -netdev argument to create and add that as interface to existing br0 for example: -netdev tapKVMLx0
shift
netdev=$1
echo If you havent already, you should run the below as root
echo ip tuntap add dev $netdev mode tap user $USER
echo ip link set dev $netdev up master br0
netscript="
-net nic,macaddr=52:54:00:53:27:00,model=e1000
-net tap,script=no,downscript=no,ifname=$netdev
"
;;
useefi)
USEEFI=YES
efibios="-bios usr/share/edk2.git/ovmf-x64/OVMF-pure-efi.fd"
;;
usenvme)
disktype="-device nvme,drive=d1,id=nvme1,serial=nonoptionalsn001"
;;
auto)
echo "using -nographic, Ctrl+A, X exits"
VNC=""
VGA="-nographic"
;;
-m)
shift
echo "Set memory to $1 gb"
memorygb=$1
;;
*)
POSITIONAL+=("$1") # save it in an array for later
;;
esac
shift
done
set -- "${POSITIONAL[@]}" # restore positional parameters
#VGA="-nographic -device sga"
#VGA="-nographic"
#VGA="-curses"
[[ "$USEEFI" != "YES" ]] && [[ "$VGA" == "" ]] && VGA="-vga vmware"
# Create interface however you want to.
# Recommendation to use a local proxy (ex squid) and transparent http redirection to save bandwidth
# ex iptables transparent proxy: iptables -t nat -A PREROUTING -i br0 -p tcp --dport 80 -j REDIRECT --to-port 3128
# start with -cdrom install-amd64-mod.iso to boot from livecd
# TODO auto handle inc of mac netdev and vnc port
[ ! -f $DISK ] && qemu-img create -f qcow2 $DISK 20G
[[ "$VNC" != "" ]] && (sleep 3; vncviewer :22) &
set -x
jn=$(nproc)
qemu-system-x86_64 -enable-kvm -M q35 -m $(($memorygb*1024)) -cpu host -smp $jn,cores=$jn,sockets=1 -name lxgentootest \
-drive id=d1,file=$DISK,format=qcow2,if=none,media=disk,index=1,cache=unsafe \
${disktype} \
$netscript \
-watchdog i6300esb -watchdog-action reset \
-boot menu=on -usb ${VGA} ${VNC} \
${efibios} \
$*
# Extra lines to add if using multiple disks with ahci
#-drive id=d2,file=kvm_lx2.img,if=none,media=disk,index=3,cache=writeback \
#-device ide-drive,drive=d2,bus=ahci.1 \
#IDE version if ahci is problematic
#-device ide-hd,drive=d1,bus=ide.0 \