A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.
fix(rootfs,init): rescue mount-move, await block devices, verify QEMU IP, daemon liveness, validate resize, exclude bridges from NIC pick, random password salt
ExTvc6392ad2115d
diff --git a/build-rootfs/build-rootfs.sh b/build-rootfs/build-rootfs.shindex ef9837d..1ee8eaa 100755--- a/build-rootfs/build-rootfs.sh+++ b/build-rootfs/build-rootfs.sh@@ -74,7 +74,9 @@ chmod 0440 "$ROOTFS/etc/sudoers.d/wheel"# Set root password to "podroid" (pre-hashed with openssl).# We can't run chpasswd inside the aarch64 rootfs from an x86_64 host,# so write the SHA-512 hash directly into /etc/shadow.-ROOT_HASH=$(openssl passwd -6 -salt podroid podroid)+# No fixed -salt: openssl generates a random salt so the stored hash differs+# per build (the password stays the documented default "podroid").+ROOT_HASH=$(openssl passwd -6 podroid)sed -i "s|^root:[^:]*:|root:${ROOT_HASH}:|" "$ROOTFS/etc/shadow"# Strip docs/man/locale to shrink squashfsdiff --git a/build-rootfs/files/etc/init.d/podroid-bootstrap b/build-rootfs/files/etc/init.d/podroid-bootstrapindex 4cd89ee..ffee78f 100644--- a/build-rootfs/files/etc/init.d/podroid-bootstrap+++ b/build-rootfs/files/etc/init.d/podroid-bootstrap@@ -84,17 +84,15 @@ start() {if [ -b /dev/zram0 ]; then_mem_kb=$(awk '/^MemTotal:/{print $2}' /proc/meminfo)echo lz4 > /sys/block/zram0/comp_algorithm 2>/dev/null+ # *1536 = KiB→bytes (*1024) × 1.5 ratio; disksize wants bytes.echo $((_mem_kb * 1536)) > /sys/block/zram0/disksize 2>/dev/nullmkswap /dev/zram0 >/dev/null 2>&1 && swapon -p 100 /dev/zram0 2>/dev/nullfi- # OOM tuning: prefer killing leaf user-apps (Firefox, browsers, npm,- # webpack) over our infrastructure. Higher score = killed first. -1000- # = OOM-immune (set in podroid-ready for dropbear/Xvnc/agent so all- # those services exist by then). Bumping the OOM "score adjustment"- # for non-protected processes is left to the kernel default. The big- # win is making sure VNC + SSH + the host-vsock relay survive even- # when a memory-hog browser tab gets reaped.+ # OOM behavior: re-assert the kernel default (0 = let the OOM killer pick+ # the highest-badness victim, rather than killing whatever triggered the+ # allocation). Per-service immunity (-1000 for dropbear/Xvnc/agent) is set+ # in podroid-ready once those services exist.[ -w /proc/sys/vm/oom_kill_allocating_task ] && \echo 0 > /proc/sys/vm/oom_kill_allocating_task# overcommit_memory=1 (always overcommit) lets us actually hand outdiff --git a/build-rootfs/files/etc/init.d/podroid-network b/build-rootfs/files/etc/init.d/podroid-networkindex db22cf5..bb8beb7 100644--- a/build-rootfs/files/etc/init.d/podroid-network+++ b/build-rootfs/files/etc/init.d/podroid-network@@ -13,8 +13,11 @@ start() {ip link set lo up 2>/dev/nullNETIF=""for _i in $(seq 1 10); do+ # Exclude virtual/bridge devices so the real virtio NIC is picked.+ # lxcbr0 is created by podroid-bootstrap (which runs *before* us), so+ # it would otherwise be a candidate; br-/cni cover other bridge names.NETIF=$(ip -o link show 2>/dev/null | awk -F': ' '{print $2}' | \- grep -vE '^(lo|dummy[0-9]*|veth|podman|cni-|docker)' | head -1)+ grep -vE '^(lo|dummy[0-9]*|veth|podman|cni|docker|lxcbr|br-)' | head -1)[ -n "$NETIF" ] && breaksleep 0.05done@@ -49,6 +52,14 @@ start() {ip route add default via 10.0.2.2 dev "$NETIF" 2>/dev/nullprintf 'nameserver 10.0.2.3\nnameserver 8.8.8.8\nnameserver 1.1.1.1\n' \> /etc/resolv.conf+ # Mirror the AVF post-check: if the static assignment didn't stick+ # (wrong NIC, link not up), don't report success. Dependents that+ # `need` us would assume the link is up and 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 "static IP did not stick on $NETIF"+ return 1+ fifiecho "Network found" > /dev/consoleeend 0diff --git a/build-rootfs/files/etc/init.d/podroid-vsock b/build-rootfs/files/etc/init.d/podroid-vsockindex 115520a..d4aeb2d 100644--- a/build-rootfs/files/etc/init.d/podroid-vsock+++ b/build-rootfs/files/etc/init.d/podroid-vsock@@ -25,6 +25,20 @@ start() {--stderr /var/log/podroid-vsock-agent.log \--exec /usr/local/bin/podroid-vsock-agent_agent_rc=$?+ # --background returns 0 the instant the child forks, even if the agent+ # exits immediately (e.g. AF_VSOCK bind failure). Poll the pidfile's PID:+ # a healthy agent breaks out on the first ~0.1s tick; a crash-on-launch+ # misses every tick and the final kill -0 flips the rc.+ if [ "$_agent_rc" -eq 0 ]; then+ _agent_pid=$(cat "$pidfile" 2>/dev/null)+ _i=0+ while [ "$_i" -lt 10 ]; do+ sleep 0.1+ kill -0 "$_agent_pid" 2>/dev/null && break+ _i=$((_i + 1))+ done+ kill -0 "$_agent_pid" 2>/dev/null || _agent_rc=1+ fi[ "$_agent_rc" -eq 0 ] || ewarn "podroid-vsock-agent failed to start (see /var/log/podroid-vsock-agent.log)"eend "$_agent_rc"}diff --git a/build-rootfs/files/etc/init.d/podroid-x11 b/build-rootfs/files/etc/init.d/podroid-x11index e58bc31..a18d928 100644--- a/build-rootfs/files/etc/init.d/podroid-x11+++ b/build-rootfs/files/etc/init.d/podroid-x11@@ -53,6 +53,21 @@ start() {-dpi $XVNC_DPI \-AcceptSetDesktopSize_xvnc_rc=$?+ # --background returns 0 once the child is forked, even if it dies an+ # instant later (bad -geometry, port already bound). Poll the pidfile's+ # PID instead of a fixed sleep: a healthy daemon is confirmed alive on the+ # first ~0.1s tick and we stop; a crash-on-launch leaves no live PID, so+ # all ticks miss and the final kill -0 flips the rc. Caps at ~1s.+ if [ "$_xvnc_rc" -eq 0 ]; then+ _xvnc_pid=$(cat /run/xvnc.pid 2>/dev/null)+ _i=0+ while [ "$_i" -lt 10 ]; do+ sleep 0.1+ kill -0 "$_xvnc_pid" 2>/dev/null && break+ _i=$((_i + 1))+ done+ kill -0 "$_xvnc_pid" 2>/dev/null || _xvnc_rc=1+ fi[ "$_xvnc_rc" -eq 0 ] || ewarn "Xvnc failed to start (see $XVNC_LOGFILE)"# PulseAudio: system-wide-style daemon writing raw S16LE PCM to TCP 4713.@@ -71,6 +86,20 @@ start() {--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=$?+ # Same liveness poll as Xvnc: --background hides an immediate crash+ # (missing module, port 4713 already bound). A healthy daemon breaks out+ # on the first ~0.1s tick; an instant crash misses every tick and the+ # final kill -0 flips the rc.+ if [ "$_pa_rc" -eq 0 ]; then+ _pa_pid=$(cat /run/pulseaudio.pid 2>/dev/null)+ _i=0+ while [ "$_i" -lt 10 ]; do+ sleep 0.1+ kill -0 "$_pa_pid" 2>/dev/null && break+ _i=$((_i + 1))+ done+ kill -0 "$_pa_pid" 2>/dev/null || _pa_rc=1+ fi[ "$_pa_rc" -eq 0 ] || ewarn "pulseaudio failed to start (see $PA_LOGFILE)"# eend reflects either daemon failing: a single `eend $?` would havediff --git a/build-rootfs/files/usr/local/bin/podroid-resize b/build-rootfs/files/usr/local/bin/podroid-resizeindex b4629da..e4d88c5 100644--- a/build-rootfs/files/usr/local/bin/podroid-resize+++ b/build-rootfs/files/usr/local/bin/podroid-resize@@ -23,6 +23,11 @@ while IFS= read -r _line; docase "$_line" inRESIZE\ *)set -- $_line+ # Reject empty / non-numeric / zero rows or cols before persisting:+ # a malformed line must not stamp junk into /run/term_size (which+ # podroid-login reads back) or stty a 0x0 winsize onto hvc0.+ case "$2" in ''|*[!0-9]*|0) continue;; esac+ case "$3" in ''|*[!0-9]*|0) continue;; esacstty rows "$2" cols "$3" </dev/hvc0 2>/dev/nullprintf '%s %s\n' "$2" "$3" > /run/term_size 2>/dev/null;;diff --git a/init-podroid b/init-podroidindex 521d804..7c97204 100755--- a/init-podroid+++ b/init-podroid@@ -17,6 +17,15 @@ echo "Mounting storage..." > /dev/console# /dev/vdb = read-only Alpine squashfs (system files)mkdir -p /mnt/persist /mnt/lower /mnt/overlay+# Bounded wait for the virtio block nodes: on most boots they already exist+# (loop breaks on the first iteration), but a slow virtio_blk probe can lag+# behind init. Cap the wait so a genuinely-missing node still drops to the+# FATAL diagnostics below instead of hanging forever.+for _i in $(seq 1 30); do+ [ -b /dev/vda ] && [ -b /dev/vdb ] && break+ sleep 0.1+done+# Persistent: format on first boot if needed.# noatime: stop atime writes on every read.# commit=60: journal commits every 60s (default 5s) — 12× less journal IO@@ -27,34 +36,43 @@ mkdir -p /mnt/persist /mnt/lower /mnt/overlay# Saves journal-commit syscalls on every metadata change.if ! mount -t ext4 -o rw,noatime,commit=60,barrier=0 /dev/vda /mnt/persist 2>/dev/null; thene2fsck -y /dev/vda >/dev/null 2>&1 || mkfs.ext4 -q -F /dev/vda- mount -t ext4 -o rw,noatime,commit=60,barrier=0 /dev/vda /mnt/persist+ mount -t ext4 -o rw,noatime,commit=60,barrier=0 /dev/vda /mnt/persist \+ || { echo "FATAL: persistent ext4 (/dev/vda) mount failed" > /dev/console; ls -l /dev/vd* > /dev/console 2>&1; exec sh; }fiecho "Mounting system..." > /dev/consolemount -t squashfs -o ro /dev/vdb /mnt/lower \- || { echo "FATAL: squashfs (/dev/vdb) mount failed" > /dev/console; exec sh; }+ || { echo "FATAL: squashfs (/dev/vdb) mount failed" > /dev/console; ls -l /dev/vd* > /dev/console 2>&1; exec sh; }-mkdir -p /mnt/persist/upper /mnt/persist/work+mkdir -p /mnt/persist/upper /mnt/persist/work \+ || { echo "FATAL: mkdir overlay upper/work failed" > /dev/console; exec sh; }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 \- || { echo "FATAL: overlay mount failed" > /dev/console; exec sh; }+ || { echo "FATAL: overlay mount failed" > /dev/console; ls -l /dev/vd* > /dev/console 2>&1; 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# under /mnt that would block its unlink pass).-mkdir -p /mnt/overlay/mnt/persist-mount --move /mnt/persist /mnt/overlay/mnt/persist+mkdir -p /mnt/overlay/mnt/persist \+ || { echo "FATAL: mkdir /mnt/overlay/mnt/persist failed" > /dev/console; exec sh; }+mount --move /mnt/persist /mnt/overlay/mnt/persist \+ || { echo "FATAL: mount --move /mnt/persist failed" > /dev/console; exec sh; }# Move /mnt/lower (the squashfs) too — keeps /dev/vdb mount visible in the# new root, and lets initramfs cleanup unlink /mnt cleanly.-mkdir -p /mnt/overlay/mnt/lower-mount --move /mnt/lower /mnt/overlay/mnt/lower+mkdir -p /mnt/overlay/mnt/lower \+ || { echo "FATAL: mkdir /mnt/overlay/mnt/lower failed" > /dev/console; exec sh; }+mount --move /mnt/lower /mnt/overlay/mnt/lower \+ || { echo "FATAL: mount --move /mnt/lower failed" > /dev/console; exec sh; }# Move our early mounts into the new root so OpenRC inherits them-mount --move /proc /mnt/overlay/proc-mount --move /sys /mnt/overlay/sys-mount --move /dev /mnt/overlay/dev+mount --move /proc /mnt/overlay/proc \+ || { echo "FATAL: mount --move /proc failed" > /dev/console; exec sh; }+mount --move /sys /mnt/overlay/sys \+ || { echo "FATAL: mount --move /sys failed" > /dev/console; exec sh; }+mount --move /dev /mnt/overlay/dev \+ || { echo "FATAL: mount --move /dev failed" > /dev/console; exec sh; }exec /sbin/switch_root /mnt/overlay /sbin/init