Skip to content

Commit

Permalink
Add post-install VHD creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Qonfused committed Jun 15, 2023
1 parent 6c960d0 commit f2415d4
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 18 deletions.
11 changes: 5 additions & 6 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ source ./scripts/lib/constants.sh

# Run build script
bash ./scripts/lib/oce-build/build.sh -c "$CONFIG" "$@"
# Patch SMBIOS serial data
if printf '%s\n' "$@" | grep -Fxq -- '--skip-serial'; then
echo "Skipping SMBIOS serial generation..."
else bash ./scripts/lib/oce-build/scripts/patch-serial.sh -c "$CONFIG"; fi

# Patch execution flow in OCE-Build for adding post-install tools
pushd "$(realpath ./scripts/lib/oce-build)" > /dev/null
Expand All @@ -36,15 +40,10 @@ url="$($yq ".${pkg##*/}.url" "$LOCKFILE")"
mkdir -p "$pkg" && curl -sL "$url" | bsdtar -xvf- -C "$pkg" > /dev/null 2>&1
cp -a "$pkg/Tools/." "$BUILD_DIR/tools/daemons"
# Update lockfile
find "$pkg/Tools" -maxdepth 1 -type f | while read -r f; do
find "$BUILD_DIR/tools/daemons" -maxdepth 1 -type f | while read -r f; do
daemon="${f##*/}"; $yq -i e ".${pkg##*/}.bundled
.\"$daemon\" = { \"extract\": \"./Tools/$daemon\", \"type\": \"binary\" }"\
"$LOCKFILE"
done
# Teardown
rm -r "$BUILD_DIR/.temp" && popd > /dev/null

# Patch SMBIOS serial data
if printf '%s\n' "$@" | grep -Fxq -- '--skip-serial'; then
echo "Skipping SMBIOS serial generation..."
else bash ./scripts/lib/oce-build/scripts/patch-serial.sh -c "$CONFIG"; fi
6 changes: 0 additions & 6 deletions scripts/lib/convert-efi-disk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,5 @@ if (Test-Path -Path "$($pwd)\$recoveryImage") {
Copy-Item -Path "$($pwd)\$recoveryImage" -Recurse -Destination "$($efiDisk.DriveLetter):\$recoveryImage"
}

# Copy post-install tools if present
$toolsDir = "tools"
if (Test-Path -Path "$($pwd)\$toolsDir") {
Copy-Item -Path "$($pwd)\$toolsDir" -Recurse -Destination "$($efiDisk.DriveLetter):\$toolsDir"
}

# Unmount VHDX disk
Dismount-DiskImage -ImagePath "$dest" | Out-Null
18 changes: 18 additions & 0 deletions scripts/lib/create-virtual-machine.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ $efiVHD = "$outdir\$name\EFI.vhdx"
Add-VMHardDiskDrive -VMName "$name" -Path "$efiVHD" -ControllerType SCSI
$efiDisk = Get-VMHardDiskDrive -VMName "$name"

# Create post-install VHDX if tools folder is present
$toolsDir = "$($pwd)\tools"
if (Test-Path -Path "$toolsDir") {
$toolsVHD = "$outdir\$name\tools.vhdx"
# Create and mount a new tools.vhdx disk
$toolsDisk = New-VHD -Path "$toolsVHD" -Dynamic -SizeBytes 512MB |
Mount-VHD -Passthru |
Initialize-Disk -PartitionStyle "GPT" -Confirm:$false -Passthru |
New-Partition -AssignDriveLetter -UseMaximumSize |
Format-Volume -FileSystem "FAT32" -NewFileSystemLabel "Tools" -Confirm:$false -Force
# Copy tools folder contents
Copy-Item -Path "$toolsDir\*" -Recurse -Destination "$($toolsDisk.DriveLetter):\"
# Unmount VHDX disk
Dismount-DiskImage -ImagePath "$toolsVHD" | Out-Null
# Add VHDX disk to virtual machine
Add-VMHardDiskDrive -VMName "$name" -Path "$toolsVHD" -ControllerType SCSI
}

# Create macOS disk
$macOSVHD = "$outdir\$name\$name.vhdx"
New-VHD -SizeBytes $($size*1GB) -Path "$macOSVHD" | Out-Null
Expand Down
2 changes: 1 addition & 1 deletion scripts/lib/oce-build
Submodule oce-build updated 1 files
+1 −0 build.sh
2 changes: 1 addition & 1 deletion scripts/lib/optimize-vm.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

## @file
# Optimizes macOS virtual machines for Hyper-V
# Post-Install script - Optimizes macOS virtual machines for Hyper-V
#
# Copyright (c) 2023, Cory Bennett. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
Expand Down
41 changes: 37 additions & 4 deletions src/build.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# Manual changes might be lost - proceed with caution!

OpenCorePkg:
version: 0.9.3
url: https://github.com/dortania/build-repo/releases/download/OpenCorePkg-0ad4a31/OpenCore-0.9.3-DEBUG.zip
resolution: '@acidanthera/OpenCorePkg@github:0.9.3#0ad4a31'
checksum: 18f2c72b8a1f699db11a2c0f2eaf7b2f1dd1b324cba92fba54a1e62bef1f8a2e
version: 0.9.4
url: https://github.com/dortania/build-repo/releases/download/OpenCorePkg-b3d7e9f/OpenCore-0.9.4-DEBUG.zip
resolution: '@acidanthera/OpenCorePkg@github:0.9.4#b3d7e9f'
checksum: be99fdf2dc6985172a17c10a06fdaefc2d0661db8869695807be4ac4b90553cd
extract: ./X64/EFI/.
type: directory
dependencies:
Expand All @@ -17,4 +17,37 @@ OpenCorePkg:
- ./Drivers/.
- ./Resources/.
type: binary
Lilu:
version: 1.6.6
url: https://github.com/dortania/build-repo/releases/download/Lilu-6b67099/Lilu-1.6.6-DEBUG.zip
resolution: '@acidanthera/Lilu@github:1.6.6#6b67099'
checksum: 169f0597206c09ac761850b8f19f8de0c8c9ee0565262bac970a74bf6b1a4d33
extract: ./Lilu.kext
type: kext
VirtualSMC:
version: 1.3.2
url: https://github.com/dortania/build-repo/releases/download/VirtualSMC-d28ca55/VirtualSMC-1.3.2-DEBUG.zip
resolution: '@acidanthera/VirtualSMC@github:1.3.2#d28ca55'
checksum: 9803cb842243ca4ce03aba29ff1129574980eb4d121bff4d593c6875848a9025
extract: ./Kexts/VirtualSMC.kext
type: kext
MacHyperVSupport:
version: 0.9.4
url: https://github.com/dortania/build-repo/releases/download/MacHyperVSupport-c2d63b4/MacHyperVSupport-0.9.4-DEBUG.zip
resolution: '@acidanthera/MacHyperVSupport@github:0.9.4#c2d63b4'
checksum: 46f1f0fe47385d70ecf62da3a472348d2a0f1a8274822249a1d086d25d2263e3
extract: ./Kexts/MacHyperVSupport.kext
type: kext
bundled:
MacHyperVSupportMonterey:
extract: ./Kexts/MacHyperVSupportMonterey.kext
type: kext
hvfilecopyd:
extract: ./Tools/hvfilecopyd
type: binary
hvshutdownd:
extract: ./Tools/hvshutdownd
type: binary
hvtimesyncd:
extract: ./Tools/hvtimesyncd
type: binary

0 comments on commit f2415d4

Please sign in to comment.