build: Use mtools instead of libguestfs to generate image (#28)

This commit is contained in:
Kroese 2024-06-08 13:48:51 +02:00 committed by GitHub
parent 07e0c5be59
commit fc6e44a803
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 69 additions and 48 deletions

View file

@ -10,8 +10,8 @@ ARG DEBCONF_NONINTERACTIVE_SEEN="true"
RUN set -eu && \
apt-get update && \
apt-get --no-install-recommends -y install \
guestfish \
linux-image-generic && \
fdisk \
mtools && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

View file

@ -1015,7 +1015,7 @@
<key>HibernateSkipsPicker</key>
<false/>
<key>HideAuxiliary</key>
<true/>
<false/>
<key>InstanceIdentifier</key>
<string></string>
<key>LauncherOption</key>
@ -1037,7 +1037,7 @@
<key>TakeoffDelay</key>
<integer>0</integer>
<key>Timeout</key>
<integer>15</integer>
<integer>0</integer>
</dict>
<key>Debug</key>
<dict>
@ -1063,7 +1063,7 @@
<key>Security</key>
<dict>
<key>AllowSetDefault</key>
<true/>
<false/>
<key>ApECID</key>
<integer>0</integer>
<key>AuthRestart</key>
@ -1083,7 +1083,7 @@
<key>PasswordSalt</key>
<data></data>
<key>ScanPolicy</key>
<integer>17761027</integer>
<integer>18809603</integer>
<key>SecureBootModel</key>
<string>Disabled</string>
<key>Vault</key>
@ -1189,7 +1189,7 @@
<key>SystemAudioVolume</key>
<data>Rg==</data>
<key>boot-args</key>
<string>-v keepsyms=1 amfi_get_out_of_my_way=1 tlbto_us=0 vti=9</string>
<string>keepsyms=1</string>
<key>csr-active-config</key>
<data>Jg8=</data>
<key>prev-lang:kbd</key>
@ -1260,11 +1260,13 @@
<key>AdviseFeatures</key>
<false/>
<key>MLB</key>
<string>C02119700QXJG36JC</string>
<string>C02717306J9JG361M</string>
<key>MaxBIOSVersion</key>
<false/>
<key>ProcessorType</key>
<integer>0</integer>
<key>ROM</key>
<string>0022412e3d4a</string>
<data>m7zhIYfl</data>
<key>SpoofVendor</key>
<true/>
<key>SystemMemoryStatus</key>
@ -1272,9 +1274,9 @@
<key>SystemProductName</key>
<string>iMacPro1,1</string>
<key>SystemSerialNumber</key>
<string>C02FPBZPHX87</string>
<string>C02TM2ZBHX87</string>
<key>SystemUUID</key>
<string>213FA768-A62C-4299-8598-47AA666E436F</string>
<string>007076A6-F2A2-4461-BBE5-BAD019F8025A</string>
</dict>
<key>UpdateDataHub</key>
<true/>

View file

@ -61,7 +61,7 @@ kubectl apply -f kubernetes.yml
- Start the container and connect to [port 8006](http://localhost:8006) using your web browser.
- Select `macOS Base System` by pressing the enter key to begin the installation.
- Select `macOS Base System` (by pressing the enter key) to begin the installation.
- Choose `Disk Utility` and then select the largest `Apple Inc. VirtIO Block Media` disk.
@ -69,7 +69,7 @@ kubectl apply -f kubernetes.yml
- Close the current window and proceed the installation by clicking `Reinstall macOS`.
- When prompted where you want to install macOS, select the disk you just created previously.
- When prompted where you want to install it, select the disk you just created previously.
- There will be several reboots, select `macOS Installer` each time until it shows your own disk.

View file

@ -1,48 +1,67 @@
#!/usr/bin/env bash
set -Eeuo pipefail
function msg() {
local txt="$1"
local bold="\x1b[1m"
local normal="\x1b[0m"
echo -e "${bold}### ${txt}${normal}"
}
echo "Extracting template image..."
function cleanup() {
if test "$GUESTFISH_PID" != ""; then
guestfish --remote -- exit >/dev/null 2>&1 || true
fi
}
DST="/images"
OUT="/tmp/extract"
function fish() {
echo "#" "$@"
guestfish --remote -- "$@" || exit 1
}
rm -rf "$OUT"
rm -rf "$DST"
rm -rf /images
msg "Mounting template ISO..."
mkdir -p "$OUT"
mkdir -p "$DST"
trap 'cleanup' EXIT
export LIBGUESTFS_BACKEND=direct
# shellcheck disable=SC2046
eval $(guestfish --listen)
if test "$GUESTFISH_PID" = ""; then
echo "ERROR: Starting Guestfish failed!"
exit 1
if [ ! -f "$1" ] || [ ! -s "$1" ]; then
error "Could not find image file \"$1\"." && exit 10
fi
fish add "$1"
fish run
fish mount /dev/sda1 /
fish ls /EFI
START=$(sfdisk -l "$1" | grep -i -m 1 "EFI System" | awk '{print $2}')
mcopy -bspmQ -i "$1@@${START}S" ::EFI "$OUT"
msg "Overriding config..."
cp "$2" "$OUT/EFI/OC/"
fish copy-in "$2" /EFI/OC/
fish umount-all
echo "Creating OpenCore image..."
mkdir -p /images
mv "$1" /images/OpenCore.img
START=2048
COUNT=522207
SIZE=268435456
msg "Finished succesfully!"
FILE="OpenCore.img"
IMG="/tmp/$SIZE.img"
NAME=$(basename "$IMG")
rm -f "$IMG"
if ! truncate -s "$SIZE" "$IMG"; then
rm -f "$IMG"
error "Could not allocate file $IMG for the OpenCore image." && exit 11
fi
PART="/tmp/partition.fdisk"
{ echo "label: gpt"
echo "label-id: 1ACB1E00-3B8F-4B2A-86A4-D99ED21DCAEB"
echo "device: $NAME"
echo "unit: sectors"
echo "first-lba: 34"
echo "last-lba: 524254"
echo "sector-size: 512"
echo ""
echo "${NAME}1 : start=$START, size=$COUNT, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=05157F6E-0AE8-4D1A-BEA5-AC172453D02C, name=\"primary\""
} > "$PART"
sfdisk -q "$IMG" < "$PART"
echo "drive c: file=\"$IMG\" partition=0 offset=1048576" > /etc/mtools.conf
mformat -F -M 512 -c 4 -T "$COUNT" -v "EFI" "C:"
echo "Copying files to image..."
mcopy -bspmQ "$OUT/EFI" "C:"
mv -f "$IMG" "$DST/$FILE"
echo "Finished succesfully!"