-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboot.sh
executable file
·331 lines (259 loc) · 7.13 KB
/
boot.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/usr/bin/env bash
#
# Script for booting with QEMU with various architectures
#
# You need to modify image file
# and create disk.qcow2 or disk.raw yourself
#
# https://gist.github.com/500c3779a18976ceb394a87a08708758
#
# Usage:
#
# ./boot.sh PRESET [option] DISK_file [ISO_file]
#
# See the blocks in code for options.
#
# I personally use 'UEFI' PRESET, but there's also
# 'NET' for booting from network (see net.sh for network
# config example) and others (see code).
#
# Don't forget to append to kernel command line:
# inst.text console=ttyS0
# for install.
#
# Options:
#
# -t set 1 minute timeout (needs to go before all other args)
# -d add device (supply one as next arg)
# -n add nic (supply one as next arg)
#
#
# Examples:
#
# ./boot.sh UEFI fedora36 Fedora-Server-dvd
#
# ./boot.sh UEFI '' 'Rawhide-20220505.n.0'
#
# ./boot.sh UEFI 'rhel-22-03-18'
#
# ./boot.sh -n bridge,br=virbr0,id=n2 UEFI 'rhel9-test' -
#
## Init
bash -n "$0" || exit 1
set -xe
cd "$(dirname "$0")"
## Methods
abort () {
echo "$@" >&2
exit 1
}
iso () {
local F="$(ls -d *"$1"*.iso | tail -n 1)"
[[ -n "$F" ]] || abort "Image file not found: *\"${1}\"*.iso"
[[ -r "$F" ]] || abort "Image missing or unreadable: $IMG"
echo "$F"
}
warn () {
echo "Warning:" "$@" >&2
}
ovmf () {
local f='/usr/share/edk2/ovmf/OVMF_CODE.fd'
[[ -r "$f" ]] && return 0
echo "OVMF is needed to boot uefi images"
[[ "$(whoami)" == root ]] && SUDO= || SUDO=sudo
$SUDO $(which dnf) install '/usr/share/edk2/ovmf/OVMF_CODE.fd'
}
escape () {
printf "%q" "$1"
return 0
}
## Const
DEFAULT_NET='-nic user,model=virtio-net-pci'
#DEFAULT_NET='-device virtio-net-pci,netdev=net0 -netdev user,id=net0,ipv6=off'
## Args
[[ "$1" == "-t" ]] && {
shift
exec timeout 60 "$0" "$@"
}
# Pre-switches
[[ "$1" == "-d" ]] && {
DEV="-device $2"
shift 2
:
} || DEV=
[[ "$1" == "-n" ]] && {
NET="$2"
shift 2
[[ -n "$NET" && "$NET" != '-' ]] \
&& NET="${NET:+-nic $NET}" \
|| NET=
:
} || NET="$DEFAULT_NET"
# Main arg
ARG="$1"
shift
[[ -z "$ARG" || "${ARG:0:1}" == "-" ]] \
&& abort "Arg missing or invalid!"
# Disk image string
[[ "${1:0:1}" != "-" ]] && {
[[ -n "$1" ]] && {
DSK="$1"
shift
}
[[ -r "$DSK" ]] || DSK="disk${DSK:+-$DSK}.qcow2"
[[ -r "$DSK" ]] || abort "Disk missing or unreadable: $DSK"
:
} || DSK=''
# Shift even if empty
shift ||:
# Iso file for the cdrom
[[ "${1:0:1}" != "-" ]] && {
[[ -n "$1" ]] && {
IMG="$1"
shift
}
IMG="$(iso ${IMG:-})"
IMG="${IMG:+-cdrom $IMG}"
:
} || IMG=''
[[ -z "$1" ]] || abort "Unknown arg: $1"
## Execute
[[ "$ARG" == 'AARCH' ]] && {
echo "> aarch"
warn "does not work yet"
#cp $(dirname $(which qemu-img))/../share/qemu/edk2-aarch64-code.fd .
#cp $(dirname $(which qemu-img))/../share/qemu/edk2-arm-vars.fd .
exec \
/opt/homebrew/bin/qemu-system-aarch64 \
-m 2048 -smp 1 \
-device virtio-serial \
-accel hvf -accel tcg -cpu cortex-a57 -M virt,highmem=off \
-drive file=/opt/homebrew/share/qemu/edk2-aarch64-code.fd,if=pflash,format=raw,readonly=on \
-drive if=virtio,file="$DSK" \
${IMG} ${NET} ${DEV} \
-nographic \
-boot d
exit
exec \
qemu-system-aarch64 \
-machine virt,accel=hvf,highmem=off \
-cpu host \
-smp 1 -m 2G \
-device intel-hda \
-device hda-output \
-device qemu-xhci \
-device usb-kbd \
-device virtio-net-pci,netdev=net0 \
-device virtio-mouse-pci \
-netdev user,id=net0,ipv6=off \
-drive "if=pflash,format=raw,file=./edk2-aarch64-code.fd,readonly=on" \
-drive "if=pflash,format=raw,file=./edk2-arm-vars.fd,discard=on" \
-drive "if=virtio,format=raw,file=./disk.raw,discard=on" \
${IMG} ${NET} ${DEV} \
-nographic \
-boot d
exit
-drive file=/Users/pvalena/.local/share/containers/podman/machine/qemu/podman-machine-default_ovmf_vars.fd,if=pflash,format=raw \
-cpu cortex-a72 \
}
[[ "$ARG" == "EXPERIMENTAL" ]] && {
echo "> x86 : non-uefi"
warn "does not work yet"
exec \
qemu-system-x86_64 \
-machine q35,accel=tcg \
-smp 1 -m 2G \
-device intel-hda \
-device hda-output \
-device qemu-xhci \
-device usb-kbd \
-device virtio-net-pci,netdev=net0 \
-device virtio-mouse-pci \
-netdev user,id=net0,ipv6=off \
-drive "if=virtio,format=qcow2,file=${DSK},discard=on" \
${IMG} ${NET} ${DEV} \
-nographic \
-boot d
exit
}
[[ "$ARG" == "DEFAULT" ]] && {
echo "> x86 : non-uefi"
exec \
qemu-system-x86_64 \
-boot menu=on \
-cpu max \
-accel kvm \
-smp 1 \
-drive "file=${DSK},format=qcow2" \
${IMG} ${NET} ${DEV} \
-m 2G \
-nographic
exit
}
[[ "$ARG" == "UEFI" ]] && {
echo "> x86 : uefi"
ovmf
exec \
qemu-system-x86_64 \
-boot menu=on \
-m 8G \
-cpu max \
-smp 4 \
-drive "file=${DSK},format=qcow2" \
-bios /usr/share/edk2/ovmf/OVMF_CODE.fd \
${IMG} ${NET} ${DEV} \
-accel kvm \
-serial mon:stdio \
-nographic \
-chardev vc,id=vc1,width=$(tput cols),height=$(tput lines) -mon chardev=vc1
exit
-nic tap,br=virbr0,model=e1000,"helper=/usr/libexec/qemu-bridge-helper" \
-device virtio-net-pci,netdev=net0 \
-netdev user,id=net0,ipv6=off \
-append 'console=ttyS0' \
# kernel: net.ifnames.prefix=net inst.text console=ttyS0
}
[[ "$ARG" == "NET" ]] && {
echo "> x86 : $ARG"
exec \
qemu-system-x86_64 \
-boot n \
-m 2G \
-cpu max \
-smp 1 \
${IMG} ${NET} ${DEV} \
-accel kvm \
-serial mon:stdio \
-nographic
-chardev vc,id=vc1,width=$(tput cols),height=$(tput lines) -mon chardev=vc1
exit
-nic tap,br=virbr0,mac=52:54:00:12:35:58,model=e1000,"helper=/usr/libexec/qemu-bridge-helper" \
-device e1000,netdev=net0,mac=52:54:00:12:35:58 \
-netdev user,id=net0,ipv6=off \
-append 'console=ttyS0' \
# kernel: net.ifnames.prefix=net inst.text console=ttyS0
}
abort "Unknown arg: $ARG"
# Unused
-device virtio-gpu-gl-pci \
-device virtio-serial \
-device virtio-rng-pci \
-bios ./u-boot.bin
# podman
qemu-system-aarch64 \
-m 2048 \
-smp 1 \
-fw_cfg name=opt/com.coreos/config,file=/Users/pvalena/.config/containers/podman/machine/qemu/podman-machine-default.ign \
-qmp unix://var/folders/j_/1q2pjk_13rn3p64zvndjgwyc0000gn/T/podman/qmp_podman-machine-default.sock,server=on,wait=off \
-netdev socket,id=vlan,fd=3 -device virtio-net-pci,netdev=vlan,mac=5a:94:ef:e4:0c:ee \
-device virtio-serial \
-chardev socket,path=/var/folders/j_/1q2pjk_13rn3p64zvndjgwyc0000gn/T/podman/podman-machine-default_ready.sock,server=on,wait=off,id=podman-machine-default_ready \
-device virtserialport,chardev=podman-machine-default_ready,name=org.fedoraproject.port.0 \
-accel hvf \
-accel tcg \
-cpu cortex-a57 \
-M virt,highmem=off \
-drive file=/opt/homebrew/share/qemu/edk2-aarch64-code.fd,if=pflash,format=raw,readonly=on \
-drive file=/Users/pvalena/.local/share/containers/podman/machine/qemu/podman-machine-default_ovmf_vars.fd,if=pflash,format=raw \
-drive if=virtio,file=/Users/pvalena/.local/share/containers/podman/machine/qemu/podman-machine-default_fedora-coreos-35.20220131.2.0-qemu.aarch64.qcow2 \
-display none