A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.
fix(vm): surface guest boot failures and harden init
ExTv553c79fc4875
diff --git a/build-rootfs/build-rootfs.sh b/build-rootfs/build-rootfs.shindex 5b0f55b..ef9837d 100755--- a/build-rootfs/build-rootfs.sh+++ b/build-rootfs/build-rootfs.sh@@ -116,10 +116,14 @@ cp /work/files/etc/inittab "$ROOTFS/etc/inittab"cp /work/files/etc/rc.conf "$ROOTFS/etc/rc.conf"# /etc/profile.d/*.sh — sourced by Alpine's /etc/profile in login shells.-# Currently: COLORTERM=truecolor so apps emit 24-bit color sequences.+# podroid-color.sh: COLORTERM=truecolor (24-bit color). podroid-x11.sh:+# DISPLAY / PULSE_SERVER for the in-app GUI viewer. Copy by explicit name so+# a renamed/removed asset fails the build (set -e) instead of silently+# shipping a squashfs without these exports.mkdir -p "$ROOTFS/etc/profile.d"-cp /work/files/etc/profile.d/*.sh "$ROOTFS/etc/profile.d/" 2>/dev/null || true-chmod 0644 "$ROOTFS/etc/profile.d/"*.sh 2>/dev/null || true+cp /work/files/etc/profile.d/podroid-color.sh "$ROOTFS/etc/profile.d/"+cp /work/files/etc/profile.d/podroid-x11.sh "$ROOTFS/etc/profile.d/"+chmod 0644 "$ROOTFS/etc/profile.d/podroid-color.sh" "$ROOTFS/etc/profile.d/podroid-x11.sh"# /etc/containers/storage.conf — pin Podman to the in-kernel overlay driver.# Without this file, Podman auto-detects fuse-overlayfs (still apk-installed@@ -149,8 +153,15 @@ EOF# Set runlevels via direct symlinks (host is x86_64, can't chroot into aarch64 rootfs to run rc-update).# rc-update is just `ln -s /etc/init.d/X /etc/runlevels/<level>/X` under the hood.mkdir -p "$ROOTFS/etc/runlevels/default" "$ROOTFS/etc/runlevels/boot"+# Guard each link: a dangling symlink (e.g. dnsmasq.lxcbr0, which lxc-bridge+# may ship only as dnsmasq config and not an init script) makes OpenRC log+# an error every boot and stalls podroid-ready's `after *` on a phantom.for svc in podroid-bootstrap podroid-network podroid-resize dropbear docker lxc dnsmasq.lxcbr0 podroid-x11 podroid-vsock podroid-ready; do- ln -sf "/etc/init.d/$svc" "$ROOTFS/etc/runlevels/default/$svc"+ if [ -e "$ROOTFS/etc/init.d/$svc" ]; then+ ln -sf "/etc/init.d/$svc" "$ROOTFS/etc/runlevels/default/$svc"+ else+ echo "WARN: init script /etc/init.d/$svc missing, skipping runlevel symlink"+ fidone# Disable services we don't need (initramfs already handles them, or they're noise in the VM)diff --git a/build-rootfs/files/etc/init.d/podroid-bootstrap b/build-rootfs/files/etc/init.d/podroid-bootstrapindex 716d848..4cd89ee 100644--- a/build-rootfs/files/etc/init.d/podroid-bootstrap+++ b/build-rootfs/files/etc/init.d/podroid-bootstrap@@ -145,8 +145,12 @@ start() {ip link add name lxcbr0 type bridge 2>/dev/nullip addr add 10.0.3.1/24 dev lxcbr0 2>/dev/nullip link set lxcbr0 up 2>/dev/null+ # Don't hide the rule-install failure: the `-C` probe is an expected+ # non-zero existence check (kept quiet), but a failed `-A` (missing+ # nat table / nf modules) must surface in the boot log instead of+ # leaving lxc containers without outbound NAT and no diagnostic.iptables -t nat -C POSTROUTING -s 10.0.3.0/24 ! -o lxcbr0 -j MASQUERADE 2>/dev/null \- || iptables -t nat -A POSTROUTING -s 10.0.3.0/24 ! -o lxcbr0 -j MASQUERADE 2>/dev/null+ || iptables -t nat -A POSTROUTING -s 10.0.3.0/24 ! -o lxcbr0 -j MASQUERADEfieend 0diff --git a/build-rootfs/files/etc/init.d/podroid-network b/build-rootfs/files/etc/init.d/podroid-networkindex 8647efd..db22cf5 100644--- a/build-rootfs/files/etc/init.d/podroid-network+++ b/build-rootfs/files/etc/init.d/podroid-network@@ -35,6 +35,13 @@ start() {# Belt-and-suspenders: if DHCP didn't write resolv.conf (busybox# variants differ), drop public DNS so apk/curl don't die silently.[ -s /etc/resolv.conf ] || printf 'nameserver 8.8.8.8\nnameserver 1.1.1.1\n' > /etc/resolv.conf+ # Don't report success on a total DHCP failure: dependents that+ # `need` us would start believing the link is up, then SSH/apk fail+ # with no obvious cause. Surface it instead.+ if ! ip -o -4 addr show dev "$NETIF" 2>/dev/null | grep -q 'inet '; then+ eend 1 "DHCP did not assign an address to $NETIF"+ return 1+ fielse# QEMU/TCG backend: SLIRP's built-in DHCP also exists but hardcoding# is faster + matches every existing user's setup. Original behavior.diff --git a/build-rootfs/files/etc/init.d/podroid-ready b/build-rootfs/files/etc/init.d/podroid-readyindex d0b82a0..a159c32 100644--- a/build-rootfs/files/etc/init.d/podroid-ready+++ b/build-rootfs/files/etc/init.d/podroid-ready@@ -2,8 +2,8 @@description="Podroid VM ready marker (consumed by Android boot detector)"depend() {- need podroid-network dropbear- after *+ need podroid-network+ after dropbear *}start() {diff --git a/build-rootfs/files/etc/init.d/podroid-vsock b/build-rootfs/files/etc/init.d/podroid-vsockindex 90b1459..115520a 100644--- a/build-rootfs/files/etc/init.d/podroid-vsock+++ b/build-rootfs/files/etc/init.d/podroid-vsock@@ -24,7 +24,9 @@ start() {--stdout /var/log/podroid-vsock-agent.log \--stderr /var/log/podroid-vsock-agent.log \--exec /usr/local/bin/podroid-vsock-agent- eend $?+ _agent_rc=$?+ [ "$_agent_rc" -eq 0 ] || ewarn "podroid-vsock-agent failed to start (see /var/log/podroid-vsock-agent.log)"+ eend "$_agent_rc"}stop() {diff --git a/build-rootfs/files/etc/init.d/podroid-x11 b/build-rootfs/files/etc/init.d/podroid-x11index b9da3a6..e58bc31 100644--- a/build-rootfs/files/etc/init.d/podroid-x11+++ b/build-rootfs/files/etc/init.d/podroid-x11@@ -2,7 +2,11 @@description="Podroid X11 server (Xvnc + pulseaudio) for in-app viewer"depend() {- need podroid-network+ # Xvnc binds 127.0.0.1:5900 and pulseaudio 0.0.0.0:4713, both loopback,+ # neither needs eth0/default-route. Order after networking but don't let a+ # podroid-network failure (slow NIC, probe timeout) needlessly kill the GUI.+ need podroid-bootstrap+ after podroid-networkbefore podroid-ready}@@ -18,7 +22,9 @@ start() {ebegin "Starting X11 server (Xvnc + pulseaudio)"# Read per-boot DPI from the kernel cmdline token written by the Android app.- XVNC_DPI=$(awk -v RS=' ' -F= '/^podroid.x11.dpi=/{print $2}' /proc/cmdline 2>/dev/null)+ # Digit-only capture: /proc/cmdline ends in '\n', and an `awk -v RS=' '`+ # parse would keep that newline on the last token, so Xvnc rejects -dpi.+ XVNC_DPI=$(sed -n 's/.*podroid\.x11\.dpi=\([0-9]*\).*/\1/p' /proc/cmdline 2>/dev/null)[ -z "$XVNC_DPI" ] && XVNC_DPI=96# /tmp lives on the persistent ext4 overlay, so a stale X server lock@@ -46,6 +52,8 @@ start() {-AlwaysShared \-dpi $XVNC_DPI \-AcceptSetDesktopSize+ _xvnc_rc=$?+ [ "$_xvnc_rc" -eq 0 ] || ewarn "Xvnc failed to start (see $XVNC_LOGFILE)"# PulseAudio: system-wide-style daemon writing raw S16LE PCM to TCP 4713.# We use --system=no with explicit XDG_RUNTIME_DIR so it runs as root@@ -62,7 +70,12 @@ start() {--load="module-null-sink sink_name=podroid_sink rate=44100 channels=2 format=s16le" \--load="module-simple-protocol-tcp source=podroid_sink.monitor record=true rate=44100 format=s16le channels=2 listen=0.0.0.0 port=$PA_PORT" \--load="module-native-protocol-unix"+ _pa_rc=$?+ [ "$_pa_rc" -eq 0 ] || ewarn "pulseaudio failed to start (see $PA_LOGFILE)"+ # eend reflects either daemon failing: a single `eend $?` would have+ # masked a dead Xvnc behind a healthy pulseaudio (or vice-versa).+ [ "$_xvnc_rc" -eq 0 ] && [ "$_pa_rc" -eq 0 ]eend $?}diff --git a/build-rootfs/files/usr/local/bin/podroid-login b/build-rootfs/files/usr/local/bin/podroid-loginindex 7ce6dca..5aeefdf 100644--- a/build-rootfs/files/usr/local/bin/podroid-login+++ b/build-rootfs/files/usr/local/bin/podroid-login@@ -10,10 +10,14 @@# sensible default rather than leaving winsize at 0x0. The host-side# TerminalView will overwrite this the moment the user touches the# screen and triggers a real SIGWINCH.+_r=""+_c=""if [ -r /run/term_size ]; thenread _r _c < /run/term_sizefi-[ -z "$_r" ] && _r=24-[ -z "$_c" ] && _c=80+# Reject empty, non-numeric, and 0 (a 0x0 winsize is the exact failure this+# script exists to prevent: TUIs bail "Failed to get size of terminal").+case "$_r" in ''|*[!0-9]*|0) _r=24;; esac+case "$_c" in ''|*[!0-9]*|0) _c=80;; esacstty rows "$_r" cols "$_c" 2>/dev/nullexec /bin/login "$@"diff --git a/build-rootfs/files/usr/local/bin/podroid-resize b/build-rootfs/files/usr/local/bin/podroid-resizeindex 3aae8e0..b4629da 100644--- a/build-rootfs/files/usr/local/bin/podroid-resize+++ b/build-rootfs/files/usr/local/bin/podroid-resize@@ -6,7 +6,11 @@# Also writes the last-known size to /run/term_size so podroid-login# can restore it after each getty respawn (virtio-console resets winsize# to 0x0 every time the line is reopened).-set -e+#+# No `set -e`: this is a long-lived `while read` daemon. A transient stty+# failure (e.g. /dev/hvc0 momentarily unavailable during a getty respawn)+# or a tmpfs write hiccup must not terminate the daemon for the rest of+# the VM's life; start-stop-daemon --background won't respawn it.# Wait for the virtio-console node to appear (timing varies)for _i in $(seq 1 30); dodiff --git a/init-podroid b/init-podroidindex 2d0ad51..521d804 100755--- a/init-podroid+++ b/init-podroid@@ -30,12 +30,16 @@ if ! mount -t ext4 -o rw,noatime,commit=60,barrier=0 /dev/vda /mnt/persist 2>/demount -t ext4 -o rw,noatime,commit=60,barrier=0 /dev/vda /mnt/persistfi-mount -t squashfs -o ro /dev/vdb /mnt/lower+echo "Mounting system..." > /dev/console+mount -t squashfs -o ro /dev/vdb /mnt/lower \+ || { echo "FATAL: squashfs (/dev/vdb) mount failed" > /dev/console; exec sh; }mkdir -p /mnt/persist/upper /mnt/persist/work+echo "Stacking overlay..." > /dev/consolemount -t overlay overlay \-o lowerdir=/mnt/lower,upperdir=/mnt/persist/upper,workdir=/mnt/persist/work,metacopy=on,redirect_dir=on,index=on \- /mnt/overlay+ /mnt/overlay \+ || { echo "FATAL: overlay mount failed" > /dev/console; exec sh; }# Move /mnt/persist into the new root so users can reach raw storage,# and so switch_root can fully clear initramfs (no orphan mounts left