-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy patharmv7
executable file
·150 lines (119 loc) · 4.8 KB
/
armv7
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
#!/bin/bash
script_info='ARM linux VM for alpine with EFI boot.'
ins=1 smp=4 mem=4G nets=1 help_ext= root_opts_file=()
img= dev_ro=() dev=() efi= iso=
read -r -d '' script_usage <<EOF
Usage: $0 [-r|--root] [ {-i|--instance} $ins ] [ {-t|--smp} $smp ] [ {-m|--mem} $mem ]
[ {-o|--opts} file.opts ] [ {-q|--img} file.qcow2 ]
[ {-s|--dev-ro} disk.img +] [ {-d|--dev} /dev/xyz +]
[ {-e|--efi} [copy of AAVMF32_CODE.fd] ] [ --iso image.iso ] [-nX|--nets=X]
(note: ordering of options matters)
EOF
script_usage=${script_usage// / }
read -r -d '' script_info_ext <<EOF
$script_info
Cheatsheet for qemu-img (to use with -q/--img option):
qemu-img create -f qcow2 install.qcow2 10G
qemu-img create -b install.qcow2 -f qcow2 install.qcow2.inc
qemu-img commit install.qcow2.inc && rm install.qcow2.inc
Alpine install ISO can be grabbed from https://alpinelinux.org/downloads/
Example: https://dl-cdn.alpinelinux.org/alpine/v3.15/releases/armv7/alpine-virt-3.15.0-armv7.iso
XXX: install/post-install info
EOF
script_info_ext=${script_info_ext// / }
[[ "$1" = -r || "$1" = --root || "$UID" -ne 0 ]] || {
echo >&2 "ERROR: running as uid=0 but no -r/--root specified"; exit 1; }
[[ "$1" = -i || "$1" = --instance ]] && { ins=$2; shift; shift; }
[[ "$1" = -t || "$1" = --smp ]] && { smp=$2; shift; shift; }
[[ "$1" = -m || "$1" = --mem ]] && { mem=$2; shift; shift; }
[[ "$1" = -o || "$1" = --opts ]] && {
declare -a root_opts_file="($(<"$2"))"; shift; shift; }
[[ "$1" = -q || "$1" = --img ]] && { img=$(realpath "$2"); shift; shift; }
while [[ "$1" = -s || "$1" = --dev-ro ]]
do dev_ro+=( $(realpath "$2") ); shift; shift; done
while [[ "$1" = -d || "$1" = --dev ]]
do dev+=( $(realpath "$2") ); shift; shift; done
[[ "$1" = -e || "$1" = --efi ]] && { efi=$(realpath "$2"); shift; shift; }
[[ "$1" = --iso ]] && { iso=$(realpath "$2"); shift; shift; }
[[ "$1" = -n2 || "$1" = --nets=2 ]] && { nets=2; shift; }
[[ "$1" = -n3 || "$1" = --nets=3 ]] && { nets=3; shift; }
root=$(dirname "$BASH_SOURCE")
net_mac_tail=54:00:12:34:$(( 60 + $ins )) # missing first (even) octet
net_pre=vm net_only=
case "$1" in
# LAZY: didn't copy management commands here
n|net|net-only) net_only=t ;;
'') ;;
-h|--help-ext) echo "$script_usage";echo; echo "$script_info_ext"; exit 0 ;;
*)
echo >&2 "$script_usage"
echo >&2
echo >&2 "$script_info"
echo >&2 "Use -h/--help-ext option for various qemu/option/setup cheatsheets."
exit 1 ;;
esac
cd "$root"
### img/iso options
root_opts=()
[[ "${#root_opts_file[@]}" -eq 0 ]] || root_opts+=( "${root_opts_file[@]}" )
[[ -z "$img" ]] || root_opts+=(
-drive file="$img",if=virtio,aio=native,cache=writeback,cache.direct=on )
[[ "${#dev_ro[@]}" -eq 0 ]] || { for dev in "${dev_ro[@]}"
do root_opts+=( -drive file="$dev",if=virtio,readonly=on,format=raw ); done; }
[[ "${#dev[@]}" -eq 0 ]] || { for dev in "${dev[@]}"
do root_opts+=( -drive file="$dev",if=virtio,format=raw ); done; }
[[ -z "$iso" ]] || root_opts+=( -cdrom "$iso" )
[[ -z "$efi" ]] || root_opts=( -bios "$efi" )
[[ -n "$efi" ]] || {
[[ -e AAVMF32_CODE.fd && -e AAVMF32_VARS.fd ]] \
&& root_opts=( -bios AAVMF32_CODE.fd ) \
|| { cat >&2 <<'EOF'
## Need either -e/--efi option or AAVMF32_{CODE,VARS}.fd in the current dir
# 32-bit ARM bios deb pkg: https://packages.debian.org/sid/qemu-efi-arm
deb=https://ftp.debian.org/debian/pool/main/e/edk2/qemu-efi-arm_2022.02-1_all.deb;
curl -L "$deb" | bsdtar -xOf - data.tar.xz | bsdtar -xf - ./usr/share/AAVMF/AAVMF32_\*.fd;
mv usr/share/AAVMF/AAVMF32_* . && rmdir -p usr/share/AAVMF
EOF
exit 1; } }
### net options
[[ -e /usr/local/bin/qemu-add-tap ]] || {
cat >&2 <<'EOF'
## Missing qemu network tap helper in /usr/local/bin/qemu-add-tap
## sudoers.d line: makepkg ALL=(root:root) NOPASSWD: /usr/local/bin/qemu-add-tap
#!/bin/bash
net_user=$1 net_pre=$2 mac_head=$3
[[ -z "$4" && -n "$net_user" && -n "$net_pre" && -n "$mac_head" ]] \
|| { echo >&2 "Invalid arguments: $@"; exit 1; }
ip link add "${net_pre}" type bridge
ip tuntap add mode tap user "$net_user" "${net_pre}-${mac_head}"
ip link set "${net_pre}-${mac_head}" master "${net_pre}"
EOF
exit 1; }
mac_head=52 net_opts=()
while [[ "$nets" -gt 0 ]]; do
net_opts+=(
-device virtio-net-pci,mac=${mac_head}:${net_mac_tail},netdev=tap_${mac_head}
-netdev tap,id=tap_${mac_head},ifname=${net_pre}-${mac_head},br=${net_pre},script=no,downscript=no )
sudo -n /usr/local/bin/qemu-add-tap $USER ${net_pre} ${mac_head}
(( nets -= 1 )); (( mac_head += 2 ))
done
[[ -n "$net_only" ]] && exit 0
### Run qemu
qemu_opts=(
-name "$(basename "$0").$ins"
-bios AAVMF32_CODE.fd
-rtc base=utc,clock=host
-device virtio-rng-pci
-accel tcg,thread=multi
-machine virt
# XXX: check -machine help, accel stuff
-cpu cortex-a15
-smp cores="$smp"
-m "$mem"
-nographic
"${net_opts[@]}"
"${root_opts[@]}"
)
ulimit -c 0
export QEMU_AUDIO_DRV=none
exec qemu-system-arm "${qemu_opts[@]}"