Compare commits

...

5 Commits

Author SHA1 Message Date
Martin Wimpress
268799cfc8
Merge 50d8cb3e9a into 45470649cb 2024-05-15 10:19:34 +00:00
Martin Wimpress
50d8cb3e9a
refactor(darwin): overhaul CPU configuration 2024-05-15 11:19:27 +01:00
Martin Wimpress
2635879446
feat: add host and VM architecture; host is hard coded to x86_64 2024-05-15 11:17:45 +01:00
Martin Wimpress
4bd94e11d6
refactor: get QEMU version from qemu-img; avoids architecture complications 2024-05-15 10:57:27 +01:00
Phil Clifford
45470649cb feat: remove unneeded sed from arcolinux url discovery 2024-05-14 17:13:39 +01:00
2 changed files with 49 additions and 39 deletions

View File

@ -286,23 +286,39 @@ function configure_cpu() {
HOST_CPU_SOCKETS=$(get_cpu_info 'Socket')
HOST_CPU_VENDOR=$(get_cpu_info 'Vendor')
# Detect if running in a VM
CPU_MODEL="host"
# Configure appropriately for the host platform
if [ "${OS_KERNEL}" == "Darwin" ]; then
MANUFACTURER=$(ioreg -l | grep -e Manufacturer | grep -v iMan | cut -d'"' -f4 | sort -u)
# Disable huge pages on macOS to prevent crashes
# - https://stackoverflow.com/questions/60231203/qemu-qcow2-mmu-gva-to-gpa-crash-in-mac-os-x
CPU_MODEL+=",-pdpe1gb"
CPU_KVM_UNHALT=""
KVM_GUEST_TWEAKS=""
QEMU_ACCEL=",accel=hvf"
# QEMU for macOS from Homebrew does not support SMM
SMM="off"
else
MANUFACTURER=$(head -1 /sys/class/dmi/id/sys_vendor)
CPU_KVM_UNHALT=",kvm_pv_unhalt"
KVM_GUEST_TWEAKS="-global kvm-pit.lost_tick_policy=discard "
QEMU_ACCEL=",accel=kvm"
fi
# If the architecture of the VM is different from the host, disable acceleration
if [ "${ARCH_VM}" != "${ARCH_HOST}" ]; then
QEMU_ACCEL=""
CPU_MODEL="qemu64"
CPU_KVM_UNHALT=""
KVM_GUEST_TWEAKS=""
fi
# Detect if running in a VM
case ${MANUFACTURER,,} in
qemu) CPU_MODEL="Penryn"
HYPERVISOR="${MANUFACTURER,,}";;
*) CPU_MODEL="host"
# Disable huge pages
# - https://stackoverflow.com/questions/60231203/qemu-qcow2-mmu-gva-to-gpa-crash-in-mac-os-x
if [ "${OS_KERNEL}" == "Darwin" ]; then
CPU_MODEL+=",-pdpe1gb"
fi
HYPERVISOR="";;
qemu|virtualbox) CPU_MODEL="qemu64"
QEMU_ACCEL=""
HYPERVISOR="${MANUFACTURER,,}";;
*) HYPERVISOR="";;
esac
if [ -z "${HYPERVISOR}" ]; then
@ -564,7 +580,7 @@ function configure_os_quirks() {
# Make any OS specific adjustments
case ${guest_os} in
batocera|*bsd|freedos|haiku|linux*|*solaris)
CPU="-cpu ${CPU_MODEL}${CPU_KVM}"
CPU="-cpu ${CPU_MODEL}"
if [ "${HOST_CPU_VENDOR}" == "AuthenticAMD" ]; then
CPU="${CPU},topoext"
fi
@ -589,7 +605,7 @@ function configure_os_quirks() {
fi
;;
kolibrios|reactos)
CPU="-cpu qemu32${CPU_KVM}"
CPU="-cpu qemu32"
if [ "${HOST_CPU_VENDOR}" == "AuthenticAMD" ]; then
CPU="${CPU},topoext"
fi
@ -616,21 +632,21 @@ function configure_os_quirks() {
case ${macos_release} in
ventura|sonoma)
if check_cpu_flag sse4_2 && check_cpu_flag avx2; then
CPU="-cpu Haswell-v4${CPU_KVM},vendor=GenuineIntel,+avx,+avx2,+sse,+sse2,+sse3,+sse4.2,vmware-cpuid-freq=on"
CPU="-cpu Haswell-v4,vendor=GenuineIntel,+avx,+avx2,+sse,+sse2,+sse3,+sse4.2,vmware-cpuid-freq=on"
else
echo "ERROR! macOS ${macos_release} requires a CPU with SSE 4.2 and AVX2 support."
exit 1
fi;;
catalina|big-sur|monterey)
if check_cpu_flag sse4_2; then
CPU="-cpu Haswell-v4${CPU_KVM},vendor=GenuineIntel,+avx,+sse,+sse2,+sse3,+sse4.2,vmware-cpuid-freq=on"
CPU="-cpu Haswell-v4,vendor=GenuineIntel,+avx,+sse,+sse2,+sse3,+sse4.2,vmware-cpuid-freq=on"
else
echo "ERROR! macOS ${macos_release} requires a CPU with SSE 4.2 support."
exit 1
fi;;
*)
if check_cpu_flag sse4_1; then
CPU="-cpu Penryn${CPU_KVM},vendor=GenuineIntel,+avx,+sse,+sse2,+sse3,+sse4.1,vmware-cpuid-freq=on"
CPU="-cpu Penryn,vendor=GenuineIntel,+avx,+sse,+sse2,+sse3,+sse4.1,vmware-cpuid-freq=on"
else
echo "ERROR! macOS ${macos_release} requires a CPU with SSE 4.1 support."
exit 1
@ -685,9 +701,9 @@ function configure_os_quirks() {
;;
windows|windows-server)
if [ "${QEMU_VER_SHORT}" -gt 60 ]; then
CPU="-cpu ${CPU_MODEL}${CPU_KVM},+hypervisor,+invtsc,l3-cache=on,migratable=no,hv_passthrough"
CPU="-cpu ${CPU_MODEL},+hypervisor,+invtsc,l3-cache=on,migratable=no,hv_passthrough"
else
CPU="-cpu ${CPU_MODEL}${CPU_KVM},+hypervisor,+invtsc,l3-cache=on,migratable=no,hv_frequencies${CPU_KVM_UNHALT},hv_reenlightenment,hv_relaxed,hv_spinlocks=8191,hv_stimer,hv_synic,hv_time,hv_vapic,hv_vendor_id=1234567890ab,hv_vpindex"
CPU="-cpu ${CPU_MODEL},+hypervisor,+invtsc,l3-cache=on,migratable=no,hv_frequencies${CPU_KVM_UNHALT},hv_reenlightenment,hv_relaxed,hv_spinlocks=8191,hv_stimer,hv_synic,hv_time,hv_vapic,hv_vendor_id=1234567890ab,hv_vpindex"
fi
if [ "${HOST_CPU_VENDOR}" == "AuthenticAMD" ]; then
CPU="${CPU},topoext"
@ -702,9 +718,13 @@ function configure_os_quirks() {
else
GUEST_TWEAKS+=" -no-hpet"
fi
SMM="on"
# SMM is not available on QEMU for macOS via Homebrew
if [ "${OS_KERNEL}" == "Linux" ]; then
SMM="on"
fi
;;
*) CPU="-cpu ${CPU_MODEL}${CPU_KVM}"
*) CPU="-cpu ${CPU_MODEL}"
NET_DEVICE="rtl8139"
echo "WARNING! Unrecognised guest OS: ${guest_os}";;
esac
@ -1101,17 +1121,12 @@ function vm_boot() {
echo "#!/usr/bin/env bash" > "${VMDIR}/${VMNAME}.sh"
# Changing process name is not supported on macOS
if [ "${OS_KERNEL}" == "Darwin" ]; then
if [ -z "${HYPERVISOR}" ]; then
# shellcheck disable=SC2054,SC2206,SC2140
args+=(-accel hvf)
fi
else
if [ "${OS_KERNEL}" == "Linux" ]; then
# shellcheck disable=SC2054,SC2206,SC2140
args+=(-name ${VMNAME},process=${VMNAME} -enable-kvm)
args+=(-name ${VMNAME},process=${VMNAME})
fi
# shellcheck disable=SC2054,SC2206,SC2140
args+=(-machine ${MACHINE_TYPE},smm=${SMM},vmport=off ${GUEST_TWEAKS}
args+=(-machine ${MACHINE_TYPE},smm=${SMM},vmport=off${QEMU_ACCEL} ${GUEST_TWEAKS}
${CPU} ${SMP}
-m ${RAM_VM} ${BALLOON}
-rtc base=localtime,clock=host,driftfix=slew
@ -1814,10 +1829,12 @@ readonly DISK_MIN_SIZE=$((197632 * 8))
readonly VERSION="4.9.5"
# TODO: Make this run the native architecture binary
QEMU=$(command -v qemu-system-x86_64)
ARCH_VM="x86_64"
ARCH_HOST=$(uname -m)
QEMU=$(command -v qemu-system-${ARCH_VM})
QEMU_IMG=$(command -v qemu-img)
if [ ! -x "${QEMU}" ] || [ ! -x "${QEMU_IMG}" ]; then
echo "ERROR! QEMU not found. Please make sure 'qemu-system-x86_64' and 'qemu-img' are installed."
echo "ERROR! QEMU not found. Please make sure 'qemu-system-${ARCH_VM}' and 'qemu-img' are installed."
exit 1
fi
@ -1828,19 +1845,12 @@ if command -v gstat &>/dev/null; then
fi
OS_KERNEL=$(uname -s)
CPU_KVM=",kvm=on"
CPU_KVM_UNHALT=",kvm_pv_unhalt"
KVM_GUEST_TWEAKS="-global kvm-pit.lost_tick_policy=discard "
# Detect macOS and disable KVM
if [ "${OS_KERNEL}" == "Darwin" ]; then
CPU_KVM=""
CPU_KVM_UNHALT=""
KVM_GUEST_TWEAKS=""
display="cocoa"
fi
QEMU_VER_LONG=$(${QEMU} -version | head -n1 | cut -d' ' -f4 | cut -d'(' -f1)
QEMU_VER_SHORT=$(${QEMU} -version | head -n1 | cut -d' ' -f4 | cut -d'(' -f1 | sed 's/\.//g' | cut -c1-2)
QEMU_VER_LONG=$(${QEMU_IMG} --version | head -1 | awk '{print $3}')
QEMU_VER_SHORT=$(echo "${QEMU_VER_LONG//./}" | cut -c1-2)
if [ "${QEMU_VER_SHORT}" -lt 60 ]; then
echo "ERROR! QEMU 6.0.0 or newer is required, detected ${QEMU_VER_LONG}."
exit 1

View File

@ -599,7 +599,7 @@ function releases_archlinux() {
function releases_arcolinux() {
#shellcheck disable=SC2046,SC2005
echo $(web_pipe "https://mirror.accum.se/mirror/arcolinux.info/iso/" | grep -o -E ">v[[:digit:]]{2}.[[:digit:]]{2}.[[:digit:]]{2}" | sed -e "s/>//" | sort -r | head -n 5)
echo $(web_pipe "https://mirror.accum.se/mirror/arcolinux.info/iso/" | grep -o -E "v[[:digit:]]{2}.[[:digit:]]{2}.[[:digit:]]{2}" | sort -ru | head -n 5)
}
function editions_arcolinux() {