ref: Move creation logic to standalone script, add legacy macOS support

Move macOS installer image creation logic from GitHub workflow file
to a dedicated shell script `mkmaciso` for better maintainability and reusability.

Changes:
- Add support for legacy macOS versions:
  - 10.7 (Lion)
  - 10.8 (Mountain Lion)
  - 10.9 (Mavericks)
  - 10.10 (Yosemite)
  - 10.11 (El Capitan)
  - 10.12 (Sierra)
- Simplify workflow to call external script
- Enable running `mkmaciso` locally without GitHub Actions
This commit is contained in:
LongQT-sea committed 2025-12-15 20:54:45 +07:00
1 parent 9aafaf8527
commit 828b53128d
4 files changed
+1347 -271

No files matched your search

+23 -14
View File
@@ -17,12 +17,6 @@ on:
- 'Catalina'
- 'Mojave'
- 'High Sierra'
- 'Sierra'
- 'El Capitan'
- 'Yosemite'
- 'Mavericks'
- 'Mountain Lion'
- 'Lion'
release_tag:
description: 'Optional: tag the build (e.g., v10.15) to upload it to Releases for long-term storage'
required: false
@@ -31,7 +25,9 @@ on:
jobs:
build-recovery-iso:
runs-on: macos-latest
timeout-minutes: 10
permissions:
contents: write # needed to create releases
timeout-minutes: 15
steps:
- name: Checkout repository
@@ -49,7 +45,7 @@ jobs:
- name: Download macrecovery.py
run: |
echo "Downloading macrecovery.py from acidanthera/OpenCorePkg..."
curl -sL "https://raw.githubusercontent.com/acidanthera/OpenCorePkg/master/Utilities/macrecovery/macrecovery.py" -o macrecovery.py
curl -OL "https://raw.githubusercontent.com/acidanthera/OpenCorePkg/master/Utilities/macrecovery/macrecovery.py"
- name: Get version info
id: version_info
@@ -193,15 +189,27 @@ jobs:
name: macOS-${{ steps.version_info.outputs.version_name }}-Recovery-ISO
path: ${{ steps.compress_iso.outputs.compressed_file }}
compression-level: 0
retention-days: 5
retention-days: 7
- name: Sanitize release tag
id: sanitize_tag
if: github.event.inputs.release_tag != ''
run: |
tag="${{ github.event.inputs.release_tag }}"
# Replace spaces and other invalid characters with hyphens
# Keep only alphanumeric, dots, hyphens, and underscores
sanitized_tag=$(echo "$tag" | sed 's/[^a-zA-Z0-9._-]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
echo "sanitized_tag=$sanitized_tag" >> $GITHUB_OUTPUT
- name: Create Release
if: github.event.inputs.release_tag != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
run: |
title="macOS ${{ steps.version_info.outputs.version_name }} Recovery"
tag=${{ github.event.inputs.release_tag }}
tag="${{ steps.sanitize_tag.outputs.sanitized_tag }}"
gh release create $tag \
--title "$title" \
@@ -210,8 +218,9 @@ jobs:
- name: Summary
run: |
echo "## Successfully built **macOS ${{ steps.version_info.outputs.version_name }} Recovery** ISO" >> $GITHUB_STEP_SUMMARY
echo "Note: This ISO is intended for creating macOS virtual machine in Proxmox VE, QEMU, VMware, and VirtualBox." >> $GITHUB_STEP_SUMMARY
echo "Note: This ISO is intended for create macOS virtual machine on Proxmox VE, QEMU, VMware, and VirtualBox." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "If this tool helped you, please consider [giving it a star ⭐](https://github.com/LongQT-sea/macos-iso-builder)" >> $GITHUB_STEP_SUMMARY
echo "> [!Tip]" >> $GITHUB_STEP_SUMMARY
echo "> Enable [Cloudflare WARP](https://one.one.one.one/) for faster downloads." >> $GITHUB_STEP_SUMMARY
echo "Found this useful? Give it a ⭐ star so others can find it too! https://github.com/LongQT-sea/macos-iso-builder" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> [!TIP]" >> $GITHUB_STEP_SUMMARY
echo "> Enable [Cloudflare WARP](https://one.one.one.one/) for faster downloads." >> $GITHUB_STEP_SUMMARY
+34 -242
View File
@@ -17,6 +17,12 @@ on:
- 'Catalina'
- 'Mojave'
- 'High Sierra'
- 'Sierra'
- 'El Capitan'
- 'Yosemite'
- 'Mavericks'
- 'Mountain Lion'
- 'Lion'
image_format:
description: 'Select image format: iso for virtual machines, dmg for burning to USB drive'
required: true
@@ -28,8 +34,8 @@ on:
jobs:
build-installer:
runs-on: macos-15-intel
timeout-minutes: 120
timeout-minutes: 70
steps:
- name: Checkout repository
uses: actions/checkout@v5
@@ -43,262 +49,48 @@ jobs:
echo "Memory:"
top -l 1 | grep PhysMem
- name: Fetch available macOS installers
id: fetch_installers
- name: Create Image
id: create_image
run: |
echo "Fetching available installers..."
softwareupdate --list-full-installers 2>/dev/null | grep "* Title:" | sed 's/^[[:space:]]*//' > installers.txt
cat installers.txt
# Get latest version for selected macOS
INSTALLER_VERSION=$(grep "${{ github.event.inputs.macos_version }}" installers.txt | head -1 | sed -n 's/.*Version: \([^,]*\).*/\1/p')
echo "Found latest ${{ github.event.inputs.macos_version }} version: $INSTALLER_VERSION"
echo "version=$INSTALLER_VERSION" >> $GITHUB_OUTPUT
- name: Download macOS installer
id: download_installer
# Download should finish within 60 minutes. If it takes longer, rerun to try another runner.
timeout-minutes: 60
continue-on-error: true
run: |
echo "Downloading macOS ${{ github.event.inputs.macos_version }} version ${{ steps.fetch_installers.outputs.version }}"
# Download with retries
RETRIES_COUNT=3
for attempt in $(seq 1 $RETRIES_COUNT); do
echo "Download attempt $attempt of $RETRIES_COUNT..."
if softwareupdate --fetch-full-installer --full-installer-version "${{ steps.fetch_installers.outputs.version }}"; then
echo "Download successful!"
echo "download_success=true" >> $GITHUB_OUTPUT
break
fi
if [ $attempt -eq $RETRIES_COUNT ]; then
echo "Download failed after $RETRIES_COUNT attempts"
echo "download_success=false" >> $GITHUB_OUTPUT
exit 1
fi
echo "Retrying in 5s..."
sleep 5
done
- name: Check download status
if: always()
run: |
if [ "${{ steps.download_installer.outcome }}" == "failure" ] || [ "${{ steps.download_installer.outcome }}" == "cancelled" ]; then
echo "download_failed=true" >> $GITHUB_ENV
elif [ "${{ steps.download_installer.outputs.download_success }}" != "true" ]; then
echo "download_failed=true" >> $GITHUB_ENV
if [ "${{ github.event.inputs.image_format }}" == "iso" ]; then
echo "Creating macOS ${{ github.event.inputs.macos_version }} ISO image"
bash mkmaciso "${{ github.event.inputs.macos_version }}"
echo "image_name=$(basename *.iso)" >> $GITHUB_OUTPUT
else
echo "download_failed=false" >> $GITHUB_ENV
fi
- name: Create ISO
if: github.event.inputs.image_format == 'iso'
id: create_iso
run: |
echo "Creating ISO for macOS ${{ github.event.inputs.macos_version }}"
# Set variables
ISO_NAME="macOS_${{ github.event.inputs.macos_version }}_${{ steps.fetch_installers.outputs.version }}"
ISO_NAME="${ISO_NAME// /_}"
SPARSE_IMAGE="/tmp/${ISO_NAME}.sparseimage"
ISO_FILE="${GITHUB_WORKSPACE}/${ISO_NAME}.iso"
VOLUME_NAME="myvolume"
INSTALLER_PATH="/Applications/Install macOS ${{ github.event.inputs.macos_version }}.app"
RETRIES_COUNT=10
echo "ISO will be created at: $ISO_FILE"
echo "Using installer at: $INSTALLER_PATH"
# Create sparse image
echo "Creating sparse image..."
hdiutil create -size 20g -volname "$VOLUME_NAME" -fs HFS+ -type SPARSE -attach "$SPARSE_IMAGE"
# Get the disk identifier
DISK_ID=$(diskutil list | grep "$VOLUME_NAME" | head -1 | awk '{print $NF}' | sed 's/s[0-9]*$//')
# Create install media
echo "Creating install media..."
sudo "$INSTALLER_PATH/Contents/Resources/createinstallmedia" --volume "/Volumes/$VOLUME_NAME" --nointeraction
# Should wait for a few seconds
sync && sleep 5
# Detach disk
echo "Detaching $DISK_ID ..."
for attempt in $(seq 1 $RETRIES_COUNT); do
echo "Detach attempt $attempt of $RETRIES_COUNT..."
if hdiutil detach "$DISK_ID" || hdiutil detach "$DISK_ID" -force; then
echo "Disk detached successfully."
break
fi
if [ $attempt -lt $RETRIES_COUNT ]; then
echo "Detach failed, retrying..."
sync && sleep 5
fi
done
# Create hybrid ISO
hdiutil makehybrid -hfs -udf -o "$ISO_FILE" "$SPARSE_IMAGE"
# Show ISO info and set output
if [ -f "$ISO_FILE" ]; then
ISO_SIZE=$(du -h "$ISO_FILE" | cut -f1)
echo ""
echo "========================================="
echo "ISO created successfully!"
echo "ISO size: $ISO_SIZE"
echo "========================================="
echo ""
echo "image_file=$ISO_FILE" >> $GITHUB_OUTPUT
echo "image_name=${ISO_NAME}.iso" >> $GITHUB_OUTPUT
else
echo "Error: ISO file not created"
exit 1
fi
- name: Create DMG
if: github.event.inputs.image_format == 'dmg'
id: create_dmg
run: |
echo "Creating macOS ${{ github.event.inputs.macos_version }} DMG image"
# Set variables
DMG_NAME="macOS_${{ github.event.inputs.macos_version }}_${{ steps.fetch_installers.outputs.version }}"
DMG_NAME="${DMG_NAME// /_}"
DMG_FILE="${GITHUB_WORKSPACE}/${DMG_NAME}.dmg"
VOLUME_NAME="myvolume"
INSTALLER_PATH="/Applications/Install macOS ${{ github.event.inputs.macos_version }}.app"
RETRIES_COUNT=10
echo "DMG will be created at: $DMG_FILE"
echo "Using installer at: $INSTALLER_PATH"
# Step 1: Create a 20GB disk image and attach it
echo "Step 1: Creating 20GB DMG disk image..."
hdiutil create -size 20g -volname "$VOLUME_NAME" -fs HFS+ -type UDIF -attach "$DMG_FILE"
# Get the disk identifier
DISK_ID=$(diskutil list | grep "$VOLUME_NAME" | head -1 | awk '{print $NF}' | sed 's/s[0-9]*$//')
# Step 2: Create install media
echo "Step 2: Creating install media ..."
sudo "$INSTALLER_PATH/Contents/Resources/createinstallmedia" --volume "/Volumes/$VOLUME_NAME" --nointeraction
sync && sleep 5
# Step 3: Check minimum size requirements
echo "Step 3: Check minimum size requirements..."
INSTALLER_PARTITION="${DISK_ID}s2"
diskutil resizeVolume "$INSTALLER_PARTITION" limits | tee resize_limits.txt
# Extract the byte value from parentheses
MIN_SIZE=$(grep "Minimum (constrained by file usage)" resize_limits.txt | sed -n 's/.*(\([0-9]*\) Bytes).*/\1/p')
echo "Minimum size: $MIN_SIZE bytes"
# Step 4: Consolidate the installer data partition by shrinking the macOS installer partition to the minimum size.
echo "Step 4: Resizing and consolidating data..."
diskutil resizeVolume "$INSTALLER_PARTITION" "${MIN_SIZE}B" free free 0
sync && sleep 5
# Step 5: Expand installer partition back
echo "Step 5: Expanding installer partition back..."
for attempt in $(seq 1 $RETRIES_COUNT); do
echo "Resize attempt $attempt of $RETRIES_COUNT..."
if diskutil resizeVolume "$INSTALLER_PARTITION" 0; then
echo "Partition resized successfully."
break
fi
if [ $attempt -lt $RETRIES_COUNT ]; then
echo "Resize failed, retrying..."
sync && sleep 5
fi
done
sync && sleep 5
# Step 6: Detach the disk
echo "Step 6: Detaching disk..."
for attempt in $(seq 1 $RETRIES_COUNT); do
echo "Detach attempt $attempt of $RETRIES_COUNT..."
if hdiutil detach "$DISK_ID" || hdiutil detach "$DISK_ID" -force; then
echo "Disk detached successfully."
break
fi
if [ $attempt -lt $RETRIES_COUNT ]; then
echo "Detach failed, retrying..."
sync && sleep 5
fi
done
sleep 2
# Step 7: Optimize DMG size
echo "Step 7: Optimizing DMG size..."
hdiutil resize -size min "$DMG_FILE"
# Show final DMG info
if [ -f "$DMG_FILE" ]; then
DMG_SIZE=$(du -h "$DMG_FILE" | cut -f1)
echo ""
echo "========================================="
echo "Optimized DMG created successfully!"
echo "DMG size: $DMG_SIZE"
echo "========================================="
echo ""
echo "image_file=$DMG_FILE" >> $GITHUB_OUTPUT
echo "image_name=${DMG_NAME}.dmg" >> $GITHUB_OUTPUT
else
echo "Error: DMG file not created"
exit 1
echo "Creating macOS ${{ github.event.inputs.macos_version }} DMG image"
bash mkmaciso "${{ github.event.inputs.macos_version }}" dmg
echo "image_name=$(basename *.dmg)" >> $GITHUB_OUTPUT
fi
- name: Upload ISO artifact
if: github.event.inputs.image_format == 'iso'
uses: actions/upload-artifact@v5
with:
name: macOS-${{ github.event.inputs.macos_version }}-${{ steps.fetch_installers.outputs.version }}-ISO
path: ${{ steps.create_iso.outputs.image_file }}
name: ${{ steps.create_image.outputs.image_name }}
path: ./*.iso
compression-level: 0
retention-days: 5
retention-days: 7
- name: Upload DMG artifact
if: github.event.inputs.image_format == 'dmg'
uses: actions/upload-artifact@v5
with:
name: macOS-${{ github.event.inputs.macos_version }}-${{ steps.fetch_installers.outputs.version }}-DMG
path: ${{ steps.create_dmg.outputs.image_file }}
name: ${{ steps.create_image.outputs.image_name }}
path: ./*.dmg
compression-level: 0
retention-days: 5
retention-days: 7
- name: Summary
if: always()
run: |
if [ "${{ env.download_failed }}" == "true" ]; then
echo "## Download macOS Failed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
echo "> This runner may have network issues. Please **re-run the workflow** to try a different runner." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> [!TIP]" >> $GITHUB_STEP_SUMMARY
echo "> - Running during off-peak hours" >> $GITHUB_STEP_SUMMARY
echo "> - Selecting a different macOS version" >> $GITHUB_STEP_SUMMARY
echo "> - Or build Recovery ISO instead" >> $GITHUB_STEP_SUMMARY
elif [ "${{ job.status }}" == "success" ]; then
if [ "${{ github.event.inputs.image_format }}" == "iso" ]; then
echo "## Successfully built macOS ${{ github.event.inputs.macos_version }} ${{ steps.fetch_installers.outputs.version }} ISO" >> $GITHUB_STEP_SUMMARY
echo "Note: This ISO is intended for creating macOS virtual machine in Proxmox VE, QEMU, VMware, and VirtualBox." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "If this tool helped you, please consider [giving it a star ⭐](https://github.com/LongQT-sea/macos-iso-builder)" >> $GITHUB_STEP_SUMMARY
else
echo "## Successfully built macOS ${{ github.event.inputs.macos_version }} ${{ steps.fetch_installers.outputs.version }} DMG" >> $GITHUB_STEP_SUMMARY
echo 'Note: This DMG is intended for create bootable installer USB drive on Windows with [Rufus](https://rufus.ie/en/#download) or on Linux with `dd`' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "If this tool helped you, please consider [giving it a star ⭐](https://github.com/LongQT-sea/macos-iso-builder)" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "> [!TIP]" >> $GITHUB_STEP_SUMMARY
echo "> Enable [Cloudflare WARP](https://one.one.one.one/) for faster downloads." >> $GITHUB_STEP_SUMMARY
if [ "${{ github.event.inputs.image_format }}" == "iso" ]; then
echo "## Successfully built $(basename *.iso)" >> $GITHUB_STEP_SUMMARY
echo "Note: This ISO is intended for create macOS virtual machine on Proxmox VE, QEMU, VMware, and VirtualBox." >> $GITHUB_STEP_SUMMARY
else
echo "## Successfully built $(basename *.dmg)" >> $GITHUB_STEP_SUMMARY
echo 'Note: This DMG is intended for flash to USB drive using [Rufus](https://rufus.ie/en/#download) (Windows) or dd (Linux)' >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "Found this useful? Give it a ⭐ star so others can find it too! https://github.com/LongQT-sea/macos-iso-builder" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> [!TIP]" >> $GITHUB_STEP_SUMMARY
echo "> Enable [Cloudflare WARP](https://one.one.one.one/) for faster downloads." >> $GITHUB_STEP_SUMMARY
+19 -15
View File
@@ -1,20 +1,24 @@
## macOS Installer Image Builder – No Mac Required
## Build macOS Installer ISO and DMG image via Github Action – No Mac Required
* Generate bootable macOS installer images directly from Apple's servers via GitHub Actions.
* Support **macOS 10.7 Lion** through **macOS 26 Tahoe** installers.
* Download macOS installers exclusively from official Apple sources.
* Includes intelligent file size optimization to produce the smallest possible installer images.
**Supported formats:**
* **ISO** – True DVD format compatible with **Proxmox VE**, **QEMU**, **VirtualBox**, and **VMware**
* **DMG** – Create bootable macOS installer USB drives on Windows with [Rufus](https://rufus.ie/en/#download) or on Linux with **`dd`**
* **ISO** – True DVD/CD format compatible with **Proxmox VE**, **QEMU**, **VirtualBox**, and **VMware**
* **DMG** – For create bootable macOS installer USB drives on Windows with [Rufus](https://rufus.ie/en/#download) or on Linux with **`dd`**
**Available workflows:**
* **macOS Recovery ISO (Recommended)** – Lightweight recovery image (build takes ~2-5 min) • Best for virtualization
* **macOS Full Installer** – Complete offline installer (build takes ~20-60 min, 5-18GB) • Best for offline use
* **Recovery ISO (Recommended)** – Lightweight recovery image (build takes ~2-5 min) • Best for virtualization
* **Full Installer** – Complete offline installer (build takes ~10-60 min, 5-18GB) • Best for offline use
> [!IMPORTANT]
> * Use the **"Build macOS Recovery ISO image"** workflow unless you really need an offline installer.
> * GitHub-hosted runners are a free public resource — please use them responsibly.
> * Already have a macOS VM? Build macOS Installer ISO inside your VM with [Create_macOS_ISO.command](https://github.com/LongQT-sea/OpenCore-ISO/blob/main/Create_macOS_ISO.command)
> * Already have macOS? Build macOS installer ISO/DMG image with this command (replace tahoe with the desired version):
> ```
> curl -L https://raw.githubusercontent.com/LongQT-sea/macos-iso-builder/main/mkmaciso | bash -s tahoe
> ```
---
@@ -22,17 +26,17 @@
1. **Fork** this repository.
2. Go to the **Actions** tab in your forked repository.
3. Click the green **"I understand my workflows, go ahead and enable them"** button.
4. Select the **"Build macOS Installer ISO/DMG image"** or **"Build macOS Recovery ISO image"** workflow.
3. Click the green button **"I understand my workflows, go ahead and enable them"**.
4. Select the **"Build macOS Installer ISO/DMG image"** or **"Build macOS Recovery ISO image"** workflow from the left sidebar..
5. Click the **"Run workflow"** button.
6. Configure the workflow inputs:
* **macOS version** – Choose a version (*Sequoia*, *Sonoma*, etc.).
* **Image format** – Choose `iso` for virtual machines or `dmg` for bootable USB drives.
7. Click the green **"Run workflow"** button to start the build.
8. Wait for the workflow to complete (this may take 20-60 minutes).
8. Wait for the workflow to complete (this may take 10-60 minutes).
9. Open the completed workflow run and scroll to the **Artifacts** section.
10. Download the artifact (e.g., `macOS-Sequoia-15.7.2-ISO`).
10. Download the artifact (e.g., `macOS_Sequoia_15.7.3.iso`).
> [!TIP]
> Enable [Cloudflare WARP](https://one.one.one.one/) for faster downloads.
11. Extract the ZIP file to get your `.iso` or `.dmg` file.
@@ -42,12 +46,12 @@
> [!TIP]
> To create a bootable macOS installer USB drive on Windows:
> 1. Open [Rufus](https://rufus.ie/en/#download)
> 2. Click **SELECT**, change the filter to **"All files"**, then select your `.dmg`
> 2. Click **SELECT**, change the filter to **"All files"**, then select your macOS `.dmg`
> 3. Click **START**
> 4. Optional: After flashing the `dmg` image to the USB drive with Rufus, there will be free/unallocated space remaining on the USB drive. Use Disk Management to create a new FAT32 partition and place your EFI there if needed.
> 4. Optional: After flashing the `dmg` image to the USB drive, there will be free/unallocated space remaining on the USB drive. Use Disk Management to create a new FAT32 partition and place your EFI folder there if needed.
> [!NOTE]
> By default, artifacts are kept for 5 days. You can change this in the workflow YAML file.
> By default, artifacts are kept for 7 days. You can change this in the workflow YAML file.
> [!TIP]
> * For best performance, use a macOS VM on **Proxmox VE** with iGPU or dGPU passthrough.
@@ -57,4 +61,4 @@
---
## Legal Notice
This tool downloads macOS images directly from Apple's servers. Users are responsible for complying with Apple's Software License Agreement.
This tool downloads macOS images directly from Apple's servers. Users are responsible for complying with Apple's Software License Agreement.
+1271
View File
File diff suppressed because it is too large. Load diff