MagiskOnWSA Android Root Runtime Assets
Overview
This area covers the Android-side files that are injected into the WSA boot image when the build selects Magisk root. The build path that places them is MagiskOnWSA/…/build.sh: when ROOT_SOL=magisk, it patches Tools/initrd.img with Magisk binaries and overlays, moves /init to /wsainit, links /init to lspinit, and adds the covered runtime assets under overlay.d (MagiskOnWSA/…/build.sh lines 495-529). The interactive launcher MagiskOnWSA/…/run.sh only reaches this path after the user chooses Magisk as the root solution and appends --root-sol magisk plus the selected Magisk channel to the build command.
At boot, MagiskOnWSA/scripts/init.lsp.magisk.rc contributes a minimal init trigger: on Android post-fs-data, init executes /system/bin/sh ${MAGISKTMP}/post-fs-data.sh under the u:r:magisk:s0 SELinux context. That ${MAGISKTMP} script is the covered MagiskOnWSA/…/post-fs-data.sh, installed by build.sh as overlay.d/…/post-fs-data.sh. It normalizes the Magisk temp location to /sbin or /debug_ramdisk, ensures /data/adb exists with 0700 and u:object_r:adb_data_file:s0, creates /data/adb/magisk with 0755 and u:object_r:system_file:s0, then extracts runtime tools from ${MAGISKTMP}/stub.apk into /data/adb/magisk. Native tools (busybox, magiskpolicy, magiskboot, magiskinit) are pulled from lib/$ABI/lib*.so using ro.product.cpu.abi; shell helpers (util_functions.sh, boot_patch.sh) are pulled from the APK assets. Existing executable files are left in place, so this hook bootstraps missing Magisk support without overwriting already-installed copies.
MagiskOnWSA/…/post-fs-data.sh is also the dispatcher for LSPosed-style payload images staged in Magisk temp storage. It scans ${MAGISKTMP} for files matching lsp_*.img, mounts each image read-only on a same-named temporary directory, runs that image's own post-fs-data.sh in the background, waits for all of them, then unmounts, removes the mount directory, and deletes the image file. The base build uses this mechanism for lsp_cust.img: MagiskOnWSA/…/build.sh requires ../download/cust.img when Magisk is enabled and injects it as overlay.d/sbin/lsp_cust.img (build.sh lines 342, 451-454, 526-528). Any behavior inside cust.img is external to the covered source files; this module owns only the Android dispatcher contract that image must satisfy.
MagiskOnWSA/…/magisk_debug.sh is a host-side debug integration helper for a supplied Magisk package and initrd target. It accepts <release|debug> <x64|arm64> <initrd>, extracts magisk-$MAGISK_VER.zip or app-$MAGISK_VER.apk from MagiskOnWSA/download, compresses Magisk binaries and stub.apk with magiskboot, and patches the provided initrd with /lspinit, /magiskinit, overlay.d/sbin/*Magisk*.xz, and overlay.d/sbin/stub.xz. Unlike the main build.sh Magisk path, this debug helper does not add init.lsp.magisk.rc, post-fs-data.sh, or lsp_cust.img; it is useful for low-level Magisk/initrd debugging but not a complete replacement for the normal WSA image integration.
MagiskOnWSA/scripts/sepolicy.rule is a small SELinux policy fragment for Google Play Services integration. It grants gmscore_app access to create/connect/read/write vsock_socket, read device_config_runtime_native_boot_prop, search/open system_server_tmpfs, and get attributes on system_server_tmpfs plus media_rw_data_file filesystems. In the non-DLL main build path currently read here, no command references this file directly; it is still part of the Android runtime support set and must be kept aligned with any payload or image-building step that packages policy as /lspolicy.rule.
MagiskOnWSA/cacerts/** contains Android hashed CA certificate files such as MagiskOnWSA/cacerts/024c10e0.0 and MagiskOnWSA/cacerts/fbb5e364.0. The files are PEM certificates followed by decoded certificate text and are named in Android's subject-hash .0 convention, so their role is to be copied into a system trust store by the image/payload builder rather than consumed as shell scripts. The sampled certificates are NetFree roots, with validity data embedded in the files; the covered source tree does not contain the packaging command that installs them into WSA.
Path-to-responsibility map:
MagiskOnWSA/scripts/init.lsp.magisk.rc: Android init trigger that enters the Magisk runtime hook atpost-fs-dataunder the Magisk SELinux domain.- MagiskOnWSA/…/post-fs-data.sh: Android boot hook that seeds
/data/adb/magiskfromstub.apkand runs/removeslsp_*.imgpost-fs payloads. - MagiskOnWSA/…/magisk_debug.sh: host-side initrd patcher for debugging Magisk binary/stub injection into a supplied initrd.
MagiskOnWSA/scripts/sepolicy.rule: SELinux allow rules needed by Google Play Services/runtime integration when the policy fragment is packaged into the Android image.MagiskOnWSA/cacerts/**: Android subject-hash CA certificate assets intended for system trust-store installation by the image/payload packaging step.
Coupling
- If
MagiskOnWSA/scripts/init.lsp.magisk.rcchanges the path or timing of the hook, update the MagiskOnWSA/…/build.sh Magisk cpio entries as well; the build hard-codes this file intooverlay.d/init.lsp.magisk.rcand post-fs-data.sh assumes it runs after filesystems are available. - If MagiskOnWSA/…/post-fs-data.sh changes the
lsp_*.imgnaming convention or mount/cleanup behavior, verify thelsp_cust.imginjection in MagiskOnWSA/…/build.sh and any downloadedcust.imgpayloads; the dispatcher discovers payloads only by that filename pattern and expects each mounted image to contain post-fs-data.sh at its root. - If Magisk APK layout support changes in MagiskOnWSA/…/post-fs-data.sh or MagiskOnWSA/…/magisk_debug.sh, verify both scripts together. The runtime hook extracts native tools from
lib/$ABI/lib$file.soand helpers fromassets/, while the debug helper compresses the entire Magisk APK asstub.xz; mismatched assumptions can produce an initrd that boots but cannot seed/data/adb/magisk. - If certificates under
MagiskOnWSA/cacerts/**are added, removed, or renamed, preserve Android subject-hash filenames and verify the payload/image step that installs them. Android trust-store lookup depends on these hashed names, not just on valid PEM content. - If
MagiskOnWSA/scripts/sepolicy.rulechanges, verify the packaging path that turns it into runtime policy. The main MagiskOnWSA/…/build.sh Magisk flow read here does not referencesepolicy.rule, so policy edits can silently be omitted unless the payload or alternate packager consumes them.
Risks
- MagiskOnWSA/…/post-fs-data.sh deletes every
${MAGISKTMP}/lsp_*.imgafter running its hook. If the filename pattern accidentally matches a payload that should persist, that image is removed during boot after its post-fs-data script runs. - MagiskOnWSA/…/post-fs-data.sh waits for all mounted payload hooks before cleanup. If a mounted
lsp_*.imgpost-fs-data.sh hangs or leaves files busy, cleanup stalls and the image may remain mounted in Magisk temp storage. - MagiskOnWSA/…/magisk_debug.sh patches only Magisk binaries and
stub.xz, notMagiskOnWSA/scripts/init.lsp.magisk.rcor MagiskOnWSA/…/post-fs-data.sh. Using it as though it produced the same initrd as MagiskOnWSA/…/build.sh can leave the Android post-fs-data bootstrap absent.