From 1a42fd4a5f78fed7fff842337db1ac5bb4a876a1 Mon Sep 17 00:00:00 2001 From: Martin Borgman Date: Thu, 16 Jun 2022 21:35:54 +0200 Subject: [PATCH] Make qemu_template.sh work on MacOS Make qemu_template.sh work on MacOS Line 14; The nproc command is only available on systems with GNU coreutils installed. The getconf _NPROCESSORS_ONLN alternative will work on a wider range of UNIX systems. Line 114; The mktemp syntax used only works on GNU implementation. Line 159; added hvf (MacOS) and tcg (no acceleration) options as a fallback. By doing this qemu-system-x86_64 will try to use kvm, but when it fails try hvf, and when that fails switch to the tcg accelerator. --- build_library/qemu_template.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build_library/qemu_template.sh b/build_library/qemu_template.sh index 48c82dbf29..3118ef96c9 100755 --- a/build_library/qemu_template.sh +++ b/build_library/qemu_template.sh @@ -11,7 +11,7 @@ VM_MEMORY= VM_CDROM= VM_PFLASH_RO= VM_PFLASH_RW= -VM_NCPUS="$(nproc)" +VM_NCPUS="$(getconf _NPROCESSORS_ONLN)" SSH_PORT=2222 SSH_KEYS="" CLOUD_CONFIG_FILE="" @@ -111,7 +111,7 @@ write_ssh_keys() { if [ -z "${CONFIG_IMAGE}" ]; then - CONFIG_DRIVE=$(mktemp -t -d flatcar-configdrive.XXXXXXXXXX) + CONFIG_DRIVE=$(mktemp -d) ret=$? if [ "$ret" -ne 0 ] || [ ! -d "$CONFIG_DRIVE" ]; then echo "$0: mktemp -d failed!" >&2 @@ -156,7 +156,7 @@ else case "${VM_BOARD}+$(uname -m)" in amd64-usr+x86_64) # Emulate the host CPU closely in both features and cores. - set -- -machine accel=kvm -cpu host -smp "${VM_NCPUS}" "$@" ;; + set -- -machine accel=kvm:hvf:tcg -cpu host -smp "${VM_NCPUS}" "$@" ;; amd64-usr+*) set -- -machine pc-q35-2.8 -cpu kvm64 -smp 1 -nographic "$@" ;; arm64-usr+aarch64)