cfw_install_host: fix SIGPIPE (Error 141) from global apfs list

Under `set -euo pipefail`, `diskutil apfs list | awk '...exit'` returns 141: awk exits on the first match and diskutil is killed by SIGPIPE while still writing its multi-container output (~21KB across 15 containers here). Scope the volume search to the image's own APFS container, derived from the attached base disk's s1 partition via APFSContainerReference, so the piped output is small enough that diskutil finishes before awk exits. This also stops the installer from selecting a System volume that belongs to an unrelated attached container.
This commit is contained in:
Xin Huang
2026-07-08 11:28:36 +03:00
committed by zqxwce
parent 16663a2f5f
commit d97f4f6045
+4 -4
View File
@@ -55,10 +55,10 @@ fi
echo "[*] host-mode CFW install: variant=$VARIANT vm=$VM_DIR"
AO=$(hdiutil attach -nomount -imagekey diskimage-class=CRawDiskImage "$IMG" 2>/dev/null)
BASEDISK=$(echo "$AO" | head -1 | awk '{print $1}')
SYS=$(diskutil apfs list 2>/dev/null | awk '/APFS Volume Disk \(Role\):/{for(i=1;i<=NF;i++) if($i ~ /^disk[0-9]+s[0-9]+$/) dev=$i} /Name:.*System \(Case-sensitive\)/{print dev; exit}')
CONT="${SYS%s*}"
[[ -n "$CONT" ]] || { echo "[-] System volume not found in $IMG" >&2; hdiutil detach "$BASEDISK" 2>/dev/null; exit 1; }
BASEDISK=$(awk 'NR == 1 { print $1; exit }' <<< "$AO")
CONT=$(diskutil info -plist "${BASEDISK}s1" | /usr/bin/plutil -extract APFSContainerReference raw -o - - 2>/dev/null || true)
SYS=$(diskutil apfs list "$CONT" 2>/dev/null | awk '/APFS Volume Disk \(Role\):/{for(i=1;i<=NF;i++) if($i ~ /^disk[0-9]+s[0-9]+$/) dev=$i} /Name:.*System \(Case-sensitive\)/{print dev; exit}')
[[ -n "$CONT" && -n "$SYS" ]] || { echo "[-] System volume not found in $IMG" >&2; hdiutil detach "$BASEDISK" 2>/dev/null; exit 1; }
echo "[*] attached: container=$CONT system=$SYS"
cleanup() {