diff --git a/.gitignore b/.gitignore index c154cea..1214c67 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ *.sucatalog OVMF_VARS*.fd OpenCore-Catalina/EFI/OC/Resources/ +*log.txt diff --git a/OpenCore/Boot-NoUI/config.plist b/OpenCore/headless/config.plist similarity index 99% rename from OpenCore/Boot-NoUI/config.plist rename to OpenCore/headless/config.plist index 1f218ea..d6f34da 100755 --- a/OpenCore/Boot-NoUI/config.plist +++ b/OpenCore/headless/config.plist @@ -1312,11 +1312,13 @@ AdviseFeatures MLB - C02119700QXJG36JC + C02731301GUJG36JC ProcessorType 0 ROM - 0022412e3d4a + + 9PFai1o+ + SpoofVendor SystemMemoryStatus @@ -1324,9 +1326,9 @@ SystemProductName iMacPro1,1 SystemSerialNumber - C02FPBZPHX87 + C02V5SYMHX87 SystemUUID - 213FA768-A62C-4299-8598-47AA666E436F + DF0A0B37-D713-4408-BD6A-3F96139F8597 UpdateDataHub diff --git a/README.md b/README.md index 72a4508..4099b50 100644 --- a/README.md +++ b/README.md @@ -209,12 +209,7 @@ processors work just fine (even for macOS Sonoma). ### Headless macOS -- Use the provided [boot-macOS-headless.sh](./boot-macOS-headless.sh) script. - - ``` - ./boot-macOS-headless.sh - ``` - +You can follow the instructions in the `headless_readme.md` file to run the macOS VM in a headless mode. ### Setting Expectations Right diff --git a/boot-macOS-headless.sh b/boot-macOS-headless.sh deleted file mode 100755 index b5ce2e8..0000000 --- a/boot-macOS-headless.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env bash - -# Special thanks to: -# https://github.com/Leoyzen/KVM-Opencore -# https://github.com/thenickdude/KVM-Opencore/ -# https://github.com/qemu/qemu/blob/master/docs/usb2.txt -# -# qemu-img create -f qcow2 mac_hdd_ng.img 128G -# -# echo 1 | sudo tee -a /sys/module/kvm/parameters/ignore_msrs # this is required -# -# Usage: -# -# $ boot-macOS-headless.sh -# -# (qemu) change vnc password -# Password: ******** -# -# Note: Using RealVNC client, connect to ``. -# E.g. `vncviewer localhost:5901` - -############################################################################ -# NOTE: Tweak the "MY_OPTIONS" line in case you are having booting problems! -############################################################################ - -MY_OPTIONS="+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check" - -# This script works for Big Sur, Catalina, Mojave, and High Sierra. Tested with -# macOS 10.15.6, macOS 10.14.6, and macOS 10.13.6. - -ALLOCATED_RAM="7192" # MiB -CPU_SOCKETS="1" -CPU_CORES="2" -CPU_THREADS="4" - -REPO_PATH="." -OVMF_DIR="." - -# shellcheck disable=SC2054 -args=( - -enable-kvm -m "$ALLOCATED_RAM" -cpu Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,"$MY_OPTIONS" - -machine q35 - -device qemu-xhci,id=xhci - -device usb-kbd,bus=xhci.0 -device usb-tablet,bus=xhci.0 - -smp "$CPU_THREADS",cores="$CPU_CORES",sockets="$CPU_SOCKETS" - -device usb-ehci,id=ehci - # -device usb-kbd,bus=ehci.0 - # -device usb-mouse,bus=ehci.0 - # -device nec-usb-xhci,id=xhci - # -global nec-usb-xhci.msi=off - -global ICH9-LPC.acpi-pci-hotplug-with-bridge-support=off - # -device usb-host,vendorid=0x8086,productid=0x0808 # 2 USD USB Sound Card - # -device usb-host,vendorid=0x1b3f,productid=0x2008 # Another 2 USD USB Sound Card - -device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" - -drive if=pflash,format=raw,readonly=on,file="$REPO_PATH/$OVMF_DIR/OVMF_CODE.fd" - -drive if=pflash,format=raw,file="$REPO_PATH/$OVMF_DIR/OVMF_VARS-1920x1080.fd" - -smbios type=2 - -device ich9-ahci,id=sata - -drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file="$REPO_PATH/OpenCore/OpenCore.qcow2" - -device ide-hd,bus=sata.2,drive=OpenCoreBoot - -device ide-hd,bus=sata.3,drive=InstallMedia - -drive id=InstallMedia,if=none,file="$REPO_PATH/BaseSystem.img",format=raw - -drive id=MacHDD,if=none,file="$REPO_PATH/mac_hdd_ng.img",format=qcow2 - -device ide-hd,bus=sata.4,drive=MacHDD - -netdev user,id=net0,hostfwd=tcp::2222-:22 -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:27 - -monitor stdio - -device vmware-svga - -display none - -vnc 0.0.0.0:1,password=on -k en-us -) - -qemu-system-x86_64 "${args[@]}" diff --git a/OpenCore-Boot-NoUI.sh b/headless_boot.sh similarity index 71% rename from OpenCore-Boot-NoUI.sh rename to headless_boot.sh index f3c93d7..68f96ec 100755 --- a/OpenCore-Boot-NoUI.sh +++ b/headless_boot.sh @@ -7,7 +7,7 @@ CPU_SOCKETS="1" CPU_CORES="2" CPU_THREADS="4" -REPO_PATH="." +REPO_PATH=$(dirname "$(readlink -f "$0")") OVMF_DIR="." args=( @@ -42,9 +42,20 @@ args=( -device virtio-net-pci,netdev=net0,id=net0,mac=52:54:00:c9:18:27 # Disable the QEMU monitor interface and graphical output + # Comment out the following lines if you want to enable conectivity to the VM via VNC -monitor none -nographic + + # Uncomment the following lines if you want to enable conectivity to the VM via VNC + # -monitor stdio + # -device vmware-svga + # -display none + # -vnc 0.0.0.0:1,password=on -k en-us ) -# Start the QEMU virtual machine in the background and disown the process -qemu-system-x86_64 "${args[@]}" > /dev/null 2>&1 & disown +# Create log file for headless boot and clear it if it already exists +touch "$REPO_PATH/headless_boot_log.txt" +echo "" > "$REPO_PATH/headless_boot_log.txt" + +# Start the QEMU virtual machine and redirect the output to the log file +qemu-system-x86_64 "${args[@]}" > "$REPO_PATH/headless_boot_log.txt" 2>&1 & diff --git a/headless_opencore.service b/headless_opencore.service new file mode 100644 index 0000000..7329aad --- /dev/null +++ b/headless_opencore.service @@ -0,0 +1,12 @@ +[Unit] +Description=OpenCore VM +After=network.target + +[Service] +Type=forking +ExecStart=%repo_path%/headless_boot.sh +ExecStop=/usr/bin/pkill -f qemu-system-x86_64 +Restart=on-failure + +[Install] +WantedBy=multi-user.target diff --git a/README-NoUI.md b/headless_readme.md similarity index 75% rename from README-NoUI.md rename to headless_readme.md index f013f68..688d282 100644 --- a/README-NoUI.md +++ b/headless_readme.md @@ -24,6 +24,13 @@ Complete the macOS setup and install XCode and other GUI-dependent tools. If you need to install XCode, you'll need a unique serial number. Complete steps 1-5 below and start `./OpenCore-Boot.sh` again to connect to your Apple account, install XCode, and other tools. +```bash +# Download XCode from [Apple Developer](https://developer.apple.com/download/all/?q=xcode) +xip -x ~/Downloads/$xcode_version.xip -C /Applications + +xcode-select --install +``` + 1. Navigate or clone GenSMBIOS repository into workspace: ```bash @@ -39,7 +46,7 @@ If you need to install XCode, you'll need a unique serial number. Complete steps ``` 3. Install/Update MacSerial. -4. Select `$osx_kvm_path/OpenCore/Boot-NoUI/config.plist` as the configuration file. +4. Select `$osx_kvm_path/OpenCore/headless/config.plist` as the configuration file. 5. Generate SMBIOS for `iMacPro1,1`. 6. Generate UUID. @@ -52,7 +59,7 @@ git submodule update --init --recursive ./resources/OcBinaryData cd ./OpenCore # Generate OpenCore image with NoUI configuration -rm -f OpenCore.qcow2; sudo ./opencore-image-ng.sh --cfg ./Boot-NoUI/config.plist --img OpenCore.qcow2 +rm -f OpenCore.qcow2; sudo ./opencore-image-ng.sh --cfg ./headless/config.plist --img OpenCore.qcow2 ``` ### Step 6: Start OpenCore VM with NoUI Configuration @@ -63,9 +70,9 @@ cd $osx_kvm_path # cd .. # Make the shell script executable -chmod +x ./OpenCore-Boot-NoUI.sh +chmod +x ./headless_boot.sh -./OpenCore-Boot-NoUI.sh +./headless_boot.sh ``` ### Step 7: Connect to macOS VM with SSH @@ -106,3 +113,27 @@ I personally use Nix flakes to manage the environment, so I can install all the Additionally, I use GitHub to store my credentials, which allows me to just copy the `.gitconfig` and `.git-credentials` to the user home directory on the VM. To debug iOS apps, it's easiest to use XCode Wi-Fi debugging, so you don't need to connect the phone to the VM. + +### Install as a Service + +To install the VM as a service, you can run the `headless_service_install.sh` script. This script will install the VM as a service that starts on boot. + +```bash +chmod +x ./headless_service_install.sh + +./headless_service_install.sh +``` + +#### Uninstall Service + +Run the commands below to uninstall the service: + +```bash +sudo systemctl stop headless_opencore.service + +sudo systemctl disable headless_opencore.service + +sudo rm /etc/systemd/system/headless_opencore.service + +sudo systemctl daemon-reload +``` diff --git a/headless_service_install.sh b/headless_service_install.sh new file mode 100755 index 0000000..9c428f1 --- /dev/null +++ b/headless_service_install.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Fetch script directory +REPO_PATH=$(dirname "$(readlink -f "$0")") + +# Replace %repo_path% in the service file with the actual path +sed -i "s|%repo_path%|$REPO_PATH|g" "$REPO_PATH/headless_opencore.service" + +# Copy the modified service file to /etc/systemd/system/ +sudo cp "$REPO_PATH/headless_opencore.service" /etc/systemd/system/ + +# Reload systemd daemon to apply the new service file +sudo systemctl daemon-reload + +# Enable the service to start on boot +sudo systemctl enable headless_opencore.service