From ad46446f1b76bdde543848a6380aa203eced57ed Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 15 Mar 2025 14:10:59 +0100 Subject: [PATCH] feat: Verify clock source (#207) --- Dockerfile | 2 +- readme.md | 4 ++++ src/boot.sh | 49 +++++++++++++++++++++++++++---------------------- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index 45209c5..da0f890 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ RUN apk --update --no-cache add unzip && \ rm -rf /tmp/* /var/tmp/* /var/cache/apk/* FROM scratch AS runner -COPY --from=qemux/qemu:6.22 / / +COPY --from=qemux/qemu:7.00 / / ARG VERSION_ARG="0.0" ARG VERSION_KVM_OPENCORE="v21" diff --git a/readme.md b/readme.md index df1e3ad..8d066d0 100644 --- a/readme.md +++ b/readme.md @@ -236,6 +236,10 @@ kubectl apply -f https://raw.githubusercontent.com/dockur/macos/refs/heads/maste You can use [dockur/windows](https://github.com/dockur/windows) for that. It shares many of the same features, and even has completely automatic installation. +### How do I run a Linux desktop in a container? + + You can use [qemus/qemu](https://github.com/qemus/qemu) in that case. + ### Is this project legal? Yes, this project contains only open-source code and does not distribute any copyrighted material. Neither does it try to circumvent any copyright protection measures. So under all applicable laws, this project will be considered legal. diff --git a/src/boot.sh b/src/boot.sh index f136f2a..cfec337 100644 --- a/src/boot.sh +++ b/src/boot.sh @@ -3,10 +3,10 @@ set -Eeuo pipefail # Docker environment variables : "${BOOT_MODE:="macos"}" # Boot mode +: "${SECURE:="off"}" # Secure boot BOOT_DESC="" BOOT_OPTS="" -SECURE="off" OVMF="/usr/share/OVMF" case "${HEIGHT,,}" in @@ -139,14 +139,12 @@ if [ ! -f "$IMG" ]; then rm -rf "$OUT" - if [[ "$DEBUG" == [Yy1]* ]]; then - info "" - info "Model: $MODEL" - info "Rom: $ROM" - info "Serial: $SN" - info "Board: $MLB" - info "" - fi + info "" + info "Model: $MODEL" + info "Rom: $ROM" + info "Serial: $SN" + info "Board: $MLB" + info "" fi @@ -169,20 +167,27 @@ else CPU_FLAGS="$DEFAULT_FLAGS,$CPU_FLAGS" fi +CLOCKSOURCE="tsc" +[[ "${ARCH,,}" == "arm64" ]] && CLOCKSOURCE="arch_sys_counter" CLOCK="/sys/devices/system/clocksource/clocksource0/current_clocksource" -[ -f "$CLOCK" ] && CLOCK=$(<"$CLOCK") -if [[ "${CLOCK,,}" == "kvm-clock" ]]; then - if [[ "$CPU_VENDOR" != "GenuineIntel" ]] && [[ "${CPU_CORES,,}" == "2" ]]; then - warn "Restricted processor to a single core because nested virtualization was detected!" - CPU_CORES="1" - else - warn "Nested virtualization was detected, this might cause issues running macOS!" - fi -fi - -if [[ "${CLOCK,,}" == "hpet" ]]; then - warn "Your clocksource is HPET instead of TSC, this will cause issues running macOS!" +if [ ! -f "$CLOCK" ]; then + warn "file \"$CLOCK\" cannot not found?" +else + result=$(<"$CLOCK") + case "${result,,}" in + "${CLOCKSOURCE,,}" ) ;; + "kvm-clock" ) + if [[ "$CPU_VENDOR" != "GenuineIntel" ]] && [[ "${CPU_CORES,,}" == "2" ]]; then + warn "Restricted processor to a single core because nested KVM virtualization was detected!" + CPU_CORES="1" + else + warn "Nested KVM virtualization detected, this might cause issues running macOS!" + fi ;; + "hyperv_clocksource_tsc_page" ) info "Nested Hyper-V virtualization detected, this might cause issues running macOS!" ;; + "hpet" ) warn "unsupported clock source detected: '$result'. Please set host clock source to '$CLOCKSOURCE', otherwise it will cause issues running macOS!" ;; + *) warn "unexpected clock source detected: '$result'. Please set host clock source to '$CLOCKSOURCE', otherwise it will cause issues running macOS!" ;; + esac fi case "$CPU_CORES" in @@ -190,7 +195,7 @@ case "$CPU_CORES" in "5" ) CPU_CORES="4" ;; "9" ) CPU_CORES="8" ;; esac - + case "$CPU_CORES" in "1" | "2" | "4" | "8" ) SMP="$CPU_CORES,sockets=1,dies=1,cores=$CPU_CORES,threads=1" ;; "6" | "7" ) SMP="$CPU_CORES,sockets=3,dies=1,cores=2,threads=1" ;;