XNU as a loadable kernel module inside Linux (macOS personality for arm64 Linux)
C
Full userland system disk: stream the macOS system files and Xcode from the host into an 80 GB HFS+ image (no host user data); FULL=1 setup
Heyang Zhou5f4b9d5a0bfd
diff --git a/scripts/mk-fulldisk.sh b/scripts/mk-fulldisk.shnew file mode 100644index 0000000..9e224fe--- /dev/null+++ b/scripts/mk-fulldisk.sh@@ -0,0 +1,45 @@+#!/bin/bash+# On the macOS host (tokyo): build the full (non-GUI) userland system disk in the xnupoc VM, /var/tmp/full.img.+# The macOS system files and Xcode are streamed from this host straight into the VM's mounted HFS+ image; they stay+# on this host and that VM only (never in the repo). No host user data: no /Users, no /private/var (a pristine+# /private/var comes from Apple's data-volume template), no keychains, no host SSH keys, no host preferences.+set -euo pipefail+cd "$(dirname "$0")/.."+SIZE=${SIZE:-80G}+XCODE=${XCODE:-/Applications/Xcode_27.app}+V="bash scripts/vm.sh"++$V "set -e; sudo umount /mnt/full 2>/dev/null || true; rm -f /var/tmp/full.img; truncate -s $SIZE /var/tmp/full.img+ mkfs.hfsplus -v xnulinux-full /var/tmp/full.img >/dev/null; sudo mkdir -p /mnt/full+ sudo mount -o loop,rw -t hfsplus /var/tmp/full.img /mnt/full; df -h /mnt/full | tail -1"++# bsdtar --exclude patterns are not anchored ("Library/Preferences" also drops System/Library/Preferences), so the+# top-level choices are made by listing what goes in; the exclusions left are unique paths.+EXCL=(+ --exclude 'System/Library/AssetsV2' --exclude 'System/Library/Desktop Pictures' --exclude 'System/Library/Caches/com.apple.*'+ --exclude 'Library/Application Support/com.apple.TCC'+ --exclude 'private/etc/ssh/ssh_host_*' --exclude 'private/etc/master.passwd' --exclude 'private/etc/kcpassword'+ --exclude 'xcuserdata' --exclude '.Spotlight-V100' --exclude '.fseventsd'+)+pick() { # the entries of directory $1 except the names given after it+ local d=$1; shift+ for e in "/$d"/*; do+ n=${e##*/}; skip=0+ for x in "$@"; do [ "$n" = "$x" ] && skip=1; done+ [ $skip = 1 ] || echo "$d/$n"+ done+}+SRC=(System/Library bin sbin private/etc System/Volumes/Preboot/Cryptexes/OS "${XCODE#/}")+while IFS= read -r l; do SRC+=("$l"); done < <(+ pick usr local+ pick Library Caches Logs Keychains Preferences 'Managed Preferences' LaunchDaemons LaunchAgents PrivilegedHelperTools Developer Bluetooth Tailscale+ pick Library/Developer CoreSimulator DeveloperDiskImages CommandLineTools)+t0=$(date +%s)+cd /+sudo -n tar -c -f - --no-mac-metadata --no-xattrs --no-acls "${EXCL[@]}" \+ -s ",^${XCODE#/},Applications/Xcode.app," "${SRC[@]}" 2> /tmp/mk-fulldisk-tar.err \+ | bash ~-/scripts/vm.sh "sudo tar -x -p -f - -C /mnt/full --warning=no-unknown-keyword 2>&1 | tail -5" \+ || echo "host tar ended nonzero (SIP-protected entries such as Library/Bluetooth cannot be read; they are not needed)"+cd ~-+echo "streamed in $(( $(date +%s) - t0 ))s; host tar warnings: $(wc -l < /tmp/mk-fulldisk-tar.err)"; tail -5 /tmp/mk-fulldisk-tar.err+$V "df -h /mnt/full | tail -1; ls /mnt/full /mnt/full/Applications; sudo umount /mnt/full"diff --git a/scripts/vm-sysdisk-launchd.sh b/scripts/vm-sysdisk-launchd.shindex 928495d..a84e244 100755--- a/scripts/vm-sysdisk-launchd.sh+++ b/scripts/vm-sysdisk-launchd.sh@@ -6,7 +6,30 @@ IMG=${IMG:-/var/tmp/sys.img}sudo fsck.hfsplus -fy $IMG 2>&1 | tail -1sudo mkdir -p /mnt/sys; sudo mount -o loop,rw -t hfsplus $IMG /mnt/sysif [ "${MODE:-launchd}" = launchd ]; then- sudo tar xf /var/tmp/launchd.tar -C /mnt/sys --warning=no-unknown-keyword+ # FULL=1: a full userland disk (scripts/mk-fulldisk.sh) already has launchd and every daemon; /private/var comes+ # from Apple's pristine data-volume template, the root symlinks are made here+ if [ "${FULL:-0}" = 1 ]; then+ ONLY_OURS=0+ T=/mnt/sys/System/Library/Templates/Data+ [ -d /mnt/sys/private/var/db ] || { [ -d $T/private/var ] && sudo cp -a $T/private/var /mnt/sys/private/; }+ [ -d $T/Library ] && sudo cp -an $T/Library/. /mnt/sys/Library/ 2>/dev/null || true+ for l in var:private/var tmp:private/tmp etc:private/etc; do [ -e /mnt/sys/${l%%:*} ] || sudo ln -s ${l#*:} /mnt/sys/${l%%:*}; done+ sudo mkdir -p /mnt/sys/private/tmp /mnt/sys/dev /mnt/sys/Users /mnt/sys/Volumes /mnt/sys/private/var/select+ sudo chmod 1777 /mnt/sys/private/tmp+ [ -e /mnt/sys/System/Library/dyld ] || sudo ln -s /System/Volumes/Preboot/Cryptexes/OS/System/Library/dyld /mnt/sys/System/Library/dyld+ [ -e /mnt/sys/private/var/select/sh ] || sudo ln -s /bin/bash /mnt/sys/private/var/select/sh+ [ -e /mnt/sys/private/var/select/developer_dir ] || sudo ln -s /Applications/Xcode.app/Contents/Developer /mnt/sys/private/var/select/developer_dir+ # no third-party software of the host (its own /Library/LaunchDaemons, /usr/local); GUI and hardware-only+ # daemons (no display, no watchdog hardware) are parked in /private/var/xnulinux-parked (DISABLE adds more)+ sudo rm -rf /mnt/sys/usr/local+ sudo find /mnt/sys/Library/LaunchDaemons /mnt/sys/Library/LaunchAgents -name '*.plist' ! -name 'com.apple.*' -delete 2>/dev/null || true+ sudo mkdir -p /mnt/sys/private/var/xnulinux-parked+ for d in com.apple.loginwindow com.apple.WindowServer com.apple.watchdogd com.apple.iomfb_bics_daemon ${DISABLE:-}; do+ [ -e /mnt/sys/System/Library/LaunchDaemons/$d.plist ] && sudo mv /mnt/sys/System/Library/LaunchDaemons/$d.plist /mnt/sys/private/var/xnulinux-parked/+ done+ else+ sudo tar xf /var/tmp/launchd.tar -C /mnt/sys --warning=no-unknown-keyword+ fisudo mkdir -p /mnt/sys/private/var/db /mnt/sys/private/var/run /mnt/sys/private/var/log /mnt/sys/private/etc /mnt/sys/Library[ -e /mnt/sys/etc ] || sudo ln -s private/etc /mnt/sys/etc# ONLY_OURS=1: none of Apple's daemons (their binaries are not on this disk), only a job of ours that launchd runs@@ -18,11 +41,12 @@ if [ "${MODE:-launchd}" = launchd ]; thensudo mv /mnt/sys/private/var/xnulinux-apple-daemons/$d.plist /mnt/sys/System/Library/LaunchDaemons/ 2>/dev/null || echo "no $d.plist"done[ -s /var/tmp/daemons.tar ] && sudo tar xf /var/tmp/daemons.tar -C /mnt/sys --warning=no-unknown-keyword- sudo mkdir -p /mnt/sys/private/var/db/diagnostics /mnt/sys/private/var/db/uuidtext /mnt/sys/private/var/log /mnt/sys/private/var/run /mnt/sys/Library/Preferences- # a minimal local directory node for opendirectoryd (it panics the system without /Local/Default): root, daemon, wheel- D=/mnt/sys/private/var/db/dslocal/nodes/Default- sudo mkdir -p $D/users $D/groups $D/config /mnt/sys/private/var/root- u() { sudo tee $D/users/$1.plist >/dev/null <<UP+ fi+ sudo mkdir -p /mnt/sys/private/var/db/diagnostics /mnt/sys/private/var/db/uuidtext /mnt/sys/private/var/log /mnt/sys/private/var/run /mnt/sys/Library/Preferences+ # a minimal local directory node for opendirectoryd (it panics the system without /Local/Default): root, daemon, wheel+ D=/mnt/sys/private/var/db/dslocal/nodes/Default+ sudo mkdir -p $D/users $D/groups $D/config /mnt/sys/private/var/root+ u() { sudo tee $D/users/$1.plist >/dev/null <<UP<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict>@@ -32,19 +56,18 @@ if [ "${MODE:-launchd}" = launchd ]; then<key>passwd</key><array><string>*</string></array><key>generateduid</key><array><string>FFFFEEEE-DDDD-CCCC-BBBB-AAAA0000000$2</string></array></dict></plist>UP- }- u root 0 0 /var/root "System Administrator"; u daemon 1 1 /var/root "System Services"- sudo tee $D/groups/wheel.plist >/dev/null <<'GP'+ }+ u root 0 0 /var/root "System Administrator"; u daemon 1 1 /var/root "System Services"+ sudo tee $D/groups/wheel.plist >/dev/null <<'GP'<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>name</key><array><string>wheel</string></array><key>gid</key><array><string>0</string></array><key>users</key><array><string>root</string></array><key>generateduid</key><array><string>ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000000</string></array></dict></plist>GP- sudo chmod -R go-rwx /mnt/sys/private/var/db/dslocal- # flat files for libinfo's file module- printf 'root:*:0:0:System Administrator:/var/root:/bin/sh\ndaemon:*:1:1:System Services:/var/root:/usr/bin/false\nnobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false\n' | sudo tee /mnt/sys/private/etc/passwd >/dev/null- printf 'wheel:*:0:root\ndaemon:*:1:root\nnobody:*:-2:\nstaff:*:20:root\n' | sudo tee /mnt/sys/private/etc/group >/dev/null- fi+ sudo chmod -R go-rwx /mnt/sys/private/var/db/dslocal+ # flat files for libinfo's file module+ printf 'root:*:0:0:System Administrator:/var/root:/bin/sh\ndaemon:*:1:1:System Services:/var/root:/usr/bin/false\nnobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false\n' | sudo tee /mnt/sys/private/etc/passwd >/dev/null+ printf 'wheel:*:0:root\ndaemon:*:1:root\nnobody:*:-2:\nstaff:*:20:root\n' | sudo tee /mnt/sys/private/etc/group >/dev/nullsudo tee /mnt/sys/System/Library/LaunchDaemons/xnulinux.hello.plist >/dev/null <<'PL'<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">@@ -72,7 +95,7 @@ PL<key>ProgramArguments</key><array><string>/bin/bash</string><string>-i</string></array><key>EnvironmentVariables</key>- <dict><key>PATH</key><string>/bin:/usr/bin:/sbin</string><key>PS1</key><string>xnulinux# </string><key>TERM</key><string>dumb</string></dict>+ <dict><key>PATH</key><string>/bin:/usr/bin:/sbin:/usr/sbin</string><key>PS1</key><string>xnulinux# </string><key>TERM</key><string>dumb</string></dict><key>RunAtLoad</key><true/><key>StandardInPath</key><string>/dev/console</string><key>StandardOutPath</key><string>/dev/console</string>