This commit is contained in:
Steffen70 2024-06-14 08:51:04 +00:00 committed by GitHub
commit 247947966d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 2186 additions and 84 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@
*.sucatalog *.sucatalog
OVMF_VARS*.fd OVMF_VARS*.fd
OpenCore-Catalina/EFI/OC/Resources/ OpenCore-Catalina/EFI/OC/Resources/
*log.txt

View File

@ -13,7 +13,7 @@
# NOTE: Tweak the "MY_OPTIONS" line in case you are having booting problems! # NOTE: Tweak the "MY_OPTIONS" line in case you are having booting problems!
############################################################################### ###############################################################################
# #
# Change `Penryn` to `Haswell-noTSX` in OpenCore-Boot.sh file for macOS Sonoma! # Change `Haswell-noTSX` to `Penryn` in OpenCore-Boot.sh file for macOS Ventura and older versions!
# #
############################################################################### ###############################################################################
@ -23,7 +23,7 @@ MY_OPTIONS="+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check"
# This script works for Big Sur, Catalina, Mojave, and High Sierra. Tested with # 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. # macOS 10.15.6, macOS 10.14.6, and macOS 10.13.6.
ALLOCATED_RAM="4096" # MiB ALLOCATED_RAM="8192" # MiB
CPU_SOCKETS="1" CPU_SOCKETS="1"
CPU_CORES="2" CPU_CORES="2"
CPU_THREADS="4" CPU_THREADS="4"
@ -33,7 +33,12 @@ OVMF_DIR="."
# shellcheck disable=SC2054 # shellcheck disable=SC2054
args=( args=(
-enable-kvm -m "$ALLOCATED_RAM" -cpu Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,"$MY_OPTIONS" -enable-kvm -m "$ALLOCATED_RAM"
# Set the CPU model and options
# Use Haswell-noTSX for Sonoma and Penryn for older versions
-cpu Haswell-noTSX,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,"$MY_OPTIONS"
-machine q35 -machine q35
-device qemu-xhci,id=xhci -device qemu-xhci,id=xhci
-device usb-kbd,bus=xhci.0 -device usb-tablet,bus=xhci.0 -device usb-kbd,bus=xhci.0 -device usb-tablet,bus=xhci.0
@ -53,9 +58,12 @@ args=(
-device ich9-intel-hda -device hda-duplex -device ich9-intel-hda -device hda-duplex
-device ich9-ahci,id=sata -device ich9-ahci,id=sata
-drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file="$REPO_PATH/OpenCore/OpenCore.qcow2" -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.2,drive=OpenCoreBoot,bootindex=1
# **IMPORTANT:** Make sure to comment out the following two lines after macOS installation
-device ide-hd,bus=sata.3,drive=InstallMedia -device ide-hd,bus=sata.3,drive=InstallMedia
-drive id=InstallMedia,if=none,file="$REPO_PATH/BaseSystem.img",format=raw -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 -drive id=MacHDD,if=none,file="$REPO_PATH/mac_hdd_ng.img",format=qcow2
-device ide-hd,bus=sata.4,drive=MacHDD -device ide-hd,bus=sata.4,drive=MacHDD
# -netdev tap,id=net0,ifname=tap0,script=no,downscript=no -device virtio-net-pci,netdev=net0,id=net0,mac=52:54:00:c9:18:27 # -netdev tap,id=net0,ifname=tap0,script=no,downscript=no -device virtio-net-pci,netdev=net0,id=net0,mac=52:54:00:c9:18:27

1942
OpenCore/headless/config.plist Executable file

File diff suppressed because it is too large Load Diff

View File

@ -209,12 +209,7 @@ processors work just fine (even for macOS Sonoma).
### Headless macOS ### Headless macOS
- Use the provided [boot-macOS-headless.sh](./boot-macOS-headless.sh) script. You can follow the instructions in the `headless_readme.md` file to run the macOS VM in a headless mode.
```
./boot-macOS-headless.sh
```
### Setting Expectations Right ### Setting Expectations Right

View File

@ -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 `<localhost:5901>`.
# 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[@]}"

View File

@ -529,8 +529,8 @@ def main():
{"name": "Catalina (10.15)", "b": "Mac-00BE6ED71E35EB86", "m": "00000000000000000", "short": "catalina"}, {"name": "Catalina (10.15)", "b": "Mac-00BE6ED71E35EB86", "m": "00000000000000000", "short": "catalina"},
{"name": "Big Sur (11.7)", "b": "Mac-2BD1B31983FE1663", "m": "00000000000000000", "short": "big-sur"}, {"name": "Big Sur (11.7)", "b": "Mac-2BD1B31983FE1663", "m": "00000000000000000", "short": "big-sur"},
{"name": "Monterey (12.6)", "b": "Mac-B809C3757DA9BB8D", "m": "00000000000000000", "os_type": "latest", "short": "monterey"}, {"name": "Monterey (12.6)", "b": "Mac-B809C3757DA9BB8D", "m": "00000000000000000", "os_type": "latest", "short": "monterey"},
{"name": "Ventura (13) - RECOMMENDED", "b": "Mac-4B682C642B45593E", "m": "00000000000000000", "os_type": "latest", "short": "ventura"}, {"name": "Ventura (13)", "b": "Mac-4B682C642B45593E", "m": "00000000000000000", "os_type": "latest", "short": "ventura"},
{"name": "Sonoma (14) ", "b": "Mac-A61BADE1FDAD7B05", "m": "00000000000000000", "short": "sonoma"} {"name": "Sonoma (14) - RECOMMENDED", "b": "Mac-A61BADE1FDAD7B05", "m": "00000000000000000", "short": "sonoma"}
] ]
for index, product in enumerate(products): for index, product in enumerate(products):
name = product["name"] name = product["name"]

61
headless_boot.sh Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env bash
MY_OPTIONS="+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check"
ALLOCATED_RAM="8192" # MiB
CPU_SOCKETS="1"
CPU_CORES="2"
CPU_THREADS="4"
REPO_PATH=$(dirname "$(readlink -f "$0")")
OVMF_DIR="."
args=(
-enable-kvm -m "$ALLOCATED_RAM"
# Set the CPU model and options
# Use Haswell-noTSX for Sonoma and Penryn for older versions
-cpu Haswell-noTSX,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 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-intel-hda -device hda-duplex
-device ich9-ahci,id=sata
# Add the OpenCore bootloader drive with boot priority
-drive id=OpenCoreBoot,if=none,snapshot=on,format=qcow2,file="$REPO_PATH/OpenCore/OpenCore.qcow2"
-device ide-hd,bus=sata.2,drive=OpenCoreBoot,bootindex=1
# Add the macOS hard drive
-drive id=MacHDD,if=none,file="$REPO_PATH/mac_hdd_ng.img",format=qcow2
-device ide-hd,bus=sata.4,drive=MacHDD
# Configure network with port forwarding for SSH access
-netdev user,id=net0,hostfwd=tcp::2222-:22
-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
)
# 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 &

12
headless_opencore.service Normal file
View File

@ -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

139
headless_readme.md Normal file
View File

@ -0,0 +1,139 @@
## Setup Instructions - SSH iOS Development Environment
### Step 1: Clone the Repository
Clone this repository to your local machine and navigate to the repository root.
### Step 2: Follow Initial Setup Instructions
Follow the steps in the [README.md](README.md) file to set up the environment and install macOS (Sonoma).
### Step 3: Initial VM Boot
Start the VM for the first time with the GUI to complete the initial macOS setup:
```bash
./OpenCore-Boot.sh
```
Complete the macOS setup and install XCode and other GUI-dependent tools.
**Note:** Active SSH on macOS `System Preferences > Sharing > Remote Login`.
### Step 4: Install XCode and Generate Unique Serial
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
git clone https://github.com/corpnewt/GenSMBIOS.git
cd GenSMBIOS
```
2. Make `GenSMBIOS.command` executable and run it:
```bash
chmod +x GenSMBIOS.command
./GenSMBIOS.command
```
3. Install/Update MacSerial.
4. Select `$osx_kvm_path/OpenCore/headless/config.plist` as the configuration file.
5. Generate SMBIOS for `iMacPro1,1`.
6. Generate UUID.
### Step 5: Generate OpenCore Image with NoUI Configuration
```bash
# Update submodule
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 ./headless/config.plist --img OpenCore.qcow2
```
### Step 6: Start OpenCore VM with NoUI Configuration
```bash
# Navigate to repository root
cd $osx_kvm_path
# cd ..
# Make the shell script executable
chmod +x ./headless_boot.sh
./headless_boot.sh
```
### Step 7: Connect to macOS VM with SSH
```bash
ssh -p 2222 $user_name@localhost
```
### Step 8: Map Port 22 to 2222 and Open Firewall
```bash
# Map port 22 to 2222
sudo iptables -t nat -A PREROUTING -p tcp --dport 22 -j REDIRECT --to-port 2222
# Open firewall
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
```
### Step 9: Connect from Any Device on the Network to the VM
```bash
ssh $user_name@$vm_host_ip
```
### Step 10: Shutdown the VM
```bash
# (run on mac via SSH)
sudo shutdown -h now
```
## Additional Notes
When you use the VSCode Remote SSH extension, you will disconnect from the VM as soon as the VM enters sleep mode. To prevent this, you can enable automatic login and disable lock screen in the macOS settings. This way, the user will be logged in automatically when the VM starts and won't enter sleep mode.
I personally use Nix flakes to manage the environment, so I can install all the required tools with `nix develop` and run the scripts from there. (The Nix package manager does not support XCode, so you need to install it manually first.)
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
```

16
headless_service_install.sh Executable file
View File

@ -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