@@ -125,6 +125,15 @@ trap '__extra_cleanup; rm -fr "$temp_dir"' EXIT
125
125
126
126
export RUST_BACKTRACE=1 RUST_LIB_BACKTRACE=1
127
127
128
+ arch=$( uname -m )
129
+ case " $arch " in
130
+ x86_64|aarch64)
131
+ ;;
132
+ * )
133
+ >&2 echo " Unsupported arch \" $arch \" "
134
+ ;;
135
+ esac
136
+
128
137
case " ${1:- } " in
129
138
build)
130
139
if (( $# != 1 )) ; then
@@ -143,21 +152,37 @@ build)
143
152
144
153
# expand base image
145
154
146
- __log_and_run qemu-img create -f qcow2 " $temp_dir /image.qcow2" 50G
155
+ root_part=$(
156
+ virt-filesystems --add " $temp_dir /image" --long |
157
+ awk ' /^\/dev\// {if ($4 == "fedora") print $1}'
158
+ )
159
+
160
+ __log_and_run qemu-img create -f qcow2 " $temp_dir /image.qcow2" 20G
147
161
__log_and_run virt-resize \
148
162
--quiet \
149
- --expand /dev/sda4 \
163
+ --expand " $root_part " \
150
164
" $temp_dir /image" \
151
165
" $temp_dir /image.qcow2"
152
166
153
167
rm " $temp_dir /image"
154
168
169
+ # enable nested virtualization
170
+
171
+ if [[ " $arch " == aarch64 ]]; then
172
+ __log_and_run virt-customize \
173
+ --quiet \
174
+ --no-network \
175
+ --add " $temp_dir /image.qcow2" \
176
+ --append-line ' /etc/default/grub:GRUB_CMDLINE_LINUX_DEFAULT="kvm-arm.mode=nested"' \
177
+ --run-command ' grub2-mkconfig -o /boot/grub2/grub.cfg'
178
+ fi
179
+
155
180
# launch VM from base image file
156
181
157
182
__log_and_run podman run \
158
183
--name " $container_name -build" \
159
184
--runtime " $runtime " \
160
- --memory 8g \
185
+ --memory 4g \
161
186
--rm -dit \
162
187
--rootfs " $temp_dir " \
163
188
--persistent
@@ -177,6 +202,15 @@ build)
177
202
# get a predictable keypair
178
203
__exec ' ssh-keygen -q -f .ssh/id_rsa -N "" && sudo cp -r .ssh /root/'
179
204
205
+ case " $arch " in
206
+ x86_64)
207
+ qemu_system_pkg=qemu-system-x86-core
208
+ ;;
209
+ aarch64)
210
+ qemu_system_pkg=qemu-system-aarch64-core
211
+ ;;
212
+ esac
213
+
180
214
__exec sudo dnf update -y
181
215
__exec sudo dnf install -y \
182
216
bash \
@@ -195,7 +229,7 @@ build)
195
229
openssh-clients \
196
230
podman \
197
231
qemu-img \
198
- qemu-system-x86-core \
232
+ " $qemu_system_pkg " \
199
233
shadow-utils \
200
234
util-linux \
201
235
virtiofsd
@@ -251,15 +285,20 @@ start)
251
285
252
286
# shellcheck disable=SC2317
253
287
__extra_cleanup () {
288
+ __exec df -h
254
289
__log_and_run podman stop --time 0 " $container_name "
255
290
}
256
291
257
- # load test images onto VM
292
+ # ensure nested hardware-accelerated virt is supported
258
293
259
294
__exec () {
260
295
__log_and_run podman exec " $container_name " --as fedora " $@ "
261
296
}
262
297
298
+ __exec ' [[ -e /dev/kvm ]] || { sudo dmesg; exit 1; }'
299
+
300
+ # load test images onto VM
301
+
263
302
chmod a+rx " $temp_dir " # so user "fedora" in guest can access it
264
303
265
304
for image in " ${TEST_IMAGES[@]} " ; do
0 commit comments