@@ -124,6 +124,15 @@ trap '__extra_cleanup; rm -fr "$temp_dir"' EXIT
124124
125125export RUST_BACKTRACE=1 RUST_LIB_BACKTRACE=1
126126
127+ arch=$( uname -m )
128+ case " $arch " in
129+ x86_64|aarch64)
130+ ;;
131+ * )
132+ >&2 echo " Unsupported arch \" $arch \" "
133+ ;;
134+ esac
135+
127136case " ${1:- } " in
128137build)
129138 if (( $# != 1 )) ; then
@@ -136,6 +145,15 @@ build)
136145
137146 # build disk image
138147
148+ case " $arch " in
149+ x86_64)
150+ qemu_system_pkg=qemu-system-x86-core
151+ ;;
152+ aarch64)
153+ qemu_system_pkg=qemu-system-aarch64-core
154+ ;;
155+ esac
156+
139157 packages=(
140158 bash
141159 cloud-init
@@ -154,7 +172,7 @@ build)
154172 openssh-clients
155173 podman
156174 qemu-img
157- qemu-system-x86-core
175+ " $qemu_system_pkg "
158176 shadow-utils
159177 util-linux
160178 virtiofsd
@@ -165,14 +183,22 @@ build)
165183
166184 daemon_json=' { "runtimes": { "crun-vm": { "path": "/home/fedora/bin/crun-vm" } } }'
167185
168- commands =(
186+ virt_builder_args =(
169187 # generate an ssh keypair for users fedora and root so crun-vm
170188 # containers get a predictable keypair
171- ' ssh-keygen -q -f /root/.ssh/id_rsa -N ""'
189+ --run-command= ' ssh-keygen -q -f /root/.ssh/id_rsa -N ""'
172190
173- " mkdir -p /etc/docker && echo ${daemon_json@ Q} > /etc/docker/daemon.json"
191+ --run-command= " mkdir -p /etc/docker && echo ${daemon_json@ Q} > /etc/docker/daemon.json"
174192 )
175193
194+ if [[ " $arch " == aarch64 ]]; then
195+ # enable nested virtualization
196+ virt_builder_args+=(
197+ --append-line ' /etc/default/grub:GRUB_CMDLINE_LINUX_DEFAULT="kvm-arm.mode=nested"'
198+ --run-command ' grub2-mkconfig -o /boot/grub2/grub.cfg'
199+ )
200+ fi
201+
176202 __log_and_run virt-builder \
177203 " fedora-${CRUN_VM_TEST_ENV_FEDORA_VERSION:- 40} " \
178204 --smp " $( nproc ) " \
@@ -182,7 +208,7 @@ build)
182208 --size 50G \
183209 --root-password password:root \
184210 --install " $packages_joined " \
185- " ${commands [@]/#/ --run-command= } "
211+ " ${virt_builder_args [@]} "
186212
187213 # reduce image file size
188214
@@ -232,6 +258,10 @@ start)
232258 __log_and_run podman exec " $container_name " --as fedora " $@ "
233259 }
234260
261+ # ensure nested hardware-accelerated virt is supported
262+
263+ __exec ' [[ -e /dev/kvm ]] || { sudo dmesg; exit 1; }'
264+
235265 chmod a+rx " $temp_dir " # so user "fedora" in guest can access it
236266
237267 __exec sudo cp /root/.ssh/id_rsa /root/.ssh/id_rsa.pub .ssh/
0 commit comments