-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_w_qemu.sh
More file actions
executable file
·124 lines (113 loc) · 3.42 KB
/
Copy pathtest_w_qemu.sh
File metadata and controls
executable file
·124 lines (113 loc) · 3.42 KB
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
#!/bin/bash
echo $0 Got arguments: $*
DISK=kvm_lxgentootest.qcow2
disktype="
-device virtio-blk-pci,drive=d1
"
disktypeahci="
-device ahci,id=ahci
-device ide-hd,drive=d1,bus=ahci.0
"
USEEFI=""
VNC="-vnc [::1]:22"
VGA=""
efibios=""
bootfile="pxe/boot.ipxe"
memorygb=4
POSITIONAL=()
while (($#)); do
case $1 in
-bootfile)
shift
bootfile=$1
;;
-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
"
;;
-bridge)
shift
netdev=$1
netscript="
-net nic,macaddr=52:54:00:53:27:00,model=virtio
-net bridge,br=$netdev
"
;;
useefi)
USEEFI=YES
cp /usr/share/edk2-ovmf/OVMF_VARS.fd kvm_lxgentootest_VARS.fd
efibios="-drive if=pflash,unit=0,format=raw,readonly=on,file=/usr/share/edk2-ovmf/OVMF_CODE.fd \
-drive if=pflash,unit=1,format=raw,file=kvm_lxgentootest_VARS.fd"
[[ -d pxe ]] || mkdir -p pxe
cp $bootfile pxe/autoexec.ipxe
[ -f pxe/ipxe.efi ] || (wget https://boot.ipxe.org/x86_64-efi/ipxe-legacy.efi && mv ipxe-legacy.efi pxe/ipxe.efi)
bootfile=pxe/ipxe.efi
;;
usenvme)
disktype="-device nvme,drive=d1,id=nvme1,serial=nonoptionalsn001"
;;
serial)
;& # fallthru
auto)
echo "using -nographic, Ctrl+A, X exits"
VNC=""
VGA="-nographic"
;;
-cdrom)
shift
POSITIONAL+=("-drive file=$1,if=none,media=cdrom,id=cd1 -device ahci,id=achi0 -device ide-cd,bus=achi0.0,drive=cd1")
;;
-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) &
if [[ -z "$VNC" ]]; then
# if serial make sure autoexec.ipxe is set for serial console
[[ -d pxe ]] || mkdir -p pxe
[[ "$USEEFI" != "YES" ]] && cp $bootfile pxe/autoexec.ipxe && bootfile="pxe/autoexec.ipxe"
sed -i 's/ cdroot/ cdroot console=ttyS0,115200/' pxe/autoexec.ipxe
fi
: "${netscript:=-nic user,model=virtio,hostfwd=tcp::2222-:22,tftp=.,bootfile=$bootfile}"
set -x
jn=$(($(nproc)/2))
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,cache=unsafe \
${disktype} \
$netscript \
-device i6300esb -action watchdog=reset \
-device virtio-rng-pci \
-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 \